diff options
Diffstat (limited to 'zen/time.h')
-rw-r--r-- | zen/time.h | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -89,12 +89,11 @@ struct std::tm toClibTimeComponents(const TimeComp& comp) ctc.tm_min = comp.minute; //0-59 ctc.tm_sec = comp.second; //0-61 ctc.tm_isdst = -1; //> 0 if DST is active, == 0 if DST is not active, < 0 if the information is not available - return ctc; } inline -TimeComp toZenTimeComponents(const struct std::tm& ctc) +TimeComp toZenTimeComponents(const struct ::tm& ctc) { TimeComp comp; comp.year = ctc.tm_year + 1900; @@ -219,7 +218,7 @@ String formatTime(const String2& format, const TimeComp& comp, UserDefinedFormat std::mktime(&ctc); // unfortunately std::strftime() needs all elements of "struct tm" filled, e.g. tm_wday, tm_yday //note: although std::mktime() explicitly expects "local time", calculating weekday and day of year *should* be time-zone and DST independent - CharType buffer[256]; + CharType buffer[256] = {}; const size_t charsWritten = strftimeWrap(buffer, 256, strBegin(format), &ctc); return String(buffer, charsWritten); } @@ -236,16 +235,17 @@ String formatTime(FormatType, const TimeComp& comp, PredefinedFormatTag) inline TimeComp localTime(time_t utc) { -#ifdef _MSC_VER - struct tm lt = {}; - errno_t rv = ::localtime_s(<, &utc); //more secure? - if (rv != 0) - return TimeComp(); - return implementation::toZenTimeComponents(lt); + struct ::tm lt = {}; + + //use thread-safe variants of localtime()! +#ifdef ZEN_WIN + if (::localtime_s(<, &utc) != 0) #else - struct tm* lt = std::localtime(&utc); //returns nullptr for invalid time_t on Visual 2010!!! (testvalue "-1") - return lt ? implementation::toZenTimeComponents(*lt) : TimeComp(); + if (::localtime_r(&utc, <) == nullptr) #endif + return TimeComp(); + + return implementation::toZenTimeComponents(lt); } |