Skip to content

Commit

Permalink
Countdown - use better date control
Browse files Browse the repository at this point in the history
Summary: Fixes T3576

Test Plan: made a countdown and it looked right on view. edited it and it had the right values pre and post edit.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T3576

Differential Revision: https://secure.phabricator.com/D8754
  • Loading branch information
bobtrahan committed Apr 11, 2014
1 parent 650bc97 commit 524e8a6
Showing 1 changed file with 11 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public function processRequest() {

$request = $this->getRequest();
$user = $request->getUser();
$epoch_control = id(new AphrontFormDateControl())
->setUser($user)
->setName('epoch')
->setLabel(pht('End Date'))
->setInitialTime(AphrontFormDateControl::TIME_END_OF_DAY);

if ($this->id) {
$page_title = pht('Edit Countdown');
Expand All @@ -34,38 +39,27 @@ public function processRequest() {
$page_title = pht('Create Countdown');
$countdown = PhabricatorCountdown::initializeNewCountdown($user);
}
$epoch_control->setValue($countdown->getEpoch());

$e_text = true;
$e_epoch = null;

$errors = array();
if ($request->isFormPost()) {
$title = $request->getStr('title');
$epoch = $request->getStr('epoch');
$epoch = $epoch_control->readValueFromRequest($request);
$view_policy = $request->getStr('viewPolicy');

$e_text = null;
if (!strlen($title)) {
$e_text = pht('Required');
$errors[] = pht('You must give the countdown a name.');
}

if (strlen($epoch)) {
$timestamp = PhabricatorTime::parseLocalTime($epoch, $user);
if (!$timestamp) {
$errors[] = pht(
'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.');
}
} else {
$e_epoch = pht('Required');
$errors[] = pht('You must specify the end date for a countdown.');
if (!$epoch) {
$errors[] = pht('You must give the countdown a valid end date.');
}

if (!count($errors)) {
$countdown->setTitle($title);
$countdown->setEpoch($timestamp);
$countdown->setEpoch($epoch);
$countdown->setViewPolicy($view_policy);
$countdown->save();
return id(new AphrontRedirectResponse())
Expand Down Expand Up @@ -106,15 +100,7 @@ public function processRequest() {
->setValue($countdown->getTitle())
->setName('title')
->setError($e_text))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('End Date'))
->setValue($display_epoch)
->setName('epoch')
->setError($e_epoch)
->setCaption(pht('Examples: '.
'2011-12-25 or 3 hours or '.
'June 8 2011, 5 PM.')))
->appendChild($epoch_control)
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)
Expand Down

0 comments on commit 524e8a6

Please sign in to comment.