Changeset View
Changeset View
Standalone View
Standalone View
src/view/form/control/AphrontFormDateControl.php
| Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | public function setValue($epoch) { | ||||
| } | } | ||||
| $result = parent::setValue($epoch); | $result = parent::setValue($epoch); | ||||
| if ($epoch === null) { | if ($epoch === null) { | ||||
| return $result; | return $result; | ||||
| } | } | ||||
| $readable = $this->formatTime($epoch, 'Y!m!d!g:i A'); | $readable = $this->formatTime($epoch, 'Y!m!d!'.$this->getTimeFormat()); | ||||
epriestley: This fixes a bug with initial values in date controls with 24-hour time. | |||||
| $readable = explode('!', $readable, 4); | $readable = explode('!', $readable, 4); | ||||
| $year = $readable[0]; | $year = $readable[0]; | ||||
| $month = $readable[1]; | $month = $readable[1]; | ||||
| $day = $readable[2]; | $day = $readable[2]; | ||||
| $this->valueDate = $month.'/'.$day.'/'.$year; | $this->valueDate = $month.'/'.$day.'/'.$year; | ||||
| $this->valueTime = $readable[3]; | $this->valueTime = $readable[3]; | ||||
| Show All 10 Lines | private function getDateInputValue() { | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| return $this->valueDate; | return $this->valueDate; | ||||
| } | } | ||||
| return $datetime->format($date_format); | return $datetime->format($date_format); | ||||
| } | } | ||||
| private function getTimeFormat() { | private function getTimeFormat() { | ||||
| return $this->getViewer() | $viewer = $this->getViewer(); | ||||
| ->getPreference(PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT); | $time_key = PhabricatorTimeFormatSetting::SETTINGKEY; | ||||
| return $viewer->getUserSetting($time_key); | |||||
| } | } | ||||
| private function getDateFormat() { | private function getDateFormat() { | ||||
| return $this->getViewer() | $viewer = $this->getViewer(); | ||||
| ->getPreference(PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT); | $date_key = PhabricatorDateFormatSetting::SETTINGKEY; | ||||
| return $viewer->getUserSetting($date_key); | |||||
| } | } | ||||
| private function getTimeInputValue() { | private function getTimeInputValue() { | ||||
| return $this->valueTime; | return $this->valueTime; | ||||
| } | } | ||||
| private function formatTime($epoch, $fmt) { | private function formatTime($epoch, $fmt) { | ||||
| return phabricator_format_local_time( | return phabricator_format_local_time( | ||||
| ▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | protected function renderInput() { | ||||
| $time_id = celerity_generate_unique_node_id(); | $time_id = celerity_generate_unique_node_id(); | ||||
| Javelin::initBehavior('time-typeahead', array( | Javelin::initBehavior('time-typeahead', array( | ||||
| 'startTimeID' => $time_id, | 'startTimeID' => $time_id, | ||||
| 'endTimeID' => $this->endDateID, | 'endTimeID' => $this->endDateID, | ||||
| 'timeValues' => $values, | 'timeValues' => $values, | ||||
| 'format' => $this->getTimeFormat(), | 'format' => $this->getTimeFormat(), | ||||
| )); | )); | ||||
| $time_sel = javelin_tag( | $time_sel = javelin_tag( | ||||
| 'input', | 'input', | ||||
| array( | array( | ||||
| 'autocomplete' => 'off', | 'autocomplete' => 'off', | ||||
| 'name' => $this->getTimeInputName(), | 'name' => $this->getTimeInputName(), | ||||
| 'sigil' => 'time-input', | 'sigil' => 'time-input', | ||||
| 'value' => $this->getTimeInputValue(), | 'value' => $this->getTimeInputValue(), | ||||
| 'type' => 'text', | 'type' => 'text', | ||||
| 'class' => 'aphront-form-time-input', | 'class' => 'aphront-form-time-input', | ||||
| ), | ), | ||||
| ''); | ''); | ||||
| $time_div = javelin_tag( | $time_div = javelin_tag( | ||||
| 'div', | 'div', | ||||
| array( | array( | ||||
| 'id' => $time_id, | 'id' => $time_id, | ||||
| 'class' => 'aphront-form-time-input-container', | 'class' => 'aphront-form-time-input-container', | ||||
| ), | ), | ||||
| $time_sel); | $time_sel); | ||||
| $preferences = $this->getViewer()->loadPreferences(); | $viewer = $this->getViewer(); | ||||
| $pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; | $week_key = PhabricatorWeekStartDaySetting::SETTINGKEY; | ||||
| $week_start = $preferences->getPreference($pref_week_start, 0); | $week_start = $viewer->getUserSetting($week_key); | ||||
| Javelin::initBehavior('fancy-datepicker', array( | Javelin::initBehavior('fancy-datepicker', array( | ||||
| 'format' => $this->getDateFormat(), | 'format' => $this->getDateFormat(), | ||||
| 'weekStart' => $week_start, | 'weekStart' => $week_start, | ||||
| )); | )); | ||||
| $classes = array(); | $classes = array(); | ||||
| $classes[] = 'aphront-form-date-container'; | $classes[] = 'aphront-form-date-container'; | ||||
| ▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines | |||||
This fixes a bug with initial values in date controls with 24-hour time.