Skip to content

Commit 3a226be

Browse files
committed
Test all use-cases + fix
1 parent fa27a37 commit 3a226be

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/XMLSchema/Type/DateTimeValue.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ class DateTimeValue extends AbstractAnySimpleType
3333
protected function sanitizeValue(string $value): string
3434
{
3535
$normalized = static::collapseWhitespace(static::normalizeWhitespace($value));
36-
3736
// Trim any trailing zero's from the sub-seconds
3837
$decimal = strrpos($normalized, '.');
3938
if ($decimal !== false) {
40-
$timezone = strrpos($normalized, '+') ?? strrpos($normalized, '-') ?? strrpos($normalized, 'Z');
39+
@list($dateValue, $timeValue) = explode('T', $normalized);
40+
Assert::notNull($dateValue);
41+
Assert::notNull($timeValue);
42+
43+
$timezone = strrpos($timeValue, '+') ?: strrpos($timeValue, '-') ?: strrpos($timeValue, 'Z');
4144
if ($timezone !== false) {
42-
$subseconds = substr($normalized, $decimal + 1, strlen($normalized) - $timezone);
45+
$subseconds = substr($timeValue, $decimal + $timezone, strlen($timeValue) - $timezone);
4346
} else {
44-
$subseconds = substr($normalized, $decimal + 1);
47+
$subseconds = substr($timeValue, $decimal + 1);
4548
}
4649

4750
$subseconds = rtrim($subseconds, '0');

src/XMLSchema/Type/TimeValue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ protected function sanitizeValue(string $value): string
3232
// Trim any trailing zero's from the sub-seconds
3333
$decimal = strrpos($normalized, '.');
3434
if ($decimal !== false) {
35-
$timezone = strrpos($normalized, '+') ?? strrpos($normalized, '-') ?? strrpos($normalized, 'Z');
35+
$timezone = strrpos($normalized, '+') ?: strrpos($normalized, '-') ?: strrpos($normalized, 'Z');
3636
if ($timezone !== false) {
37-
$subseconds = substr($normalized, $decimal + 1, strlen($normalized) - $timezone);
37+
$subseconds = substr($normalized, $decimal + $timezone, strlen($normalized) - $timezone);
3838
} else {
3939
$subseconds = substr($normalized, $decimal + 1);
4040
}

tests/XMLSchema/Type/DateTimeValueTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ public static function provideValidDateTime(): array
6262
return [
6363
'whitespace collapse' => [true, ' 2001-10-26T21:32:52 '],
6464
'trailing sub-second zero' => [true, '2001-10-26T21:32:52.1230'],
65+
'trailing sub-second zero with timezone' => [true, '2001-10-26T21:32:52.1230+00:00'],
66+
'trailing sub-second zero with timezone Zulu' => [true, '2001-10-26T21:32:52.1230Z'],
6567
'all trailing sub-second zero' => [true, '2001-10-26T21:32:52.00'],
68+
'all trailing sub-second zero with timezone' => [true, '2001-10-26T21:32:52.00+00:00'],
69+
'all trailing sub-second zero with timezone Zulu' => [true, '2001-10-26T21:32:52.00Z'],
6670
];
6771
}
6872

tests/XMLSchema/Type/TimeValueTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ public static function provideValidTime(): array
4848
return [
4949
'whitespace collapse' => [true, "\n 21:32:52.12679\t "],
5050
'trailing sub-second zero' => [true, '21:32:52.1230'],
51-
'all trailing sub-second zero' => [true, '21:32:52.00'],
51+
'trailing sub-second zero with timezone' => [true, '21:32:52.1230+00:00'],
52+
'trailing sub-second zero with timezone Zulu' => [true, '21:32:52.1230Z'],
53+
'all trailing sub-second all zero' => [true, '21:32:52.00'],
54+
'all trailing sub-second all zero with timezone' => [true, '21:32:52.00+00:00'],
55+
'all trailing sub-second all zero with timezone Zulu' => [true, '21:32:52.00Z'],
5256
];
5357
}
5458

0 commit comments

Comments
 (0)