Hi – beginner here, on ESP32 with vscode/pio, esp32 platform / arduino framework. I am using time_t all over my code for temp/humidity logging and other things, but I have read that it will fail in 2038.
I can’t seem to find much info on how to handle this situation; I found this post suggesting some build flags but they had no effect when I added them (on a whim) in platformio.ini.
I found another post that suggests that most libraries now use an unsigned long to represent time, but when I F12 through the type definitions it looks like it’s defined as long; in /home/me/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/sys-include/sys/_timeval.h:
#if !defined(__time_t_defined) && !defined(_TIME_T_DECLARED)
typedef _TIME_T_ time_t;
#define __time_t_defined
#define _TIME_T_DECLARED
#endif
in /home/me/.platformio/packages/toolchain-xtensa-esp32/xtensa-esp32-elf/sys-include/sys/_types.h:
#if defined(_USE_LONG_TIME_T) || __LONG_MAX__ > 0x7fffffffL
#define _TIME_T_ long
#else
#define _TIME_T_ __int_least64_t
#endif
I admit that while I understand the conceptual issue (signed 32bit time_t can’t represent that many seconds since the epoch) the architectural issue (which abstracted library layer/library/compiler/whatever is relevant, how that can be changed, and how those changes can be effected in the context of PIO/vscode) is well over my head.
Is there anything I can do to make my embedded device work past 2038? Or is it in fact using unsigned long already so I don’t need to worry until 2106? Or is this just a deficiency in the underlying architecture and there’s nothing I can realistically do as a beginner until those libraries are updated?
(Note: yes, I know 2038 is a long way away, but I’d like my device to be operating well past then, hence the question. )
Thanks!