Skip to content

Commit 341647e

Browse files
committed
Extract the absolute time away to show the differences in parsing
This makes it much easier to read what are the differences in parsing the positive & negative relative times. Next step is allowing for the CLICS absolute time format
1 parent 9b83162 commit 341647e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

webapp/src/Validator/Constraints/TimeStringValidator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class TimeStringValidator extends ConstraintValidator
1111
public function validate(mixed $value, Constraint $constraint): void
1212
{
1313
$timezoneRegex = "[A-Za-z][A-Za-z0-9_\/+-]{1,35}"; # See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
14+
$absoluteRegex = "\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(\.\d{1,6})? " . $timeZoneRegex;
1415
$relativeRegex = "\d+:\d\d(:\d\d(\.\d{1,6})?)?";
1516
if (!$constraint instanceof TimeString) {
1617
throw new UnexpectedTypeException($constraint, TimeString::class);
@@ -26,8 +27,8 @@ public function validate(mixed $value, Constraint $constraint): void
2627

2728
if ($constraint->allowRelative) {
2829
$regex = $constraint->relativeIsPositive ?
29-
"/^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(\.\d{1,6})? " . $timeZoneRegex . "|\+?" . $relativeRegex . ")$/" :
30-
"/^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(\.\d{1,6})? " . $timeZoneRegex . "|-" . $relativeRegex . ")$/";
30+
"/^(" . $absoluteRegex . "|\+?" . $relativeRegex . ")$/" :
31+
"/^(" . $absoluteRegex . "|-" . $relativeRegex . ")$/";
3132
$message = $constraint->absoluteRelativeMessage;
3233
} else {
3334
$regex = "/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(\.\d{1,6})? [A-Za-z][A-Za-z0-9_\/+-]{1,35}$/";

0 commit comments

Comments
 (0)