From 8d5b9351d1d8774445112c46b561d0a658c621a4 Mon Sep 17 00:00:00 2001 From: Florian Guimier Date: Thu, 5 Nov 2026 14:22:39 +0100 Subject: [PATCH 1/2] IT9PE1-33922: accept backward-compatible timezone aliases \DateTimeZone accepts aliases such as US/Hawaii, so a value it built can be stored and then fail the Timezone constraint on every later update. Co-Authored-By: Claude Opus 5.5 --- .../Constraints/TimezoneValidator.php | 3 ++- .../Constraints/TimezoneValidatorTest.php | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Validator/Constraints/TimezoneValidator.php b/src/Validator/Constraints/TimezoneValidator.php index d047a99..7f5ee00 100644 --- a/src/Validator/Constraints/TimezoneValidator.php +++ b/src/Validator/Constraints/TimezoneValidator.php @@ -30,7 +30,8 @@ public function validate(mixed $value, Constraint $constraint): void $value = $this->getValue($value); - if (!in_array($value, \DateTimeZone::listIdentifiers(), true)) { + // \DateTimeZone accepts backward-compatible aliases (US/Hawaii), so stored values may hold them. + if (!in_array($value, \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC), true)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) ->setCode(Timezone::NO_SUCH_TIMEZONE_ERROR) diff --git a/tests/Validator/Constraints/TimezoneValidatorTest.php b/tests/Validator/Constraints/TimezoneValidatorTest.php index 7c023be..a9c6eaf 100644 --- a/tests/Validator/Constraints/TimezoneValidatorTest.php +++ b/tests/Validator/Constraints/TimezoneValidatorTest.php @@ -32,6 +32,21 @@ public function testExpectsStringCompatibleType(): void $this->validator->validate(new \stdClass(), new Timezone()); } + public function testAcceptsBackwardCompatibleAlias(): void + { + $aliases = array_diff( + \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC), + \DateTimeZone::listIdentifiers(), + ); + if ([] === $aliases) { + self::markTestSkipped('The timezone database of this platform has no backward-compatible alias.'); + } + + $this->validator->validate(reset($aliases), new Timezone()); + + $this->assertNoViolation(); + } + public static function providerValidValues(): iterable { yield [null]; @@ -48,5 +63,10 @@ public static function providerInvalidValues(): iterable Timezone::NO_SUCH_TIMEZONE_ERROR, 'The value {{ value }} is not a valid timezone.', ]; + yield [ + 'US/Atlantis', + Timezone::NO_SUCH_TIMEZONE_ERROR, + 'The value {{ value }} is not a valid timezone.', + ]; } } From eea622190e9ac2d372da2034172f4fcc5f5500ee Mon Sep 17 00:00:00 2001 From: Florian Guimier Date: Thu, 5 Nov 2026 14:30:59 +0100 Subject: [PATCH 2/2] IT9PE1-33922: keep only the lasting constraint in the validator comment (review gate finding) Co-Authored-By: Claude Opus 5.5 --- src/Validator/Constraints/TimezoneValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Validator/Constraints/TimezoneValidator.php b/src/Validator/Constraints/TimezoneValidator.php index 7f5ee00..6c913c3 100644 --- a/src/Validator/Constraints/TimezoneValidator.php +++ b/src/Validator/Constraints/TimezoneValidator.php @@ -30,7 +30,7 @@ public function validate(mixed $value, Constraint $constraint): void $value = $this->getValue($value); - // \DateTimeZone accepts backward-compatible aliases (US/Hawaii), so stored values may hold them. + // Mirror \DateTimeZone, which also accepts backward-compatible aliases (US/Hawaii). if (!in_array($value, \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC), true)) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value))