1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Make "Countdown" aware of time locales

Summary:
When you type "5 PM", it should mean "5 PM in your local time", not "5 PM in the
server's time". Use locale-aware functions to read and write times.

Also a couple of usability tweaks.

Test Plan:
Swapped my time between America/Los_Angeles and America/New_York and created a
bunch of countdowns.

Reviewed By: jungejason
Reviewers: hsb, toulouse, jungejason, tuomaspelkonen, aran
CC: aran, jungejason
Differential Revision: 531
This commit is contained in:
epriestley 2011-06-26 10:51:59 -07:00
parent 4c2ff4fdee
commit 1b55c4bdc9
4 changed files with 31 additions and 10 deletions

View file

@ -55,18 +55,25 @@ class PhabricatorCountdownEditController
$errors = array();
$title = $request->getStr('title');
$datepoint = $request->getStr('datepoint');
$timestamp = strtotime($datepoint);
$e_text = null;
if (!strlen($title)) {
$e_text = 'Required';
$errors[] = 'You must give it a name';
$errors[] = 'You must give it a name.';
}
if ($timestamp === false) {
// If the user types something like "5 PM", convert it to a timestamp
// using their local time, not the server time.
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
try {
$date = new DateTime($datepoint, $timezone);
$timestamp = $date->format('U');
} catch (Exception $e) {
$errors[] = 'You entered an incorrect date. You can enter date like'.
' \'2011-06-26 13:33:37\' to create an event at'.
' 13:33:37 on the 26th of June 2011';
' 13:33:37 on the 26th of June 2011.';
$timestamp = null;
}
$timer->setTitle($title);
@ -77,8 +84,7 @@ class PhabricatorCountdownEditController
$timer->save();
return id(new AphrontRedirectResponse())
->setURI('/countdown/'.$timer->getID().'/');
}
else {
} else {
$error_view = id(new AphrontErrorView())
->setErrors($errors)
->setTitle('It\'s not The Final Countdown (du nu nuuu nun)' .
@ -86,6 +92,14 @@ class PhabricatorCountdownEditController
}
}
if ($timer->getDatePoint()) {
$display_datepoint = phabricator_datetime(
$timer->getDatePoint(),
$user);
} else {
$display_datepoint = $request->getStr('datepoint');
}
$form = id(new AphrontFormView())
->setUser($user)
->setAction($request->getRequestURI()->getPath())
@ -97,9 +111,13 @@ class PhabricatorCountdownEditController
->appendChild(
id(new AphrontFormTextControl())
->setLabel('End date')
->setValue(strftime("%F %H:%M:%S", $timer->getDatePoint()))
->setValue($display_datepoint)
->setName('datepoint')
->setCaption('Post any date that is parsable by strtotime'))
->setCaption(
'Examples: '.
'<tt>2011-12-25</tt> or '.
'<tt>3 hours</tt> or '.
'<tt>June 8 2011, 5 PM</tt>.'))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton('/countdown/')

View file

@ -15,6 +15,7 @@ phutil_require_module('phabricator', 'view/form/control/submit');
phutil_require_module('phabricator', 'view/form/control/text');
phutil_require_module('phabricator', 'view/form/error');
phutil_require_module('phabricator', 'view/layout/panel');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'utils');

View file

@ -49,8 +49,9 @@ class PhabricatorCountdownViewController
$content =
'<div class="phabricator-timer">
<h1 class="phabricator-timer-header">'.
phutil_escape_html($timer->getTitle()).'
</h1>
phutil_escape_html($timer->getTitle()).' &middot; '.
phabricator_datetime($timer->getDatePoint(), $user).
'</h1>
<div class="phabricator-timer-pane">
<table class="phabricator-timer-table">
<tr>

View file

@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'applications/countdown/controller/base');
phutil_require_module('phabricator', 'applications/countdown/storage/timer');
phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'infrastructure/javelin/api');
phutil_require_module('phabricator', 'view/utils');
phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'utils');