The problem was with the tm.tm_isdst that is set to the current environment
value: either DST or not. While the current state is not relevant to the state
in the desired date.
Hence — it should be reset so that the mktime_or_timegm could normalise it
later.
if (!localtime_or_gmtime_r(&x, &tm, utc))
return -EINVAL;
- if (!with_tz) {
- tm.tm_isdst = dst;
- if (tzn)
- tm.tm_zone = tzn;
- }
+ tm.tm_isdst = dst;
+ if (!with_tz && tzn)
+ tm.tm_zone = tzn;
if (streq(t, "today")) {
tm.tm_sec = tm.tm_min = tm.tm_hour = 0;