Can now() roll over just like millis()?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I'm using now() and millis() to trigger events after a certain time has passed.
I am aware, and it's also easily found on the web, that millis() rolls over after a certain time has passed and for code that has to run indefinitely you have to handle this.



However I am not aware of if now() can do the same at some point. I mean it does count the seconds from the 1.1.1970 so just regarding this fact, it should not roll over. However, just like millis() this has to be counted somewhere no? How does it work?










share|improve this question

















  • 2




    What now() are you talking about? Could you give a reference?
    – Edgar Bonet
    3 hours ago










  • @EdgarBonet probably arduino.cc/en/Reference/CurieTimeNow
    – Michel Keijzers
    2 hours ago










  • he asks about Epoch seconds in Arduino, as used by the TimeLib
    – Juraj
    2 hours ago











  • It may be worth noting that you don't necessarily have to "handle" millis() rollover; you just have to prepare your comparison correctly, and there is no rollover problem, as long as you are trying to compare durations smaller than the maximum millis() value.
    – jose can u c
    2 hours ago














up vote
1
down vote

favorite












I'm using now() and millis() to trigger events after a certain time has passed.
I am aware, and it's also easily found on the web, that millis() rolls over after a certain time has passed and for code that has to run indefinitely you have to handle this.



However I am not aware of if now() can do the same at some point. I mean it does count the seconds from the 1.1.1970 so just regarding this fact, it should not roll over. However, just like millis() this has to be counted somewhere no? How does it work?










share|improve this question

















  • 2




    What now() are you talking about? Could you give a reference?
    – Edgar Bonet
    3 hours ago










  • @EdgarBonet probably arduino.cc/en/Reference/CurieTimeNow
    – Michel Keijzers
    2 hours ago










  • he asks about Epoch seconds in Arduino, as used by the TimeLib
    – Juraj
    2 hours ago











  • It may be worth noting that you don't necessarily have to "handle" millis() rollover; you just have to prepare your comparison correctly, and there is no rollover problem, as long as you are trying to compare durations smaller than the maximum millis() value.
    – jose can u c
    2 hours ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm using now() and millis() to trigger events after a certain time has passed.
I am aware, and it's also easily found on the web, that millis() rolls over after a certain time has passed and for code that has to run indefinitely you have to handle this.



However I am not aware of if now() can do the same at some point. I mean it does count the seconds from the 1.1.1970 so just regarding this fact, it should not roll over. However, just like millis() this has to be counted somewhere no? How does it work?










share|improve this question













I'm using now() and millis() to trigger events after a certain time has passed.
I am aware, and it's also easily found on the web, that millis() rolls over after a certain time has passed and for code that has to run indefinitely you have to handle this.



However I am not aware of if now() can do the same at some point. I mean it does count the seconds from the 1.1.1970 so just regarding this fact, it should not roll over. However, just like millis() this has to be counted somewhere no? How does it work?







arduino-uno arduino-mega






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 3 hours ago









Streamline

134




134







  • 2




    What now() are you talking about? Could you give a reference?
    – Edgar Bonet
    3 hours ago










  • @EdgarBonet probably arduino.cc/en/Reference/CurieTimeNow
    – Michel Keijzers
    2 hours ago










  • he asks about Epoch seconds in Arduino, as used by the TimeLib
    – Juraj
    2 hours ago











  • It may be worth noting that you don't necessarily have to "handle" millis() rollover; you just have to prepare your comparison correctly, and there is no rollover problem, as long as you are trying to compare durations smaller than the maximum millis() value.
    – jose can u c
    2 hours ago












  • 2




    What now() are you talking about? Could you give a reference?
    – Edgar Bonet
    3 hours ago










  • @EdgarBonet probably arduino.cc/en/Reference/CurieTimeNow
    – Michel Keijzers
    2 hours ago










  • he asks about Epoch seconds in Arduino, as used by the TimeLib
    – Juraj
    2 hours ago











  • It may be worth noting that you don't necessarily have to "handle" millis() rollover; you just have to prepare your comparison correctly, and there is no rollover problem, as long as you are trying to compare durations smaller than the maximum millis() value.
    – jose can u c
    2 hours ago







2




2




What now() are you talking about? Could you give a reference?
– Edgar Bonet
3 hours ago




