date and time BUGFIX handle DST when moving timestamp to UTC
Fixes #1734
diff --git a/src/plugins_types/date_and_time.c b/src/plugins_types/date_and_time.c
index f849c46..62e304c 100644
--- a/src/plugins_types/date_and_time.c
+++ b/src/plugins_types/date_and_time.c
@@ -17,6 +17,7 @@
#include "plugins_types.h"
#include <ctype.h>
+#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -52,6 +53,7 @@
LY_ERR ret = LY_SUCCESS;
struct lysc_type_str *type_dat = (struct lysc_type_str *)type;
struct lyd_value_date_and_time *val;
+ struct tm tm;
uint32_t i;
char c;
@@ -118,6 +120,21 @@
tzset();
val->time += timezone;
val->unknown_tz = 1;
+
+ if (daylight) {
+ /* DST may apply, adjust accordingly */
+ if (!localtime_r(&val->time, &tm)) {
+ ret = ly_err_new(err, LY_ESYS, LYVE_DATA, NULL, NULL, "localtime_r() call failed (%s).", strerror(errno));
+ goto cleanup;
+ } else if (tm.tm_isdst < 0) {
+ ret = ly_err_new(err, LY_EINT, LYVE_DATA, NULL, NULL, "Failed to get DST information.");
+ goto cleanup;
+ }
+ if (tm.tm_isdst) {
+ /* move an hour back */
+ val->time -= 3600;
+ }
+ }
}
if (format == LY_VALUE_CANON) {