MSVC: preserve date-and-time with unspecified TZ
This compatibility code was not stable for datetime values with unknown
TZ. I think that the old behavior was not in violation of the YANG
standard, but it was silly anyway -- if there's a timestamp with
"unknown TZ", adding the *local* TZ before storing it doesn't make a lot
of sense.
After this commit, the date-and-time handling on Windows becomes saner.
These timestamps still won't remember their original TZ, but at least
the absolute time will remain unchanged if we interpret "unknown" as
"UTC", *and* there's now roundtrip stability.
Also expand the test coverage a bit.
Fixes: e182a27c Allow building on platforms without `struct tm.tm_gmtoff`, `timezone`, `daylight`
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index f1b453d..c3dc23b 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -930,12 +930,12 @@
/* initialize the local timezone */
tzset();
+#ifdef HAVE_TM_GMTOFF
/* convert */
if (!localtime_r(&time, &tm)) {
return LY_ESYS;
}
-#ifdef HAVE_TM_GMTOFF
/* get timezone offset */
if (tm.tm_gmtoff == 0) {
/* time is Zulu (UTC) */
@@ -948,6 +948,11 @@
}
sprintf(zoneshift, "%+03d:%02d", zonediff_h, zonediff_m);
#else
+ /* convert */
+ if (!gmtime_r(&time, &tm)) {
+ return LY_ESYS;
+ }
+
(void)zonediff_h;
(void)zonediff_m;
sprintf(zoneshift, "-00:00");