From 26fad523ee7d660d864e9f95f21e90e34d241077 Mon Sep 17 00:00:00 2001 From: Louis Strous Date: Sat, 11 Oct 2025 21:56:47 +0200 Subject: [PATCH 1/2] Add test case to show that negative years aren't stringified correctly --- t/02_main.t | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/t/02_main.t b/t/02_main.t index bd6f4a4..b3bd74d 100644 --- a/t/02_main.t +++ b/t/02_main.t @@ -8,7 +8,7 @@ BEGIN { $^W = 1; } -use Test::More tests => 19; +use Test::More tests => 21; use Date::Tiny; @@ -80,3 +80,21 @@ SCOPE: { is( $date->month, 1, '->month ok' ); is( $date->day, 31, '->day ok' ); } + +# Testing stringification + +SCOPE: { + my $date = Date::Tiny->new( + year => 6, + month => 1, + day => 31 + ); + is( "$date", '0006-01-31', 'stringification positive year ok' ); + + $date = Date::Tiny->new( + year => -3, + month => 7, + day => 5 + ); + is( "$date", '-0003-07-05', 'stringification negative year ok' ); +} From 9013f8cc268aac41802e07b4c169b62619eeeb76 Mon Sep 17 00:00:00 2001 From: Louis Strous Date: Sat, 11 Oct 2025 22:09:39 +0200 Subject: [PATCH 2/2] Make Date::Tiny instances with negative years be stringified correctly with a minus sign and at least 4 digits for the year, e.g. '-0003-02-28' --- lib/Date/Tiny.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Date/Tiny.pm b/lib/Date/Tiny.pm index 19c560c..9359636 100644 --- a/lib/Date/Tiny.pm +++ b/lib/Date/Tiny.pm @@ -113,7 +113,7 @@ format, which returns in the form "2006-04-12". =cut sub ymd { - sprintf( "%04u-%02u-%02u", + sprintf( "%04.4d-%02u-%02u", $_[0]->year, $_[0]->month, $_[0]->day,