What now() are you talking about? Could you give a reference?
– Edgar Bonet
3 hours ago












@EdgarBonet probably arduino.cc/en/Reference/CurieTimeNow
– Michel Keijzers
2 hours ago




@EdgarBonet probably arduino.cc/en/Reference/CurieTimeNow
– Michel Keijzers
2 hours ago












he asks about Epoch seconds in Arduino, as used by the TimeLib
– Juraj
2 hours ago





he asks about Epoch seconds in Arduino, as used by the TimeLib
– Juraj
2 hours ago













It may be worth noting that you don't necessarily have to "handle" millis() rollover; you just have to prepare your comparison correctly, and there is no rollover problem, as long as you are trying to compare durations smaller than the maximum millis() value.
– jose can u c
2 hours ago




It may be worth noting that you don't necessarily have to "handle" millis() rollover; you just have to prepare your comparison correctly, and there is no rollover problem, as long as you are trying to compare durations smaller than the maximum millis() value.
– jose can u c
2 hours ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote













If now() is from the TimeLib.h library, then this definition:



typedef unsigned long time_t;


indicates time_t is 32-bit unsigned value. Since it represents seconds since 1970-Jan-01 00:00:00, it will experience a rollover when representing dates past approximately 2106 (1970-Jan-01 + 2^32 seconds). Being unsigned, it also cannot represent dates earlier than 1970-Jan-01.



This is slightly different than the 2038 Rollover Problem, which occurs when a system defines a time_t as a signed 32-bit integer, and thus experiences this rollover earlier, in year 2038.



All of this depends on how/where the type time_t is defined for your CPU architecture, and this answer assumes an 8-bit AVR like Arduino Uno. If you use a different architecture, for which TimeLib.h has a different type definition, read the source code to find out exactly what you're dealing with.






share|improve this answer






















  • sorry, long is 32 bits on 32 bits system too
    – Juraj
    4 mins ago


















up vote
2
down vote













now() is a function that is specific to Intel Curie based boards.



It returns an unsigned long (which on a 32-bit system is the same as an unsigned int) and so can provide the number of seconds since 1/1/1970 up until the year 2106, at which point it will roll over.



If you plan on having your system run continuously for more than the next 88 years you will have to deal with that rollover correctly, including:



  • Using subtraction to "wrap around" your calculations

  • Not trying to calculate any periods longer than 136 years





