espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
12.93k stars 7.1k forks source link

Full Unix-like time & timezone API support (IDFGH-3799) #5715

Open huming2207 opened 3 years ago

huming2207 commented 3 years ago

Is your feature request related to a problem? Please describe.

ESP32 does not have full support on time and timezone support. For example, tm_gmtoff in struct tm is not available. Some TZ variables are also not available. This may be very problematic for some use cases like:

Describe the solution you'd like

I understand that adding these features may dramatically increase the firmware size. But I think if possible, could you guys please leave an option in Kconfig so that can let the user decide whether to enable it or not, instead of hard-coded macros.

Describe alternatives you've considered

But meanwhile seems like ESP32 uses the time APIs from the internal ROM. Maybe we need to implement a separate time library/wrapper instead?

Additional context

N/A

Alvin1Zhang commented 3 years ago

Thanks for raising this feature request.

KonstantinKondrashov commented 3 years ago

Hi @huming2207! Thanks for the feature request. We will add this to the future IDF versions. I can suggest trying to use CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option to disable ROM time functions, and after that, you can build the toolchain yourself with supporting TZ database.

huming2207 commented 3 years ago

Hello @KonstantinKondrashov

Thanks! I will have a look for that!

huming2207 commented 3 years ago

Hello again @KonstantinKondrashov

I just had a look on the menuconfig of that crosstool-ng. But I couldn't find any options for enabling the full timezone. Is it not available in the current version of newlib and I have to add it by myself?

KonstantinKondrashov commented 3 years ago

Actually, the CONFIG_SDK_TOOLCHAIN_SUPPORTS_TIME_WIDE_64_BITS option is related to ESP-IDF. If you do not see this option in IDF it means that you can not apply this approach. Sorry, I am not familiar with crosstool-ng, and I do not know how to enable the full timezone there.

huming2207 commented 3 years ago

Hi @KonstantinKondrashov ,

Yea I also couldn't find a way of getting timezone database in in the crosstool-ng or newlib configure's args.

But for the tm_gmtoff, seems like I just need to do something like this before including the time.h:

#ifdef ESP_PLATFORM
#define __TM_GMTOFF tm_gmtoff
#endif

I guess it should work. But I haven't got time to test it.

crackwitz commented 1 year ago

@huming2207 I just tested that (define before include) with esp-idf v5.0.1 and it had no effect for me. the definition needs to be visible in whatever library code implements strptime. I can't find the implementation by diving into the esp-idf code using VSCode.

diplfranzhoepfinger commented 1 month ago

i support this too.