1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

User preference for time format

Summary: Also, don't try to load prefs for non-users.

Test Plan: toggle, save, look at something with a time. arc unit.

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, aran

Differential Revision: https://secure.phabricator.com/D6796
This commit is contained in:
Aviv Eyal 2013-09-02 12:40:04 -07:00 committed by epriestley
parent 35b209c464
commit cf13885736
4 changed files with 64 additions and 5 deletions

View file

@ -512,9 +512,12 @@ final class PhabricatorUser
return $this->preferences;
}
$preferences = id(new PhabricatorUserPreferences())->loadOneWhere(
'userPHID = %s',
$this->getPHID());
$preferences = null;
if ($this->getPHID()) {
$preferences = id(new PhabricatorUserPreferences())->loadOneWhere(
'userPHID = %s',
$this->getPHID());
}
if (!$preferences) {
$preferences = new PhabricatorUserPreferences();

View file

@ -17,6 +17,10 @@ final class PhabricatorSettingsPanelAccount
public function processRequest(AphrontRequest $request) {
$user = $request->getUser();
$pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT;
$preferences = $user->loadPreferences();
$errors = array();
if ($request->isFormPost()) {
$new_timezone = $request->getStr('timezone');
@ -37,7 +41,10 @@ final class PhabricatorSettingsPanelAccount
// Checked in runtime.
$user->setTranslation($request->getStr('translation'));
$preferences->setPreference($pref_time, $request->getStr($pref_time));
if (!$errors) {
$preferences->save();
$user->save();
return id(new AphrontRedirectResponse())
->setURI($this->getPanelURI('?saved=true'));
@ -84,6 +91,18 @@ final class PhabricatorSettingsPanelAccount
'' => pht('Server Default (%s)', $default->getName()),
) + $translations;
/*
$time_format_instructions = pht(
'
'PHP format string to use for time. for full referance, see %s. '.
'For quick start, try `g:i A` or `H:i`',
phutil_tag(
'a',
array(
'href' => 'http://www.php.net/manual/en/function.date.php'
),
pht('Date formats documentation')));
*/
$form = new AphrontFormView();
$form
@ -106,6 +125,27 @@ final class PhabricatorSettingsPanelAccount
->setLabel(pht('Translation'))
->setName('translation')
->setValue($user->getTranslation()))
->appendRemarkupInstructions(
pht(
"**Custom Date and Time Formats**\n\n".
"You can specify custom formats which will be used when ".
"rendering dates and times of day. Examples:\n\n".
"| Format | Example | Notes |\n".
"| ------ | -------- | ----- |\n".
"| `g:i A` | 2:34 PM | Default 12-hour time. |\n".
"| `G.i a` | 02.34 pm | Alternate 12-hour time. |\n".
"| `H:i` | 14:34 | 24-hour time. |\n".
"\n\n".
"You can find a [[%s | full reference in the PHP manual]].",
"http://www.php.net/manual/en/function.date.php"
))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Time-of-Day Format'))
->setName($pref_time)
->setCaption(
pht('Format used when rendering a time of day.'))
->setValue($preferences->getPreference($pref_time)))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save Account Settings')));

View file

@ -8,6 +8,7 @@ final class PhabricatorUserPreferences extends PhabricatorUserDAO {
const PREFERENCE_MULTIEDIT = 'multiedit';
const PREFERENCE_TITLES = 'titles';
const PREFERENCE_MONOSPACED_TEXTAREAS = 'monospaced-textareas';
const PREFERENCE_TIME_FORMAT = 'time-format';
const PREFERENCE_RE_PREFIX = 're-prefix';
const PREFERENCE_NO_SELF_MAIL = 'self-mail';

View file

@ -38,14 +38,16 @@ function phabricator_time($epoch, $user) {
return phabricator_format_local_time(
$epoch,
$user,
pht('g:i A'));
_phabricator_time_format($user));
}
function phabricator_datetime($epoch, $user) {
return phabricator_format_local_time(
$epoch,
$user,
pht('%s, g:i A', _phabricator_date_format($epoch)));
pht('%s, %s',
_phabricator_date_format($epoch),
_phabricator_time_format($user)));
}
function _phabricator_date_format($epoch) {
@ -59,6 +61,19 @@ function _phabricator_date_format($epoch) {
return $format;
}
function _phabricator_time_format($user) {
$prefs = $user->loadPreferences();
$pref = $prefs->getPreference(
PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT);
if (strlen($pref)) {
return $pref;
}
return pht('g:i A');
}
/**
* This function does not usually need to be called directly. Instead, call
* @{function:phabricator_date}, @{function:phabricator_time}, or