Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Date/Parse.pm
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ sub {
if ($5) {
$year = $5;
# Possible match for 1995-01-24 or 31-12-2023
if ($month > 12) {
if ($month > 11) {
if ($1 > 31) {
# YYYY-MM-DD (mainframe date format)
($year,$month,$day) = ($1, $3 - 1, $5);
Expand Down
17 changes: 16 additions & 1 deletion t/ddmmyyyy.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 12;
use Test::More tests => 18;
use Date::Parse qw(strptime str2time);

# DD-MM-YYYY (European date format) — the first field exceeds 12,
Expand Down Expand Up @@ -33,3 +33,18 @@ is($r[4], 11, "31-12-96: month = 11 (December, 0-based)");
is($r[3], 24, "1995-01-24: day = 24");
is($r[4], 0, "1995-01-24: month = 0 (January, 0-based)");
is($r[5], 95, "1995-01-24: year = 95 (1995 - 1900)");

# 13-01-2025 → 13 Jan 2025
# Regression: first field = 13 produces $month = 12 (0-indexed),
# which is > 11 but was NOT > 12 in the old check, so the swap
# from MM-DD to DD-MM never triggered.
@r = strptime("13-01-2025");
is($r[3], 13, "13-01-2025: day = 13 (not treated as month)");
is($r[4], 0, "13-01-2025: month = 0 (January, 0-based)");
is($r[5], 125, "13-01-2025: year = 125 (2025 - 1900)");
ok(defined str2time("13-01-2025"), "str2time('13-01-2025') is defined");

# 14-02-2025 → 14 Feb 2025 (also affected by off-by-one)
@r = strptime("14-02-2025");
is($r[3], 14, "14-02-2025: day = 14");
is($r[4], 1, "14-02-2025: month = 1 (February, 0-based)");
Loading