Skip to content

Commit

Permalink
Parse years before 1900
Browse files Browse the repository at this point in the history
They could be produced by e.g. subtracting something from 1900-01-01,
but parsing year < 1900 failed.

Also add a test to verify it works.

Fixes Dual-Life#56.
  • Loading branch information
choroba committed Nov 23, 2023
1 parent c9f6256 commit 7cec319
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 0 additions & 2 deletions Piece.xs
Original file line number Diff line number Diff line change
Expand Up @@ -793,8 +793,6 @@ label:
i -= 1900;
if (c == 'y' && i < 69)
i += 100;
if (i < 0)
return 0;

tm->tm_year = i;

Expand Down
7 changes: 6 additions & 1 deletion t/02core.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test::More tests => 100;
use Test::More tests => 101;

my $is_win32 = ($^O =~ /Win32/);
my $is_qnx = ($^O eq 'qnx');
Expand Down Expand Up @@ -219,6 +219,11 @@ cmp_ok(
951827696
);

is(
eval { Time::Piece->strptime('1899-12-31', '%Y-%m-%d')->epoch() } || $@,
Time::Piece->strptime('1900-01-01', '%Y-%m-%d')->epoch - Time::Seconds::ONE_DAY,
'before 1900'
);

my $s = Time::Seconds->new(-691050);
is($s->pretty, 'minus 7 days, 23 hours, 57 minutes, 30 seconds');
Expand Down

0 comments on commit 7cec319

Please sign in to comment.