]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: date: check fixed offset is anchored before relative items
authorSylvestre Ledru <sylvestre@debian.org>
Mon, 1 Jun 2026 18:00:00 +0000 (20:00 +0200)
committerPádraig Brady <P@draigBrady.com>
Tue, 2 Jun 2026 10:45:52 +0000 (11:45 +0100)
A fixed-offset keyword such as 'UTC' must anchor the instant before
relative items are applied, so that '1970-01-01 UTC N seconds' is
exactly N seconds past the epoch even when the local zone observes
DST between the epoch and the result.

* tests/date/date-tz.sh: Add a relative-seconds-across-DST case.
https://github.com/coreutils/coreutils/pull/275

tests/date/date-tz.sh

index 0fd8ac16a64f3dbd8b5071a52666bf7a3cee4714..fb8b657801715ae6f7c6271669af481b61ba9daa 100755 (executable)
@@ -29,4 +29,14 @@ case $? in
   *) grep '^date: invalid date' err || fail=1 ;;
 esac
 
+# A fixed-offset keyword (here 'UTC') anchors the instant before relative
+# items are applied.  With a DST-observing zone the epoch base is in winter
+# while the result lands in summer, so adding the seconds must not pick up the
+# DST hour: '1970-01-01 UTC N seconds' is always exactly N seconds past the
+# epoch, regardless of TZ.
+secs=1780318971
+TZ='Europe/Berlin' date -d "1970-01-01 UTC $secs seconds" +%s > out || fail=1
+echo "$secs" > exp
+compare exp out || fail=1
+
 Exit $fail