@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.

Remove user-independent date and time functions from Phabricator

Summary: These have been moved into libphutil.

Test Plan: Browsed Phabricator, didn't see a crash.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D9907

+38 -212
-6
src/__phutil_library_map__.php
··· 2709 2709 ), 2710 2710 'function' => 2711 2711 array( 2712 - '_phabricator_date_format' => 'view/viewutils.php', 2713 2712 '_phabricator_time_format' => 'view/viewutils.php', 2714 2713 'celerity_generate_unique_node_id' => 'infrastructure/celerity/api.php', 2715 2714 'celerity_get_resource_uri' => 'infrastructure/celerity/api.php', ··· 2718 2717 'phabricator_date' => 'view/viewutils.php', 2719 2718 'phabricator_datetime' => 'view/viewutils.php', 2720 2719 'phabricator_form' => 'infrastructure/javelin/markup.php', 2721 - 'phabricator_format_bytes' => 'view/viewutils.php', 2722 2720 'phabricator_format_local_time' => 'view/viewutils.php', 2723 - 'phabricator_format_relative_time' => 'view/viewutils.php', 2724 - 'phabricator_format_relative_time_detailed' => 'view/viewutils.php', 2725 - 'phabricator_format_units_generic' => 'view/viewutils.php', 2726 2721 'phabricator_on_relative_date' => 'view/viewutils.php', 2727 - 'phabricator_parse_bytes' => 'view/viewutils.php', 2728 2722 'phabricator_relative_date' => 'view/viewutils.php', 2729 2723 'phabricator_time' => 'view/viewutils.php', 2730 2724 'phid_get_subtype' => 'applications/phid/utils.php',
+1 -1
src/applications/conduit/method/ConduitAPI_conduit_connect_Method.php
··· 125 125 'timestamp must differ from the server time by no more than '. 126 126 '%s seconds. Your client or server clock may not be set '. 127 127 'correctly.', 128 - phabricator_format_relative_time($threshold), 128 + phutil_format_relative_time($threshold), 129 129 $token, 130 130 date('r', $token), 131 131 $now,
+7 -7
src/applications/daemon/controller/PhabricatorDaemonLogViewController.php
··· 109 109 $details = pht( 110 110 'This daemon is running normally and reported a status update '. 111 111 'recently (within %s).', 112 - phabricator_format_relative_time($unknown_time)); 112 + phutil_format_relative_time($unknown_time)); 113 113 break; 114 114 case PhabricatorDaemonLog::STATUS_UNKNOWN: 115 115 $details = pht( 116 116 'This daemon has not reported a status update recently (within %s). '. 117 117 'It may have exited abruptly. After %s, it will be presumed dead.', 118 - phabricator_format_relative_time($unknown_time), 119 - phabricator_format_relative_time($dead_time)); 118 + phutil_format_relative_time($unknown_time), 119 + phutil_format_relative_time($dead_time)); 120 120 break; 121 121 case PhabricatorDaemonLog::STATUS_DEAD: 122 122 $details = pht( ··· 124 124 'presumed dead. Usually, this indicates that the daemon was '. 125 125 'killed or otherwise exited abruptly with an error. You may '. 126 126 'need to restart it.', 127 - phabricator_format_relative_time($dead_time)); 127 + phutil_format_relative_time($dead_time)); 128 128 break; 129 129 case PhabricatorDaemonLog::STATUS_WAIT: 130 130 $details = pht( ··· 133 133 'doing work and is waiting a little while (%s) to resume '. 134 134 'processing. After encountering an error, daemons wait before '. 135 135 'resuming work to avoid overloading services.', 136 - phabricator_format_relative_time($unknown_time), 137 - phabricator_format_relative_time($wait_time)); 136 + phutil_format_relative_time($unknown_time), 137 + phutil_format_relative_time($wait_time)); 138 138 break; 139 139 case PhabricatorDaemonLog::STATUS_EXITED: 140 140 $details = pht( ··· 152 152 pht('Seen'), 153 153 pht( 154 154 '%s ago (%s)', 155 - phabricator_format_relative_time(time() - $u_epoch), 155 + phutil_format_relative_time(time() - $u_epoch), 156 156 phabricator_datetime($u_epoch, $viewer))); 157 157 158 158 $argv = $daemon->getArgv();
+2 -2
src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php
··· 174 174 175 175 if ($task->getLeaseExpires() && $task->getLeaseOwner()) { 176 176 $expires = ($task->getLeaseExpires() - time()); 177 - $expires = phabricator_format_relative_time_detailed($expires); 177 + $expires = phutil_format_relative_time_detailed($expires); 178 178 } else { 179 179 $expires = phutil_tag('em', array(), pht('None')); 180 180 } ··· 247 247 $duration = 60; 248 248 } 249 249 $cumulative += $duration; 250 - $next[$key] = phabricator_format_relative_time($cumulative); 250 + $next[$key] = phutil_format_relative_time($cumulative); 251 251 } 252 252 if ($ii != $retry_count) { 253 253 $next[] = '...';
+1 -1
src/applications/files/controller/PhabricatorFileInfoController.php
··· 179 179 180 180 $finfo->addProperty( 181 181 pht('Size'), 182 - phabricator_format_bytes($file->getByteSize())); 182 + phutil_format_bytes($file->getByteSize())); 183 183 184 184 $finfo->addProperty( 185 185 pht('Mime Type'),
+2 -2
src/applications/files/controller/PhabricatorFileUploadController.php
··· 86 86 87 87 private function renderUploadLimit() { 88 88 $limit = PhabricatorEnv::getEnvConfig('storage.upload-size-limit'); 89 - $limit = phabricator_parse_bytes($limit); 89 + $limit = phutil_parse_bytes($limit); 90 90 if ($limit) { 91 - $formatted = phabricator_format_bytes($limit); 91 + $formatted = phutil_format_bytes($limit); 92 92 return 'Maximum file size: '.$formatted; 93 93 } 94 94
+1 -1
src/applications/files/query/PhabricatorFileSearchEngine.php
··· 166 166 ->setHeader($name) 167 167 ->setHref($file_uri) 168 168 ->addAttribute($uploaded) 169 - ->addIcon('none', phabricator_format_bytes($file->getByteSize())); 169 + ->addIcon('none', phutil_format_bytes($file->getByteSize())); 170 170 171 171 $ttl = $file->getTTL(); 172 172 if ($ttl !== null) {
+1 -1
src/applications/files/storage/PhabricatorFile.php
··· 108 108 return; 109 109 } 110 110 111 - $limit = phabricator_parse_bytes($limit); 111 + $limit = phutil_parse_bytes($limit); 112 112 if ($size > $limit) { 113 113 throw new PhabricatorFileUploadException(-1000); 114 114 }
+1 -1
src/applications/notification/controller/PhabricatorNotificationStatusController.php
··· 41 41 switch ($key) { 42 42 case 'uptime': 43 43 $value /= 1000; 44 - $value = phabricator_format_relative_time_detailed($value); 44 + $value = phutil_format_relative_time_detailed($value); 45 45 break; 46 46 case 'log': 47 47 break;
+1 -1
src/applications/people/customfield/PhabricatorUserSinceField.php
··· 26 26 $this->getObject()->getDateCreated(), 27 27 $this->getViewer()); 28 28 29 - $relative = phabricator_format_relative_time_detailed( 29 + $relative = phutil_format_relative_time_detailed( 30 30 time() - $this->getObject()->getDateCreated(), 31 31 $levels = 2); 32 32
+1 -1
src/applications/phrequent/event/PhrequentUIEventListener.php
··· 138 138 139 139 $block = new PhrequentTimeBlock($event_group); 140 140 $item->setNote( 141 - phabricator_format_relative_time( 141 + phutil_format_relative_time( 142 142 $block->getTimeSpentOnObject( 143 143 $object->getPHID(), 144 144 time())));
+1 -1
src/applications/phrequent/query/PhrequentSearchEngine.php
··· 166 166 } 167 167 168 168 $time_spent = $time_spent == 0 ? 'none' : 169 - phabricator_format_relative_time_detailed($time_spent); 169 + phutil_format_relative_time_detailed($time_spent); 170 170 171 171 if ($usertime->getDateEnded() !== null) { 172 172 $item->addAttribute(
+1 -1
src/applications/releeph/controller/request/ReleephRequestEditController.php
··· 195 195 196 196 $age_string = ''; 197 197 if ($is_edit) { 198 - $age_string = phabricator_format_relative_time( 198 + $age_string = phutil_format_relative_time( 199 199 time() - $pull->getDateCreated()).' ago'; 200 200 } 201 201
+1 -1
src/applications/releeph/controller/request/ReleephRequestTypeaheadController.php
··· 56 56 $full_commit_id, 57 57 $short_commit_id, 58 58 $row['authorName'], 59 - phabricator_format_relative_time($now - $row['epoch']), 59 + phutil_format_relative_time($now - $row['epoch']), 60 60 $first_line, 61 61 ); 62 62 }
+2 -2
src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
··· 469 469 470 470 $size = strlen($raw_diff); 471 471 if ($byte_limit && $size > $byte_limit) { 472 - $pretty_size = phabricator_format_bytes($size); 473 - $pretty_limit = phabricator_format_bytes($byte_limit); 472 + $pretty_size = phutil_format_bytes($size); 473 + $pretty_limit = phutil_format_bytes($byte_limit); 474 474 throw new Exception( 475 475 "Patch size of {$pretty_size} exceeds configured byte size limit of ". 476 476 "{$pretty_limit}.");
+1 -1
src/applications/settings/panel/PhabricatorSettingsPanelSessions.php
··· 78 78 substr($session->getSessionKey(), 0, 6), 79 79 $session->getType(), 80 80 ($hisec > 0) 81 - ? phabricator_format_relative_time($hisec) 81 + ? phutil_format_relative_time($hisec) 82 82 : null, 83 83 phabricator_datetime($session->getSessionStart(), $viewer), 84 84 phabricator_date($session->getSessionExpires(), $viewer),
+11 -11
src/view/__tests__/PhabricatorUnitsTestCase.php
··· 19 19 foreach ($tests as $input => $expect) { 20 20 $this->assertEqual( 21 21 $expect, 22 - phabricator_format_bytes($input), 23 - 'phabricator_format_bytes('.$input.')'); 22 + phutil_format_bytes($input), 23 + 'phutil_format_bytes('.$input.')'); 24 24 } 25 25 } 26 26 ··· 42 42 foreach ($tests as $input => $expect) { 43 43 $this->assertEqual( 44 44 $expect, 45 - phabricator_parse_bytes($input), 46 - 'phabricator_parse_bytes('.$input.')'); 45 + phutil_parse_bytes($input), 46 + 'phutil_parse_bytes('.$input.')'); 47 47 } 48 48 49 49 $this->tryTestCases( 50 50 array('string' => 'string'), 51 51 array(false), 52 - 'phabricator_parse_bytes'); 52 + 'phutil_parse_bytes'); 53 53 } 54 54 55 55 public function testDetailedDurationFormatting() { ··· 68 68 foreach ($tests as $duration => $expect) { 69 69 $this->assertEqual( 70 70 $expect, 71 - phabricator_format_relative_time_detailed($duration), 72 - 'phabricator_format_relative_time_detailed('.$duration.')'); 71 + phutil_format_relative_time_detailed($duration), 72 + 'phutil_format_relative_time_detailed('.$duration.')'); 73 73 } 74 74 75 75 ··· 113 113 foreach ($sub_tests as $levels => $expect) { 114 114 $this->assertEqual( 115 115 $expect, 116 - phabricator_format_relative_time_detailed($duration, $levels), 117 - 'phabricator_format_relative_time_detailed('.$duration.', 116 + phutil_format_relative_time_detailed($duration, $levels), 117 + 'phutil_format_relative_time_detailed('.$duration.', 118 118 '.$levels.')'); 119 119 } 120 120 } else { 121 121 $expect = $sub_tests; 122 122 $this->assertEqual( 123 123 $expect, 124 - phabricator_format_relative_time_detailed($duration), 125 - 'phabricator_format_relative_time_detailed('.$duration.')'); 124 + phutil_format_relative_time_detailed($duration), 125 + 'phutil_format_relative_time_detailed('.$duration.')'); 126 126 127 127 } 128 128 }
+1 -1
src/view/page/PhabricatorStandardPageView.php
··· 171 171 if ($user->hasSession()) { 172 172 $hisec = ($user->getSession()->getHighSecurityUntil() - time()); 173 173 if ($hisec > 0) { 174 - $remaining_time = phabricator_format_relative_time($hisec); 174 + $remaining_time = phutil_format_relative_time($hisec); 175 175 Javelin::initBehavior( 176 176 'high-security-warning', 177 177 array(
+2 -170
src/view/viewutils.php
··· 4 4 return phabricator_format_local_time( 5 5 $epoch, 6 6 $user, 7 - _phabricator_date_format($epoch)); 7 + _phutil_date_format($epoch)); 8 8 } 9 9 10 10 function phabricator_on_relative_date($epoch, $user) { ··· 46 46 $epoch, 47 47 $user, 48 48 pht('%s, %s', 49 - _phabricator_date_format($epoch), 49 + _phutil_date_format($epoch), 50 50 _phabricator_time_format($user))); 51 51 } 52 52 53 - function _phabricator_date_format($epoch) { 54 - $now = time(); 55 - $shift = 30 * 24 * 60 * 60; 56 - if ($epoch < $now + $shift && $epoch > $now - $shift) { 57 - $format = pht('D, M j'); 58 - } else { 59 - $format = pht('M j Y'); 60 - } 61 - return $format; 62 - } 63 - 64 53 function _phabricator_time_format($user) { 65 54 $prefs = $user->loadPreferences(); 66 55 ··· 119 108 return PhutilTranslator::getInstance()->translateDate($format, $date); 120 109 } 121 110 122 - function phabricator_format_relative_time($duration) { 123 - return phabricator_format_units_generic( 124 - $duration, 125 - array(60, 60, 24, 7), 126 - array('s', 'm', 'h', 'd', 'w'), 127 - $precision = 0); 128 - } 129 111 130 - /** 131 - * Format a relative time (duration) into weeks, days, hours, minutes, 132 - * seconds, but unlike phabricator_format_relative_time, does so for more than 133 - * just the largest unit. 134 - * 135 - * @param int Duration in seconds. 136 - * @param int Levels to render - will render the three highest levels, ie: 137 - * 5 h, 37 m, 1 s 138 - * @return string Human-readable description. 139 - */ 140 - function phabricator_format_relative_time_detailed($duration, $levels = 2) { 141 - if ($duration == 0) { 142 - return 'now'; 143 - } 144 - $levels = max(1, min($levels, 5)); 145 - $remainder = 0; 146 - 147 - $is_negative = false; 148 - if ($duration < 0) { 149 - $is_negative = true; 150 - $duration = abs($duration); 151 - } 152 - 153 - $this_level = 1; 154 - $detailed_relative_time = phabricator_format_units_generic( 155 - $duration, 156 - array(60, 60, 24, 7), 157 - array('s', 'm', 'h', 'd', 'w'), 158 - $precision = 0, 159 - $remainder); 160 - $duration = $remainder; 161 - 162 - while ($remainder > 0 && $this_level < $levels) { 163 - $detailed_relative_time .= ', '.phabricator_format_units_generic( 164 - $duration, 165 - array(60, 60, 24, 7), 166 - array('s', 'm', 'h', 'd', 'w'), 167 - $precision = 0, 168 - $remainder); 169 - $duration = $remainder; 170 - $this_level++; 171 - }; 172 - 173 - if ($is_negative) { 174 - $detailed_relative_time .= ' ago'; 175 - } 176 - 177 - return $detailed_relative_time; 178 - } 179 - 180 - /** 181 - * Format a byte count for human consumption, e.g. "10MB" instead of 182 - * "10000000". 183 - * 184 - * @param int Number of bytes. 185 - * @return string Human-readable description. 186 - */ 187 - function phabricator_format_bytes($bytes) { 188 - return phabricator_format_units_generic( 189 - $bytes, 190 - // NOTE: Using the SI version of these units rather than the 1024 version. 191 - array(1000, 1000, 1000, 1000, 1000), 192 - array('B', 'KB', 'MB', 'GB', 'TB', 'PB'), 193 - $precision = 0); 194 - } 195 - 196 - 197 - /** 198 - * Parse a human-readable byte description (like "6MB") into an integer. 199 - * 200 - * @param string Human-readable description. 201 - * @return int Number of represented bytes. 202 - */ 203 - function phabricator_parse_bytes($input) { 204 - $bytes = trim($input); 205 - if (!strlen($bytes)) { 206 - return null; 207 - } 208 - 209 - // NOTE: Assumes US-centric numeral notation. 210 - $bytes = preg_replace('/[ ,]/', '', $bytes); 211 - 212 - $matches = null; 213 - if (!preg_match('/^(?:\d+(?:[.]\d+)?)([kmgtp]?)b?$/i', $bytes, $matches)) { 214 - throw new Exception("Unable to parse byte size '{$input}'!"); 215 - } 216 - 217 - $scale = array( 218 - 'k' => 1000, 219 - 'm' => 1000 * 1000, 220 - 'g' => 1000 * 1000 * 1000, 221 - 't' => 1000 * 1000 * 1000 * 1000, 222 - 'p' => 1000 * 1000 * 1000 * 1000 * 1000, 223 - ); 224 - 225 - $bytes = (float)$bytes; 226 - if ($matches[1]) { 227 - $bytes *= $scale[strtolower($matches[1])]; 228 - } 229 - 230 - return (int)$bytes; 231 - } 232 - 233 - 234 - function phabricator_format_units_generic( 235 - $n, 236 - array $scales, 237 - array $labels, 238 - $precision = 0, 239 - &$remainder = null) { 240 - 241 - $is_negative = false; 242 - if ($n < 0) { 243 - $is_negative = true; 244 - $n = abs($n); 245 - } 246 - 247 - $remainder = 0; 248 - $accum = 1; 249 - 250 - $scale = array_shift($scales); 251 - $label = array_shift($labels); 252 - while ($n >= $scale && count($labels)) { 253 - $remainder += ($n % $scale) * $accum; 254 - $n /= $scale; 255 - $accum *= $scale; 256 - $label = array_shift($labels); 257 - if (!count($scales)) { 258 - break; 259 - } 260 - $scale = array_shift($scales); 261 - } 262 - 263 - if ($is_negative) { 264 - $n = -$n; 265 - $remainder = -$remainder; 266 - } 267 - 268 - if ($precision) { 269 - $num_string = number_format($n, $precision); 270 - } else { 271 - $num_string = (int)floor($n); 272 - } 273 - 274 - if ($label) { 275 - $num_string .= ' '.$label; 276 - } 277 - 278 - return $num_string; 279 - }