Can now() roll over just like millis()?
Clash 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?
arduino-uno arduino-mega
add a comment |Â
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?
arduino-uno arduino-mega
2
Whatnow()
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
add a comment |Â
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?
arduino-uno arduino-mega
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
arduino-uno arduino-mega
asked 3 hours ago
Streamline
134
134
2
Whatnow()
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
add a comment |Â
2
Whatnow()
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
add a comment |Â
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.
sorry, long is 32 bits on 32 bits system too
â Juraj
4 mins ago
add a comment |Â
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
add a comment |Â
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.
sorry, long is 32 bits on 32 bits system too
â Juraj
4 mins ago
add a comment |Â
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.
sorry, long is 32 bits on 32 bits system too
â Juraj
4 mins ago
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered 2 hours ago
Majenkoâ¦
63k42873
63k42873
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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