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:
- 11:1d880a50da8a
- Parent:
- 10:5734dbc2f5cc
- Child:
- 17:45dae5a72679
--- a/TimeInterface.cpp Sun Jan 22 04:06:16 2017 +0000 +++ b/TimeInterface.cpp Sun Jan 22 19:31:44 2017 +0000 @@ -101,7 +101,7 @@ dst_event_pair_t test_pair; if (parseDSTstring(&test_pair.dst_start, dstStart) - && parseDSTstring(&test_pair.dst_stop, dstStop)) { + && parseDSTstring(&test_pair.dst_stop, dstStop)) { memcpy(&dst_pair, &test_pair, sizeof(dst_event_pair_t)); INFO("set_dst from (%s,%s)", dstStart, dstStop); return true; @@ -215,7 +215,8 @@ return result; } -struct tm_ex * TimeInterface::gmtime(const time_t * timer) { +struct tm_ex * TimeInterface::gmtime(const time_t * timer) +{ time_t priv = *timer + get_tzo_min() * 60 + dst * 3600; struct tm * tmp = std::localtime(&priv); @@ -232,7 +233,8 @@ return &tm_ext; } -struct tm_ex * TimeInterface::localtime(const time_t * timer) { +struct tm_ex * TimeInterface::localtime(const time_t * timer) +{ struct tm * tmp = std::localtime(timer); tm_ext.tm_sec = tmp->tm_sec; @@ -417,8 +419,8 @@ char *am_string; char *pm_string; char *ldate_format; - char *zone_names[9]; - int8_t zone_offsets[9]; + char *zone_names[10]; + int8_t zone_offsets[10]; }; static struct dtconv En_US = { @@ -442,10 +444,11 @@ "AM", "PM", "%A, %B, %e, %Y", - { "UTC", "EST", "CST", "MST", "PST" }, - { 0, -5, -6, -7, -8 }, + { "UTC", "EST", "CST", "MST", "PST", "YST", "CAT", "HST", "CET", "EET", }, + { 0, -5, -6, -7, -8, -9, -10, -10, +1, +2, }, }; + #ifndef isprint #define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up) #define isprint(c) in_range(c, 0x20, 0x7f) @@ -734,13 +737,10 @@ } if (i == asizeof(En_US.zone_names)) return 0; -printf("z: %s => %d\r\n", En_US.zone_names[i], En_US.zone_offsets[i]); tm->tm_tzo_min = En_US.zone_offsets[i] * 60; buf += len; break; } } - return buf; } -