Allow standard date fields to read default dates as strings
Summary: Ref T2217. Fixes T3866. We need to do a little more massaging before we can set strings as the value on datetime controls. Test Plan: Set default to "1:23 AM", "2001/02/03". Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2217, T3866 Differential Revision: https://secure.phabricator.com/D7116
This commit is contained in:
@@ -65,7 +65,18 @@ final class PhabricatorStandardCustomFieldDate
|
||||
->setCaption($this->getCaption())
|
||||
->setAllowNull(!$this->getRequired());
|
||||
|
||||
$control->setValue($this->getFieldValue());
|
||||
// If the value is already numeric, treat it as an epoch timestamp and set
|
||||
// it directly. Otherwise, it's likely a field default, which we let users
|
||||
// specify as a string. Parse the string into an epoch.
|
||||
|
||||
$value = $this->getFieldValue();
|
||||
if (!ctype_digit($value)) {
|
||||
$value = PhabricatorTime::parseLocalTime($value, $this->getViewer());
|
||||
}
|
||||
|
||||
// If we don't have anything valid, make sure we pass `null`, since the
|
||||
// control special-cases that.
|
||||
$control->setValue(nonempty($value, null));
|
||||
|
||||
return $control;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user