Skip to content

Commit 360320e

Browse files
committed
Fix the timezone validator
Due to the new format we should check for different zones. We now either check for the timezones or for the offset as technically those are the same timezone but the idea was to require consistency.
1 parent 863f4a6 commit 360320e

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

webapp/src/Controller/Jury/ContestController.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,9 +956,22 @@ private function checkTimezones(FormInterface $form): ?Response
956956
foreach (['Activate', 'Deactivate', 'Start', 'End', 'Freeze', 'Unfreeze'] as $timeString) {
957957
$tmpValue = $formData->{'get' . $timeString . 'timeString'}();
958958
if ($tmpValue !== '' && !is_null($tmpValue)) {
959-
$fields = explode(' ', $tmpValue);
960-
if (count($fields) > 1) {
961-
$timeZones[] = $fields[2];
959+
if (preg_match("/\d{2}-\d{2}-\d{2}.*/", $tmpValue) === 1) {
960+
$chr = $tmpValue[10]; // The separator between date & time
961+
$fields = explode($chr, $tmpValue);
962+
// First field is the time, 2nd/3th might be timezone or offset
963+
$tmpValue = substr(str_replace($fields[0], '', $tmpValue), 1); // Also remove the separator
964+
if (str_contains($tmpValue, ' ')) {
965+
$fields = explode(' ', $tmpValue);
966+
} elseif (str_contains($tmpValue, '+')) {
967+
$fields = explode('+', $tmpValue);
968+
} elseif (substr($tmpValue, -1) === 'Z') {
969+
$timeZones[] = 'UTC';
970+
continue;
971+
}
972+
if (count($fields) > 1) {
973+
$timeZones[] = $fields[1];
974+
}
962975
}
963976
}
964977
}

0 commit comments

Comments
 (0)