Skip to content

Commit f24376a

Browse files
committed
Convert the broken date time value into something reasonable
Follow up of 3a1e542 which does not properly handle repeated edits.
1 parent 3a1e542 commit f24376a

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

wcfsetup/install/files/lib/system/form/builder/field/DateFormField.class.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,21 +301,30 @@ public function readValue()
301301
// string to omit the time zone entirely.
302302
//
303303
// This is an incorrect behavior of the JS component which we
304-
// cannot fix for compatibility reasons. We therefore implicitly
305-
// assume Zulu time here.
304+
// cannot fix for compatibility reasons.
305+
$isValidTime = false;
306306
if (
307307
$this->supportsTime()
308308
&& $this->hasFieldAttribute('data-ignore-timezone')
309309
&& $this->getFieldAttribute('data-ignore-timezone') === 'true'
310310
) {
311-
$value .= 'Z';
312-
$this->value = $value;
311+
$dateTime = \DateTime::createFromFormat(
312+
'Y-m-d\TH:i:s',
313+
$this->getValue(),
314+
new \DateTimeZone('UTC')
315+
);
316+
317+
if ($dateTime !== false) {
318+
$isValidTime = true;
319+
320+
$this->value = $dateTime->format(self::TIME_FORMAT);
321+
}
313322
}
314323

315-
if ($this->getValueDateTimeObject() === null) {
324+
if (!$isValidTime && $this->getValueDateTimeObject() === null) {
316325
try {
317326
$this->value($value);
318-
} catch (\InvalidArgumentException) {
327+
} catch (\InvalidArgumentException $e) {
319328
$this->value = null;
320329
}
321330
}

0 commit comments

Comments
 (0)