From bef6d82cce1116e1fd005b0dc9b2a0e186738f5b Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 25 Sep 2013 11:17:05 -0700 Subject: [PATCH] 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 --- .../standard/PhabricatorStandardCustomFieldDate.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php index 0d8cd8ddae..943f6c1e91 100644 --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php @@ -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; }