Replies: 3 comments 1 reply
-
Hi Henry I have been looking into time_t in general, and I see it has fallen out of favor and I can see why. For ESP it works as expected but is not considered portable. While the intent of the V4 code is not portability, just look at the Arduino implementation of String, which is a good example of braindead behavior and the very unfortunate repurposing of the map functionality and the missing vector support and you will see why much of the code has no chance to be portable. With that said, using uint32_t to replace time_t will have no impact on the system functionality and will align the code with current opinions for "not so bad code". Feel free to update the use of time_t to uint32_t. |
Beta Was this translation helpful? Give feedback.
-
I admit that I was surprised by the results. My personal results from the above thought experiment? (click to expand)
Because ESP32 uses 32-bit signed integer, it cannot represent dates past January 18, 2038. Bonus Question B2The ESP8266 defines How's that for unexpected? When |
Beta Was this translation helpful? Give feedback.
-
Actually, uint32_t is more than enough for millis since it is time since boot since there is no concept of "now" other than setting the timestamp on a downloaded file. Any code that could be impacted by a rollover in millis already has protection against that in the unlikely event that an ESP goes multiple year without a reboot. It is when we use micros that the real issue can come up. That rolls over every few days. |
Beta Was this translation helpful? Give feedback.
-
MartinMueller2003 wrote:
I was fairly sure that
time_t
wasn't quite that well defined, even for just the ESP product line. My challenge was fairly simple:Without validating your understanding (e.g., don't check via compilation, documentation, etc.), write down your answers to the following questions on a piece of paper:
sizeof(time_t)
?time_t
?time_t
?time_t
a signed or unsigned type?time_t
?time_t
?After you've written answers to the above (don't have to send them), feel free to verify them programmatically. Here's an example file that you should be able to just drop into an existing project, for example ... just edit (or uncomment) the line at the end according to your expectations ... if you are correct, the file will compile. If not, it will assert during compilation. Try on both ESP8266 and ESP32.
BONUS POINTS:
B1. Also perform experiment on ESP32-C2, ESP32-S3, or other platforms of interest
B2. If
time_t
is 64-bit, what limits should the code enforce on allowed range?1 vote ·
Beta Was this translation helpful? Give feedback.
All reactions