share|improve this answer




















    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("schematics", function ()
    StackExchange.schematics.init();
    );
    , "cicuitlab");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "540"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f56844%2fcan-now-roll-over-just-like-millis%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    If now() is from the TimeLib.h library, then this definition:



    typedef unsigned long time_t;


    indicates time_t is 32-bit unsigned value. Since it represents seconds since 1970-Jan-01 00:00:00, it will experience a rollover when representing dates past approximately 2106 (1970-Jan-01 + 2^32 seconds). Being unsigned, it also cannot represent dates earlier than 1970-Jan-01.



    This is slightly different than the 2038 Rollover Problem, which occurs when a system defines a time_t as a signed 32-bit integer, and thus experiences this rollover earlier, in year 2038.



    All of this depends on how/where the type time_t is defined for your CPU architecture, and this answer assumes an 8-bit AVR like Arduino Uno. If you use a different architecture, for which TimeLib.h has a different type definition, read the source code to find out exactly what you're dealing with.






    share|improve this answer






















    • sorry, long is 32 bits on 32 bits system too
      – Juraj
      4 mins ago















    up vote
    2
    down vote













    If now() is from the TimeLib.h library, then this definition:



    typedef unsigned long time_t;


    indicates time_t is 32-bit unsigned value. Since it represents seconds since 1970-Jan-01 00:00:00, it will experience a rollover when representing dates past approximately 2106 (1970-Jan-01 + 2^32 seconds). Being unsigned, it also cannot represent dates earlier than 1970-Jan-01.



    This is slightly different than the 2038 Rollover Problem, which occurs when a system defines a time_t as a signed 32-bit integer, and thus experiences this rollover earlier, in year 2038.



    All of this depends on how/where the type time_t is defined for your CPU architecture, and this answer assumes an 8-bit AVR like Arduino Uno. If you use a different architecture, for which TimeLib.h has a different type definition, read the source code to find out exactly what you're dealing with.






    share|improve this answer






















    • sorry, long is 32 bits on 32 bits system too
      – Juraj
      4 mins ago













    up vote
    2
    down vote










    up vote
    2
    down vote









    If now() is from the TimeLib.h library, then this definition:



    typedef unsigned long time_t;


    indicates time_t is 32-bit unsigned value. Since it represents seconds since 1970-Jan-01 00:00:00, it will experience a rollover when representing dates past approximately 2106 (1970-Jan-01 + 2^32 seconds). Being unsigned, it also cannot represent dates earlier than 1970-Jan-01.



    This is slightly different than the 2038 Rollover Problem, which occurs when a system defines a time_t as a signed 32-bit integer, and thus experiences this rollover earlier, in year 2038.



    All of this depends on how/where the type time_t is defined for your CPU architecture, and this answer assumes an 8-bit AVR like Arduino Uno. If you use a different architecture, for which TimeLib.h has a different type definition, read the source code to find out exactly what you're dealing with.






    share|improve this answer














    If now() is from the TimeLib.h library, then this definition:



    typedef unsigned long time_t;


    indicates time_t is 32-bit unsigned value. Since it represents seconds since 1970-Jan-01 00:00:00, it will experience a rollover when representing dates past approximately 2106 (1970-Jan-01 + 2^32 seconds). Being unsigned, it also cannot represent dates earlier than 1970-Jan-01.



    This is slightly different than the 2038 Rollover Problem, which occurs when a system defines a time_t as a signed 32-bit integer, and thus experiences this rollover earlier, in year 2038.



    All of this depends on how/where the type time_t is defined for your CPU architecture, and this answer assumes an 8-bit AVR like Arduino Uno. If you use a different architecture, for which TimeLib.h has a different type definition, read the source code to find out exactly what you're dealing with.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 hours ago

























    answered 2 hours ago









    jose can u c

    5,1372624




    5,1372624











    • sorry, long is 32 bits on 32 bits system too
      – Juraj
      4 mins ago

















    • sorry, long is 32 bits on 32 bits system too
      – Juraj
      4 mins ago
















    sorry, long is 32 bits on 32 bits system too
    – Juraj
    4 mins ago





    sorry, long is 32 bits on 32 bits system too
    – Juraj
    4 mins ago











    up vote
    2
    down vote













    now() is a function that is specific to Intel Curie based boards.



    It returns an unsigned long (which on a 32-bit system is the same as an unsigned int) and so can provide the number of seconds since 1/1/1970 up until the year 2106, at which point it will roll over.



    If you plan on having your system run continuously for more than the next 88 years you will have to deal with that rollover correctly, including:



    • Using subtraction to "wrap around" your calculations

    • Not trying to calculate any periods longer than 136 years





    share|improve this answer
























      up vote
      2
      down vote













      now() is a function that is specific to Intel Curie based boards.



      It returns an unsigned long (which on a 32-bit system is the same as an unsigned int) and so can provide the number of seconds since 1/1/1970 up until the year 2106, at which point it will roll over.



      If you plan on having your system run continuously for more than the next 88 years you will have to deal with that rollover correctly, including:



      • Using subtraction to "wrap around" your calculations

      • Not trying to calculate any periods longer than 136 years





      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        now() is a function that is specific to Intel Curie based boards.



        It returns an unsigned long (which on a 32-bit system is the same as an unsigned int) and so can provide the number of seconds since 1/1/1970 up until the year 2106, at which point it will roll over.



        If you plan on having your system run continuously for more than the next 88 years you will have to deal with that rollover correctly, including:



        • Using subtraction to "wrap around" your calculations

        • Not trying to calculate any periods longer than 136 years





        share|improve this answer












        now() is a function that is specific to Intel Curie based boards.



        It returns an unsigned long (which on a 32-bit system is the same as an unsigned int) and so can provide the number of seconds since 1/1/1970 up until the year 2106, at which point it will roll over.



        If you plan on having your system run continuously for more than the next 88 years you will have to deal with that rollover correctly, including:



        • Using subtraction to "wrap around" your calculations

        • Not trying to calculate any periods longer than 136 years






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        Majenko♦

        63k42873




        63k42873



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2farduino.stackexchange.com%2fquestions%2f56844%2fcan-now-roll-over-just-like-millis%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            What does second last employer means? [closed]

            One-line joke