Skip to content

Commit 2caaaae

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

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

library/Helpers/CanValidateDateTime.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use function date_default_timezone_get;
1717
use function date_parse_from_format;
1818
use function preg_match;
19+
use function strlen;
20+
use function strrpos;
21+
use function substr;
1922

2023
/**
2124
* Helper to handle date/time.
@@ -43,6 +46,10 @@ private function isDateTime(string $format, string $value): bool
4346
}
4447

4548
if ($this->isDateFormat($format)) {
49+
if (($format === DateTime::RFC3339_EXTENDED || $format === DateTime::RFC3339) && strrpos($value, 'Z') === strlen($value) - 1) {
50+
$value = substr($value, 0, -1) . '+00:00';
51+
}
52+
4653
$formattedDate = DateTime::createFromFormat(
4754
'!' . $format,
4855
$value,

tests/unit/Helpers/CanValidateDateTimeTest.php

Lines changed: 3 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,8 @@ 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'],
62+
[DateTime::RFC3339, '2005-08-15T15:52:01Z'],
6063
];
6164
}
6265

0 commit comments

Comments
 (0)