mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-10 23:01:04 +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:
parent
4c2ff4fdee
commit
1b55c4bdc9
4 changed files with 31 additions and 10 deletions
|
@ -55,18 +55,25 @@ class PhabricatorCountdownEditController
|
||||||
$errors = array();
|
$errors = array();
|
||||||
$title = $request->getStr('title');
|
$title = $request->getStr('title');
|
||||||
$datepoint = $request->getStr('datepoint');
|
$datepoint = $request->getStr('datepoint');
|
||||||
$timestamp = strtotime($datepoint);
|
|
||||||
|
|
||||||
$e_text = null;
|
$e_text = null;
|
||||||
if (!strlen($title)) {
|
if (!strlen($title)) {
|
||||||
$e_text = 'Required';
|
$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'.
|
$errors[] = 'You entered an incorrect date. You can enter date like'.
|
||||||
' \'2011-06-26 13:33:37\' to create an event at'.
|
' \'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);
|
$timer->setTitle($title);
|
||||||
|
@ -77,8 +84,7 @@ class PhabricatorCountdownEditController
|
||||||
$timer->save();
|
$timer->save();
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
->setURI('/countdown/'.$timer->getID().'/');
|
->setURI('/countdown/'.$timer->getID().'/');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$error_view = id(new AphrontErrorView())
|
$error_view = id(new AphrontErrorView())
|
||||||
->setErrors($errors)
|
->setErrors($errors)
|
||||||
->setTitle('It\'s not The Final Countdown (du nu nuuu nun)' .
|
->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())
|
$form = id(new AphrontFormView())
|
||||||
->setUser($user)
|
->setUser($user)
|
||||||
->setAction($request->getRequestURI()->getPath())
|
->setAction($request->getRequestURI()->getPath())
|
||||||
|
@ -97,9 +111,13 @@ class PhabricatorCountdownEditController
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormTextControl())
|
id(new AphrontFormTextControl())
|
||||||
->setLabel('End date')
|
->setLabel('End date')
|
||||||
->setValue(strftime("%F %H:%M:%S", $timer->getDatePoint()))
|
->setValue($display_datepoint)
|
||||||
->setName('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(
|
->appendChild(
|
||||||
id(new AphrontFormSubmitControl())
|
id(new AphrontFormSubmitControl())
|
||||||
->addCancelButton('/countdown/')
|
->addCancelButton('/countdown/')
|
||||||
|
|
|
@ -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/control/text');
|
||||||
phutil_require_module('phabricator', 'view/form/error');
|
phutil_require_module('phabricator', 'view/form/error');
|
||||||
phutil_require_module('phabricator', 'view/layout/panel');
|
phutil_require_module('phabricator', 'view/layout/panel');
|
||||||
|
phutil_require_module('phabricator', 'view/utils');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'utils');
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,9 @@ class PhabricatorCountdownViewController
|
||||||
$content =
|
$content =
|
||||||
'<div class="phabricator-timer">
|
'<div class="phabricator-timer">
|
||||||
<h1 class="phabricator-timer-header">'.
|
<h1 class="phabricator-timer-header">'.
|
||||||
phutil_escape_html($timer->getTitle()).'
|
phutil_escape_html($timer->getTitle()).' · '.
|
||||||
</h1>
|
phabricator_datetime($timer->getDatePoint(), $user).
|
||||||
|
'</h1>
|
||||||
<div class="phabricator-timer-pane">
|
<div class="phabricator-timer-pane">
|
||||||
<table class="phabricator-timer-table">
|
<table class="phabricator-timer-table">
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'applications/countdown/controller/base');
|
||||||
phutil_require_module('phabricator', 'applications/countdown/storage/timer');
|
phutil_require_module('phabricator', 'applications/countdown/storage/timer');
|
||||||
phutil_require_module('phabricator', 'infrastructure/celerity/api');
|
phutil_require_module('phabricator', 'infrastructure/celerity/api');
|
||||||
phutil_require_module('phabricator', 'infrastructure/javelin/api');
|
phutil_require_module('phabricator', 'infrastructure/javelin/api');
|
||||||
|
phutil_require_module('phabricator', 'view/utils');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'markup');
|
phutil_require_module('phutil', 'markup');
|
||||||
phutil_require_module('phutil', 'utils');
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
Loading…
Reference in a new issue