summaryrefslogtreecommitdiff
path: root/zen/time.h
diff options
context:
space:
mode:
Diffstat (limited to 'zen/time.h')
-rw-r--r--zen/time.h22
1 files changed, 11 insertions, 11 deletions
diff --git a/zen/time.h b/zen/time.h
index 4593c48b..996593c8 100644
--- a/zen/time.h
+++ b/zen/time.h
@@ -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(&lt, &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(&lt, &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, &lt) == nullptr)
#endif
+ return TimeComp();
+
+ return implementation::toZenTimeComponents(lt);
}
bgstack15