Skip to content

Commit e922981

Browse files
committed
Fix BC break when using RFC3339 constants with Zulu timezone
1 parent 79f214c commit e922981

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

library/Helpers/CanValidateDateTime.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use function date_default_timezone_get;
1717
use function date_parse_from_format;
1818
use function preg_match;
19+
use function str_contains;
20+
use function str_replace;
1921

2022
/**
2123
* Helper to handle date/time.
@@ -49,6 +51,10 @@ private function isDateTime(string $format, string $value): bool
4951
new DateTimeZone(date_default_timezone_get())
5052
);
5153

54+
if ($format === DateTime::RFC3339_EXTENDED && str_contains($value, 'Z')) {
55+
$value = str_replace('Z', '+00:00', $value);
56+
}
57+
5258
if ($formattedDate === false || $value !== $formattedDate->format($format)) {
5359
return false;
5460
}

tests/unit/Helpers/CanValidateDateTimeTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Respect\Validation\Helpers;
1111

12+
use DateTime;
1213
use Respect\Validation\Test\TestCase;
1314

1415
/**
@@ -57,6 +58,7 @@ public static function providerForValidDateTime(): array
5758
['Y-m-d\TH:i:sP', '2018-01-30T19:04:35+00:00'],
5859
['r', 'Tue, 30 Jan 2018 19:06:01 +0000'],
5960
['D, d M Y H:i:s O', 'Tue, 30 Jan 2018 19:06:01 +0000'],
61+
[DateTime::RFC3339_EXTENDED, '2014-04-12T23:20:50.052Z'],
6062
];
6163
}
6264

0 commit comments

Comments
 (0)