Page MenuHomePhabricator

D13291.id32173.diff
No OneTemporary

D13291.id32173.diff

diff --git a/src/view/form/control/AphrontFormDateControl.php b/src/view/form/control/AphrontFormDateControl.php
--- a/src/view/form/control/AphrontFormDateControl.php
+++ b/src/view/form/control/AphrontFormDateControl.php
@@ -136,6 +136,14 @@
return $date;
}
+ private function getTimeFormat() {
+ $viewer = $this->getUser();
+ $preferences = $viewer->loadPreferences();
+ $pref_time_format = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
+
+ return $preferences->getPreference($pref_time_format, 'g:i A');
+ }
+
private function getDateFormat() {
$viewer = $this->getUser();
$preferences = $viewer->loadPreferences();
@@ -233,6 +241,7 @@
'startTimeID' => $time_id,
'endTimeID' => $this->endDateID,
'timeValues' => $values,
+ 'format' => $this->getTimeFormat(),
));
@@ -335,20 +344,31 @@
}
private function getTimeTypeaheadValues() {
+ $time_format = $this->getTimeFormat();
$times = array();
- $am_pm_list = array('AM', 'PM');
- foreach ($am_pm_list as $am_pm) {
- for ($hour = 0; $hour < 12; $hour++) {
- $actual_hour = ($hour == 0) ? 12 : $hour;
- $times[] = $actual_hour.':00 '.$am_pm;
- $times[] = $actual_hour.':30 '.$am_pm;
+ if ($time_format == 'g:i A') {
+ $am_pm_list = array('AM', 'PM');
+
+ foreach ($am_pm_list as $am_pm) {
+ for ($hour = 0; $hour < 12; $hour++) {
+ $actual_hour = ($hour == 0) ? 12 : $hour;
+ $times[] = $actual_hour.':00 '.$am_pm;
+ $times[] = $actual_hour.':30 '.$am_pm;
+ }
+ }
+ } else if ($time_format == 'H:i') {
+ for ($hour = 0; $hour < 24; $hour++) {
+ $written_hour = ($hour > 9) ? $hour : '0'.$hour;
+ $times[] = $written_hour.':00';
+ $times[] = $written_hour.':30';
}
}
foreach ($times as $key => $time) {
$times[$key] = array($key, $time);
}
+
return $times;
}
diff --git a/src/view/form/control/AphrontFormDateControlValue.php b/src/view/form/control/AphrontFormDateControlValue.php
--- a/src/view/form/control/AphrontFormDateControlValue.php
+++ b/src/view/form/control/AphrontFormDateControlValue.php
@@ -66,12 +66,13 @@
$value = new AphrontFormDateControlValue();
$value->viewer = $viewer;
- $value->valueDate = $value->getFormattedDateFromParts(
- $year,
- $month,
- $day,
- $value);
- $value->valueTime = coalesce($time, '12:00 AM');
+ list($value->valueDate, $value->valueTime) =
+ $value->getFormattedDateFromParts(
+ $year,
+ $month,
+ $day,
+ coalesce($time, '12:00 AM'),
+ $value);
$value->valueEnabled = $enabled;
return $value;
@@ -81,11 +82,12 @@
$value = new AphrontFormDateControlValue();
$value->viewer = $request->getViewer();
- $value->valueDate = $value->getFormattedDateFromDate(
- $request->getStr($key.'_d'),
- $value);
+ list($value->valueDate, $value->valueTime) =
+ $value->getFormattedDateFromDate(
+ $request->getStr($key.'_d'),
+ $request->getStr($key.'_t'),
+ $value);
- $value->valueTime = $request->getStr($key.'_t');
$value->valueEnabled = $request->getStr($key.'_e');
return $value;
}
@@ -99,14 +101,15 @@
$year = $readable[0];
$month = $readable[1];
$day = $readable[2];
+ $time = $readable[3];
- $value->valueDate = $value->getFormattedDateFromParts(
- $year,
- $month,
- $day,
- $value);
- $value->valueTime = $readable[3];
-
+ list($value->valueDate, $value->valueTime) =
+ $value->getFormattedDateFromParts(
+ $year,
+ $month,
+ $day,
+ $time,
+ $value);
return $value;
}
@@ -117,11 +120,12 @@
$value = new AphrontFormDateControlValue();
$value->viewer = $viewer;
- $value->valueDate = $value->getFormattedDateFromDate(
- idx($dictionary, 'd'),
- $value);
+ list($value->valueDate, $value->valueTime) =
+ $value->getFormattedDateFromDate(
+ idx($dictionary, 'd'),
+ idx($dictionary, 't'),
+ $value);
- $value->valueTime = idx($dictionary, 't');
$value->valueEnabled = idx($dictionary, 'e');
return $value;
@@ -200,6 +204,13 @@
return $value;
}
+ private function getTimeFormat() {
+ $preferences = $this->viewer->loadPreferences();
+ $pref_time_format = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
+
+ return $preferences->getPreference($pref_time_format, 'g:i A');
+ }
+
private function getDateFormat() {
$preferences = $this->viewer->loadPreferences();
$pref_date_format = PhabricatorUserPreferences::PREFERENCE_DATE_FORMAT;
@@ -207,7 +218,7 @@
return $preferences->getPreference($pref_date_format, 'Y-m-d');
}
- private function getFormattedDateFromDate($date, $value) {
+ private function getFormattedDateFromDate($date, $time, $value) {
$original_input = $date;
$zone = $value->getTimezone();
$separator = $value->getFormatSeparator();
@@ -216,17 +227,32 @@
$date = id(new DateTime($date, $zone));
if ($date) {
- return $date->format($value->getDateFormat());
+ $date = $date->format($value->getDateFormat());
} else {
- return $original_input;
+ $date = $original_input;
}
+
+ $date = id(new DateTime("{$date} {$time}", $zone));
+
+ return array(
+ $date->format($value->getDateFormat()),
+ $date->format($value->getTimeFormat()),
+ );
}
- private function getFormattedDateFromParts($year, $month, $day, $value) {
+ private function getFormattedDateFromParts(
+ $year,
+ $month,
+ $day,
+ $time,
+ $value) {
$zone = $value->getTimezone();
+ $date_time = id(new DateTime("{$year}-{$month}-{$day} {$time}", $zone));
- return id(new DateTime("{$year}-{$month}-{$day}", $zone))
- ->format($value->getDateFormat());
+ return array(
+ $date_time->format($value->getDateFormat()),
+ $date_time->format($value->getTimeFormat()),
+ );
}
private function getFormatSeparator() {
diff --git a/webroot/rsrc/js/core/behavior-time-typeahead.js b/webroot/rsrc/js/core/behavior-time-typeahead.js
--- a/webroot/rsrc/js/core/behavior-time-typeahead.js
+++ b/webroot/rsrc/js/core/behavior-time-typeahead.js
@@ -11,6 +11,7 @@
JX.behavior('time-typeahead', function(config) {
var start_date_control = JX.$(config.startTimeID);
var end_date_control = config.endTimeID ? JX.$(config.endTimeID) : null;
+ var format = config.format;
var end_date_tampered = false;
@@ -79,7 +80,7 @@
function getNewValue(time) {
- var regex = /^([01]?\d)(?::([0-5]\d))?\s*((am|pm))?$/i;
+ var regex = /^([0-2]?\d)(?::([0-5]\d))?\s*((am|pm))?$/i;
if (!regex.test(time)) {
return null;
@@ -90,32 +91,56 @@
var minutes = parseInt(results[2], 10) ? parseInt(results[2], 10) : 0;
var real_time = 0;
-
- if (/pm/i.test(results[3])) {
- real_time = 12*60;
- } else if (/am/i.test(results[3]) && hours == 12) {
- hours = 0;
+ var end_value = '';
+
+ var end_hours;
+ var end_minutes;
+
+ if (format === 'H:i' && hours < 23) {
+ end_hours = hours + 1;
+
+ if (end_hours > 9) {
+ end_hours = end_hours.toString();
+ } else {
+ end_hours = '0' + end_hours.toString();
+ }
+
+ if (minutes > 9) {
+ end_minutes = minutes.toString();
+ } else {
+ end_minutes = '0' + minutes.toString();
+ }
+
+ end_value = end_hours + ':' + end_minutes;
+ } else if (format === 'g:i A') {
+ if (/pm/i.test(results[3])) {
+ real_time = 12*60;
+ } else if (/am/i.test(results[3]) && hours == 12) {
+ hours = 0;
+ }
+
+ real_time = real_time + (hours * 60) + minutes;
+
+ var end_time = real_time + 60;
+
+ var end_meridian = 'AM';
+ end_hours = Math.floor(end_time / 60);
+
+ if (end_hours == 12) {
+ end_meridian = 'PM';
+ } else if (end_hours > 12 && end_hours < 24) {
+ end_hours = end_hours - 12;
+ end_meridian = 'PM';
+ } else if (end_hours == 24) {
+ end_hours = end_hours - 12;
+ }
+
+ end_minutes = end_time%60;
+ end_minutes = (end_minutes < 9) ? end_minutes : ('0' + end_minutes);
+ end_value = end_hours + ':' + end_minutes + ' ' + end_meridian;
}
- real_time = real_time + (hours * 60) + minutes;
-
- var end_time = real_time + 60;
-
- var end_meridian = 'AM';
- var end_hours = Math.floor(end_time / 60);
-
- if (end_hours == 12) {
- end_meridian = 'PM';
- } else if (end_hours > 12 && end_hours < 24) {
- end_hours = end_hours - 12;
- end_meridian = 'PM';
- } else if (end_hours == 24) {
- end_hours = end_hours - 12;
- }
- var end_minutes = end_time%60;
- end_minutes = (end_minutes > 9) ? end_minutes : ('0' + end_minutes);
- var end_value = end_hours + ':' + end_minutes + ' ' + end_meridian;
return end_value;
}

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 3:54 PM (10 h, 7 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6795232
Default Alt Text
D13291.id32173.diff (8 KB)

Event Timeline