A time interface class. This class replicates the normal time functions, but goes a couple of steps further. mbed library 82 and prior has a defective gmtime function. Also, this class enables access to setting the time, and adjusting the accuracy of the RTC.
Dependents: CI-data-logger-server WattEye X10Svr SSDP_Server
Diff: TimeInterface.cpp
- Revision:
- 13:17e1f5bb9b0e
- Parent:
- 7:1de342fa7840
diff -r a77f1e9e42b3 -r 17e1f5bb9b0e TimeInterface.cpp --- a/TimeInterface.cpp Mon Apr 11 02:22:45 2016 +0000 +++ b/TimeInterface.cpp Thu May 19 18:13:09 2016 +0000 @@ -197,7 +197,7 @@ struct tm_ex * TimeInterface::gmtime(const time_t * timer) { - time_t priv = *timer + get_tzo_min() * 60 + dst * 3600; + time_t priv = *timer; // + get_tzo_min() * 60 + dst * 3600; struct tm * tmp = std::localtime(&priv); tm_ext.tm_sec = tmp->tm_sec; @@ -237,7 +237,13 @@ size_t TimeInterface::strftime(char * ptr, size_t maxsize, const char * format, const struct tm_ex * timeptr) { - return std::strftime(ptr, maxsize, format, (struct tm *)timeptr); + size_t r = std::strftime(ptr, maxsize, format, (struct tm *)timeptr); + // strftime looks like it should return "GMT" on the tail, but doesn't. + if (strstr(format,"%Z") && strlen(ptr) + 3 < maxsize) { + strcat(ptr, "GMT"); + r += 3; + } + return r; } double TimeInterface::difftime(time_t end, time_t beginning)