Skip to content

Commit 3a1e542

Browse files
committed
Fix the handling of datetime string without a time zone
See https://www.woltlab.com/community/thread/314528/
1 parent 209d64b commit 3a1e542

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,28 @@ public function readValue()
296296

297297
if ($this->value === '') {
298298
$this->value = null;
299-
} elseif ($this->getValueDateTimeObject() === null) {
300-
try {
301-
$this->value($value);
302-
} catch (\InvalidArgumentException) {
303-
$this->value = null;
299+
} else {
300+
// Suppressing the time zone causes the generated datetime
301+
// string to omit the time zone entirely.
302+
//
303+
// 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.
306+
if (
307+
$this->supportsTime()
308+
&& $this->hasFieldAttribute('data-ignore-timezone')
309+
&& $this->getFieldAttribute('data-ignore-timezone') === 'true'
310+
) {
311+
$value .= 'Z';
312+
$this->value = $value;
313+
}
314+
315+
if ($this->getValueDateTimeObject() === null) {
316+
try {
317+
$this->value($value);
318+
} catch (\InvalidArgumentException) {
319+
$this->value = null;
320+
}
304321
}
305322
}
306323
}

0 commit comments

Comments
 (0)