From 0bac20572c9989362dd0d5b75579c64451321643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C5=8Dan?= Date: Sat, 28 Mar 2026 02:52:15 -0600 Subject: [PATCH] fix: correct Czech strftime() calling wrong SUPER method Czech.pm's strftime() method was calling $ref->SUPER::time2str(@a) instead of $ref->SUPER::strftime(@a). Since time2str() expects an epoch integer as its second argument but strftime() passes a localtime() array reference, the array ref was coerced to a number (its memory address), producing completely wrong dates (e.g., year 3269 instead of 1999). Add regression test covering strftime output, year sanity, and %o format for Czech. Co-Authored-By: Claude Opus 4.6 --- lib/Date/Language/Czech.pm | 2 +- t/czech-strftime.t | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 t/czech-strftime.t diff --git a/lib/Date/Language/Czech.pm b/lib/Date/Language/Czech.pm index 4273162..6c3868d 100644 --- a/lib/Date/Language/Czech.pm +++ b/lib/Date/Language/Czech.pm @@ -56,7 +56,7 @@ sub strftime { my $ref = shift; my @a = @_; $a[0] =~ s/(%[do]\.?\s?)%B/$1%Q/; - $ref->SUPER::time2str(@a); + $ref->SUPER::strftime(@a); } 1; diff --git a/t/czech-strftime.t b/t/czech-strftime.t new file mode 100644 index 0000000..23d7d02 --- /dev/null +++ b/t/czech-strftime.t @@ -0,0 +1,35 @@ +use strict; +use warnings; +use Test::More; +use Date::Language; + +# Regression test: Czech strftime() was calling SUPER::time2str() +# instead of SUPER::strftime(), producing garbage dates because +# time2str() interprets its second argument as epoch seconds, +# not as a localtime() array reference. + +my $cz = Date::Language->new('Czech'); + +# Tue Sep 7 13:02:42 1999 GMT +my @tm = (42, 2, 13, 7, 8, 99, 2, 249, 0); + +# strftime takes (format, time_ref) — same as time2str but with arrayref +my $result = $cz->strftime('%d. %B %Y', \@tm); + +# Must match time2str output for the same date +my $epoch = 936709362; # same timestamp +my $expected = $cz->time2str('%d. %B %Y', $epoch, 'GMT'); + +is($result, $expected, 'Czech strftime produces same result as time2str'); + +# Verify the date components are sane +like($result, qr/^ ?7\. .+ 1999$/, 'Czech strftime: day 7, year 1999'); + +# Also test the %o format (Czech day ordinal) +is($cz->strftime('%o', \@tm), '7.', 'Czech strftime: %o produces day with dot'); + +# Test that time2str still works (both methods should apply the B→Q substitution) +like($cz->time2str('%d. %B %Y', $epoch, 'GMT'), qr/1999/, 'Czech time2str still works'); +like($cz->strftime('%d. %B %Y', \@tm), qr/1999/, 'Czech strftime returns correct year'); + +done_testing;