Many C++ implementations have a non standard extension timegm() for doing just that. The nearest equivalent is mktime() but that is timezone aware and, in this case, does an unwanted conversion to the local time zone. The problem now comes when reading the RTC because, in the standard C++ time library, there is no reverse of the gmtime() method of converting a "broken down" time into a UTC Unix time stamp. So, with timeStruct, I can set the time on the RTC having obtained the "broken down" time format of the current UTC time, and maybe applying a few corrections to compensate for months sometimes being enumerated as a range 0 to 11 and at other times 1 to 12, different epochs etc. It takes the current time (UTC) and updates a struct of type tm. There is a standard C++ time library function gmtime(). That is day, month, year, hour, minute, second instead of a Unix time stamp. I run the RTC in UTC and the RTC internally requires the date to be in "broken down time" format. The ESP8266 Arduino platform now has built in functions for obtaining an NTP timestamp and updating the ESP8266 system time, so theoretically, this should now be a simple task. It uses various Arduino libraries including the TimeZone library. I'm attempting to update an old project which uses an ESP8266, NTP and a DS3231 RTC module. That is an equivalent of the timegm() extension found on some C/C++ platforms. TL DR : Is there a reliable and robust timezone/DST-neutral way of converting a UTC time in a tm struct to a time_t UTC Unix epoch date.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |