From: Collin Funk Date: Thu, 23 Jul 2026 04:49:48 +0000 (-0700) Subject: tests: date: check that weekdays are ignored when given an explicit date X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e812858bb8b5cc1a4c91b16502a3092ead1d72f;p=thirdparty%2Fcoreutils.git tests: date: check that weekdays are ignored when given an explicit date * tests/date/date.pl: Add some test cases. * tests/date/date-debug.sh: Test the debug output for this case. --- diff --git a/tests/date/date-debug.sh b/tests/date/date-debug.sh index 8441dc8e8f..241646379e 100755 --- a/tests/date/date-debug.sh +++ b/tests/date/date-debug.sh @@ -310,5 +310,24 @@ sed '2s/(Y-M-D) [0-9][0-9][0-9][0-9]-/(Y-M-D) XXXX-/' out10_t >> out10 \ || framework_failure_ compare exp10 out10 || fail=1 +# Test that the weekday is ignored when explicit dates are given. +cat<exp11 +date: parsed day part: Tue (day ordinal=0 number=2) +date: parsed date part: (Y-M-D) 2026-07-22 +date: input timezone: TZ="UTC0" environment value or -u +date: warning: using midnight as starting time: 00:00:00 +date: warning: day (Tue) ignored when explicit dates are given +date: starting date/time: '(Y-M-D) 2026-07-22 00:00:00' +date: '(Y-M-D) 2026-07-22 00:00:00' = 1784678400 epoch-seconds +date: timezone: Universal Time +date: final: 1784678400.000000000 (epoch-seconds) +date: final: (Y-M-D) 2026-07-22 00:00:00 (UTC) +date: final: (Y-M-D) 2026-07-22 00:00:00 (UTC+00) +date: output format: '$d_t_fmt' +Wed Jul 22 00:00:00 UTC 2026 +EOF + +date -u --debug -d 'Tue, 2026-07-22' >out11 2>&1 || fail=1 +compare exp11 out11 || fail=1 Exit $fail diff --git a/tests/date/date.pl b/tests/date/date.pl index c685c3d3b8..d096686599 100755 --- a/tests/date/date.pl +++ b/tests/date/date.pl @@ -466,6 +466,26 @@ push @Tests, {EXIT => 1}, ]; +# Test that the weekday is ignored when explicit dates are given. +# However, a invalid weekday will still result in an error. +my @weekdays = ('Mond', 'Tuesd', 'Wedn', 'Thursd', 'Frid', 'Satu', 'Sund'); +my (@bad, @good); +for my $i (1..$#weekdays + 1) + { + my $weekday = $weekdays[$i - 1]; + my $iso_date = "2026-07-" . ($weekday eq 'Wedn' ? '21' : '22'); + my $date = "$weekday, $iso_date"; + push @bad, + ["bad-weekday-explict-date$i", "-u -d '$date' +'%Y-%m-%d'", + {ERR=>"date: invalid date '$date'\n"}, {EXIT=>1}]; + chop $weekday; + my $date = "$weekday, $iso_date"; + push @good, + ["good-weekday-explict-date$i", "-u -d '$date' +'%Y-%m-%d'", + {OUT=>"$iso_date"}]; + } +push @Tests, @bad, @good; + # Repeat the cross-dst test, using Jan 1, 2005 and every interval from 1..364. foreach my $i (1..364) {