@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Aviv Eyal and committed by
epriestley
cf138857 35b209c4

+64 -5
+6 -3
src/applications/people/storage/PhabricatorUser.php
··· 512 512 return $this->preferences; 513 513 } 514 514 515 - $preferences = id(new PhabricatorUserPreferences())->loadOneWhere( 516 - 'userPHID = %s', 517 - $this->getPHID()); 515 + $preferences = null; 516 + if ($this->getPHID()) { 517 + $preferences = id(new PhabricatorUserPreferences())->loadOneWhere( 518 + 'userPHID = %s', 519 + $this->getPHID()); 520 + } 518 521 519 522 if (!$preferences) { 520 523 $preferences = new PhabricatorUserPreferences();
+40
src/applications/settings/panel/PhabricatorSettingsPanelAccount.php
··· 17 17 18 18 public function processRequest(AphrontRequest $request) { 19 19 $user = $request->getUser(); 20 + 21 + $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; 22 + $preferences = $user->loadPreferences(); 23 + 20 24 $errors = array(); 21 25 if ($request->isFormPost()) { 22 26 $new_timezone = $request->getStr('timezone'); ··· 37 41 // Checked in runtime. 38 42 $user->setTranslation($request->getStr('translation')); 39 43 44 + $preferences->setPreference($pref_time, $request->getStr($pref_time)); 45 + 40 46 if (!$errors) { 47 + $preferences->save(); 41 48 $user->save(); 42 49 return id(new AphrontRedirectResponse()) 43 50 ->setURI($this->getPanelURI('?saved=true')); ··· 84 91 '' => pht('Server Default (%s)', $default->getName()), 85 92 ) + $translations; 86 93 94 + /* 95 + $time_format_instructions = pht( 96 + ' 97 + 'PHP format string to use for time. for full referance, see %s. '. 98 + 'For quick start, try `g:i A` or `H:i`', 99 + phutil_tag( 100 + 'a', 101 + array( 102 + 'href' => 'http://www.php.net/manual/en/function.date.php' 103 + ), 104 + pht('Date formats documentation'))); 105 + */ 87 106 88 107 $form = new AphrontFormView(); 89 108 $form ··· 106 125 ->setLabel(pht('Translation')) 107 126 ->setName('translation') 108 127 ->setValue($user->getTranslation())) 128 + ->appendRemarkupInstructions( 129 + pht( 130 + "**Custom Date and Time Formats**\n\n". 131 + "You can specify custom formats which will be used when ". 132 + "rendering dates and times of day. Examples:\n\n". 133 + "| Format | Example | Notes |\n". 134 + "| ------ | -------- | ----- |\n". 135 + "| `g:i A` | 2:34 PM | Default 12-hour time. |\n". 136 + "| `G.i a` | 02.34 pm | Alternate 12-hour time. |\n". 137 + "| `H:i` | 14:34 | 24-hour time. |\n". 138 + "\n\n". 139 + "You can find a [[%s | full reference in the PHP manual]].", 140 + "http://www.php.net/manual/en/function.date.php" 141 + )) 142 + ->appendChild( 143 + id(new AphrontFormTextControl()) 144 + ->setLabel(pht('Time-of-Day Format')) 145 + ->setName($pref_time) 146 + ->setCaption( 147 + pht('Format used when rendering a time of day.')) 148 + ->setValue($preferences->getPreference($pref_time))) 109 149 ->appendChild( 110 150 id(new AphrontFormSubmitControl()) 111 151 ->setValue(pht('Save Account Settings')));
+1
src/applications/settings/storage/PhabricatorUserPreferences.php
··· 8 8 const PREFERENCE_MULTIEDIT = 'multiedit'; 9 9 const PREFERENCE_TITLES = 'titles'; 10 10 const PREFERENCE_MONOSPACED_TEXTAREAS = 'monospaced-textareas'; 11 + const PREFERENCE_TIME_FORMAT = 'time-format'; 11 12 12 13 const PREFERENCE_RE_PREFIX = 're-prefix'; 13 14 const PREFERENCE_NO_SELF_MAIL = 'self-mail';
+17 -2
src/view/viewutils.php
··· 38 38 return phabricator_format_local_time( 39 39 $epoch, 40 40 $user, 41 - pht('g:i A')); 41 + _phabricator_time_format($user)); 42 42 } 43 43 44 44 function phabricator_datetime($epoch, $user) { 45 45 return phabricator_format_local_time( 46 46 $epoch, 47 47 $user, 48 - pht('%s, g:i A', _phabricator_date_format($epoch))); 48 + pht('%s, %s', 49 + _phabricator_date_format($epoch), 50 + _phabricator_time_format($user))); 49 51 } 50 52 51 53 function _phabricator_date_format($epoch) { ··· 57 59 $format = pht('M j Y'); 58 60 } 59 61 return $format; 62 + } 63 + 64 + function _phabricator_time_format($user) { 65 + $prefs = $user->loadPreferences(); 66 + 67 + $pref = $prefs->getPreference( 68 + PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT); 69 + 70 + if (strlen($pref)) { 71 + return $pref; 72 + } 73 + 74 + return pht('g:i A'); 60 75 } 61 76 62 77 /**