Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14065629
D9907.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
19 KB
Referenced Files
None
Subscribers
None
D9907.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2709,7 +2709,6 @@
),
'function' =>
array(
- '_phabricator_date_format' => 'view/viewutils.php',
'_phabricator_time_format' => 'view/viewutils.php',
'celerity_generate_unique_node_id' => 'infrastructure/celerity/api.php',
'celerity_get_resource_uri' => 'infrastructure/celerity/api.php',
@@ -2718,13 +2717,8 @@
'phabricator_date' => 'view/viewutils.php',
'phabricator_datetime' => 'view/viewutils.php',
'phabricator_form' => 'infrastructure/javelin/markup.php',
- 'phabricator_format_bytes' => 'view/viewutils.php',
'phabricator_format_local_time' => 'view/viewutils.php',
- 'phabricator_format_relative_time' => 'view/viewutils.php',
- 'phabricator_format_relative_time_detailed' => 'view/viewutils.php',
- 'phabricator_format_units_generic' => 'view/viewutils.php',
'phabricator_on_relative_date' => 'view/viewutils.php',
- 'phabricator_parse_bytes' => 'view/viewutils.php',
'phabricator_relative_date' => 'view/viewutils.php',
'phabricator_time' => 'view/viewutils.php',
'phid_get_subtype' => 'applications/phid/utils.php',
diff --git a/src/applications/conduit/method/ConduitAPI_conduit_connect_Method.php b/src/applications/conduit/method/ConduitAPI_conduit_connect_Method.php
--- a/src/applications/conduit/method/ConduitAPI_conduit_connect_Method.php
+++ b/src/applications/conduit/method/ConduitAPI_conduit_connect_Method.php
@@ -125,7 +125,7 @@
'timestamp must differ from the server time by no more than '.
'%s seconds. Your client or server clock may not be set '.
'correctly.',
- phabricator_format_relative_time($threshold),
+ phutil_format_relative_time($threshold),
$token,
date('r', $token),
$now,
diff --git a/src/applications/daemon/controller/PhabricatorDaemonLogViewController.php b/src/applications/daemon/controller/PhabricatorDaemonLogViewController.php
--- a/src/applications/daemon/controller/PhabricatorDaemonLogViewController.php
+++ b/src/applications/daemon/controller/PhabricatorDaemonLogViewController.php
@@ -109,14 +109,14 @@
$details = pht(
'This daemon is running normally and reported a status update '.
'recently (within %s).',
- phabricator_format_relative_time($unknown_time));
+ phutil_format_relative_time($unknown_time));
break;
case PhabricatorDaemonLog::STATUS_UNKNOWN:
$details = pht(
'This daemon has not reported a status update recently (within %s). '.
'It may have exited abruptly. After %s, it will be presumed dead.',
- phabricator_format_relative_time($unknown_time),
- phabricator_format_relative_time($dead_time));
+ phutil_format_relative_time($unknown_time),
+ phutil_format_relative_time($dead_time));
break;
case PhabricatorDaemonLog::STATUS_DEAD:
$details = pht(
@@ -124,7 +124,7 @@
'presumed dead. Usually, this indicates that the daemon was '.
'killed or otherwise exited abruptly with an error. You may '.
'need to restart it.',
- phabricator_format_relative_time($dead_time));
+ phutil_format_relative_time($dead_time));
break;
case PhabricatorDaemonLog::STATUS_WAIT:
$details = pht(
@@ -133,8 +133,8 @@
'doing work and is waiting a little while (%s) to resume '.
'processing. After encountering an error, daemons wait before '.
'resuming work to avoid overloading services.',
- phabricator_format_relative_time($unknown_time),
- phabricator_format_relative_time($wait_time));
+ phutil_format_relative_time($unknown_time),
+ phutil_format_relative_time($wait_time));
break;
case PhabricatorDaemonLog::STATUS_EXITED:
$details = pht(
@@ -152,7 +152,7 @@
pht('Seen'),
pht(
'%s ago (%s)',
- phabricator_format_relative_time(time() - $u_epoch),
+ phutil_format_relative_time(time() - $u_epoch),
phabricator_datetime($u_epoch, $viewer)));
$argv = $daemon->getArgv();
diff --git a/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php b/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php
--- a/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php
+++ b/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php
@@ -174,7 +174,7 @@
if ($task->getLeaseExpires() && $task->getLeaseOwner()) {
$expires = ($task->getLeaseExpires() - time());
- $expires = phabricator_format_relative_time_detailed($expires);
+ $expires = phutil_format_relative_time_detailed($expires);
} else {
$expires = phutil_tag('em', array(), pht('None'));
}
@@ -247,7 +247,7 @@
$duration = 60;
}
$cumulative += $duration;
- $next[$key] = phabricator_format_relative_time($cumulative);
+ $next[$key] = phutil_format_relative_time($cumulative);
}
if ($ii != $retry_count) {
$next[] = '...';
diff --git a/src/applications/files/controller/PhabricatorFileInfoController.php b/src/applications/files/controller/PhabricatorFileInfoController.php
--- a/src/applications/files/controller/PhabricatorFileInfoController.php
+++ b/src/applications/files/controller/PhabricatorFileInfoController.php
@@ -179,7 +179,7 @@
$finfo->addProperty(
pht('Size'),
- phabricator_format_bytes($file->getByteSize()));
+ phutil_format_bytes($file->getByteSize()));
$finfo->addProperty(
pht('Mime Type'),
diff --git a/src/applications/files/controller/PhabricatorFileUploadController.php b/src/applications/files/controller/PhabricatorFileUploadController.php
--- a/src/applications/files/controller/PhabricatorFileUploadController.php
+++ b/src/applications/files/controller/PhabricatorFileUploadController.php
@@ -86,9 +86,9 @@
private function renderUploadLimit() {
$limit = PhabricatorEnv::getEnvConfig('storage.upload-size-limit');
- $limit = phabricator_parse_bytes($limit);
+ $limit = phutil_parse_bytes($limit);
if ($limit) {
- $formatted = phabricator_format_bytes($limit);
+ $formatted = phutil_format_bytes($limit);
return 'Maximum file size: '.$formatted;
}
diff --git a/src/applications/files/query/PhabricatorFileSearchEngine.php b/src/applications/files/query/PhabricatorFileSearchEngine.php
--- a/src/applications/files/query/PhabricatorFileSearchEngine.php
+++ b/src/applications/files/query/PhabricatorFileSearchEngine.php
@@ -166,7 +166,7 @@
->setHeader($name)
->setHref($file_uri)
->addAttribute($uploaded)
- ->addIcon('none', phabricator_format_bytes($file->getByteSize()));
+ ->addIcon('none', phutil_format_bytes($file->getByteSize()));
$ttl = $file->getTTL();
if ($ttl !== null) {
diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php
--- a/src/applications/files/storage/PhabricatorFile.php
+++ b/src/applications/files/storage/PhabricatorFile.php
@@ -108,7 +108,7 @@
return;
}
- $limit = phabricator_parse_bytes($limit);
+ $limit = phutil_parse_bytes($limit);
if ($size > $limit) {
throw new PhabricatorFileUploadException(-1000);
}
diff --git a/src/applications/notification/controller/PhabricatorNotificationStatusController.php b/src/applications/notification/controller/PhabricatorNotificationStatusController.php
--- a/src/applications/notification/controller/PhabricatorNotificationStatusController.php
+++ b/src/applications/notification/controller/PhabricatorNotificationStatusController.php
@@ -41,7 +41,7 @@
switch ($key) {
case 'uptime':
$value /= 1000;
- $value = phabricator_format_relative_time_detailed($value);
+ $value = phutil_format_relative_time_detailed($value);
break;
case 'log':
break;
diff --git a/src/applications/people/customfield/PhabricatorUserSinceField.php b/src/applications/people/customfield/PhabricatorUserSinceField.php
--- a/src/applications/people/customfield/PhabricatorUserSinceField.php
+++ b/src/applications/people/customfield/PhabricatorUserSinceField.php
@@ -26,7 +26,7 @@
$this->getObject()->getDateCreated(),
$this->getViewer());
- $relative = phabricator_format_relative_time_detailed(
+ $relative = phutil_format_relative_time_detailed(
time() - $this->getObject()->getDateCreated(),
$levels = 2);
diff --git a/src/applications/phrequent/event/PhrequentUIEventListener.php b/src/applications/phrequent/event/PhrequentUIEventListener.php
--- a/src/applications/phrequent/event/PhrequentUIEventListener.php
+++ b/src/applications/phrequent/event/PhrequentUIEventListener.php
@@ -138,7 +138,7 @@
$block = new PhrequentTimeBlock($event_group);
$item->setNote(
- phabricator_format_relative_time(
+ phutil_format_relative_time(
$block->getTimeSpentOnObject(
$object->getPHID(),
time())));
diff --git a/src/applications/phrequent/query/PhrequentSearchEngine.php b/src/applications/phrequent/query/PhrequentSearchEngine.php
--- a/src/applications/phrequent/query/PhrequentSearchEngine.php
+++ b/src/applications/phrequent/query/PhrequentSearchEngine.php
@@ -166,7 +166,7 @@
}
$time_spent = $time_spent == 0 ? 'none' :
- phabricator_format_relative_time_detailed($time_spent);
+ phutil_format_relative_time_detailed($time_spent);
if ($usertime->getDateEnded() !== null) {
$item->addAttribute(
diff --git a/src/applications/releeph/controller/request/ReleephRequestEditController.php b/src/applications/releeph/controller/request/ReleephRequestEditController.php
--- a/src/applications/releeph/controller/request/ReleephRequestEditController.php
+++ b/src/applications/releeph/controller/request/ReleephRequestEditController.php
@@ -195,7 +195,7 @@
$age_string = '';
if ($is_edit) {
- $age_string = phabricator_format_relative_time(
+ $age_string = phutil_format_relative_time(
time() - $pull->getDateCreated()).' ago';
}
diff --git a/src/applications/releeph/controller/request/ReleephRequestTypeaheadController.php b/src/applications/releeph/controller/request/ReleephRequestTypeaheadController.php
--- a/src/applications/releeph/controller/request/ReleephRequestTypeaheadController.php
+++ b/src/applications/releeph/controller/request/ReleephRequestTypeaheadController.php
@@ -56,7 +56,7 @@
$full_commit_id,
$short_commit_id,
$row['authorName'],
- phabricator_format_relative_time($now - $row['epoch']),
+ phutil_format_relative_time($now - $row['epoch']),
$first_line,
);
}
diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
--- a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
+++ b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php
@@ -469,8 +469,8 @@
$size = strlen($raw_diff);
if ($byte_limit && $size > $byte_limit) {
- $pretty_size = phabricator_format_bytes($size);
- $pretty_limit = phabricator_format_bytes($byte_limit);
+ $pretty_size = phutil_format_bytes($size);
+ $pretty_limit = phutil_format_bytes($byte_limit);
throw new Exception(
"Patch size of {$pretty_size} exceeds configured byte size limit of ".
"{$pretty_limit}.");
diff --git a/src/applications/settings/panel/PhabricatorSettingsPanelSessions.php b/src/applications/settings/panel/PhabricatorSettingsPanelSessions.php
--- a/src/applications/settings/panel/PhabricatorSettingsPanelSessions.php
+++ b/src/applications/settings/panel/PhabricatorSettingsPanelSessions.php
@@ -78,7 +78,7 @@
substr($session->getSessionKey(), 0, 6),
$session->getType(),
($hisec > 0)
- ? phabricator_format_relative_time($hisec)
+ ? phutil_format_relative_time($hisec)
: null,
phabricator_datetime($session->getSessionStart(), $viewer),
phabricator_date($session->getSessionExpires(), $viewer),
diff --git a/src/view/__tests__/PhabricatorUnitsTestCase.php b/src/view/__tests__/PhabricatorUnitsTestCase.php
--- a/src/view/__tests__/PhabricatorUnitsTestCase.php
+++ b/src/view/__tests__/PhabricatorUnitsTestCase.php
@@ -19,8 +19,8 @@
foreach ($tests as $input => $expect) {
$this->assertEqual(
$expect,
- phabricator_format_bytes($input),
- 'phabricator_format_bytes('.$input.')');
+ phutil_format_bytes($input),
+ 'phutil_format_bytes('.$input.')');
}
}
@@ -42,14 +42,14 @@
foreach ($tests as $input => $expect) {
$this->assertEqual(
$expect,
- phabricator_parse_bytes($input),
- 'phabricator_parse_bytes('.$input.')');
+ phutil_parse_bytes($input),
+ 'phutil_parse_bytes('.$input.')');
}
$this->tryTestCases(
array('string' => 'string'),
array(false),
- 'phabricator_parse_bytes');
+ 'phutil_parse_bytes');
}
public function testDetailedDurationFormatting() {
@@ -68,8 +68,8 @@
foreach ($tests as $duration => $expect) {
$this->assertEqual(
$expect,
- phabricator_format_relative_time_detailed($duration),
- 'phabricator_format_relative_time_detailed('.$duration.')');
+ phutil_format_relative_time_detailed($duration),
+ 'phutil_format_relative_time_detailed('.$duration.')');
}
@@ -113,16 +113,16 @@
foreach ($sub_tests as $levels => $expect) {
$this->assertEqual(
$expect,
- phabricator_format_relative_time_detailed($duration, $levels),
- 'phabricator_format_relative_time_detailed('.$duration.',
+ phutil_format_relative_time_detailed($duration, $levels),
+ 'phutil_format_relative_time_detailed('.$duration.',
'.$levels.')');
}
} else {
$expect = $sub_tests;
$this->assertEqual(
$expect,
- phabricator_format_relative_time_detailed($duration),
- 'phabricator_format_relative_time_detailed('.$duration.')');
+ phutil_format_relative_time_detailed($duration),
+ 'phutil_format_relative_time_detailed('.$duration.')');
}
}
diff --git a/src/view/page/PhabricatorStandardPageView.php b/src/view/page/PhabricatorStandardPageView.php
--- a/src/view/page/PhabricatorStandardPageView.php
+++ b/src/view/page/PhabricatorStandardPageView.php
@@ -171,7 +171,7 @@
if ($user->hasSession()) {
$hisec = ($user->getSession()->getHighSecurityUntil() - time());
if ($hisec > 0) {
- $remaining_time = phabricator_format_relative_time($hisec);
+ $remaining_time = phutil_format_relative_time($hisec);
Javelin::initBehavior(
'high-security-warning',
array(
diff --git a/src/view/viewutils.php b/src/view/viewutils.php
--- a/src/view/viewutils.php
+++ b/src/view/viewutils.php
@@ -4,7 +4,7 @@
return phabricator_format_local_time(
$epoch,
$user,
- _phabricator_date_format($epoch));
+ _phutil_date_format($epoch));
}
function phabricator_on_relative_date($epoch, $user) {
@@ -46,21 +46,10 @@
$epoch,
$user,
pht('%s, %s',
- _phabricator_date_format($epoch),
+ _phutil_date_format($epoch),
_phabricator_time_format($user)));
}
-function _phabricator_date_format($epoch) {
- $now = time();
- $shift = 30 * 24 * 60 * 60;
- if ($epoch < $now + $shift && $epoch > $now - $shift) {
- $format = pht('D, M j');
- } else {
- $format = pht('M j Y');
- }
- return $format;
-}
-
function _phabricator_time_format($user) {
$prefs = $user->loadPreferences();
@@ -119,161 +108,4 @@
return PhutilTranslator::getInstance()->translateDate($format, $date);
}
-function phabricator_format_relative_time($duration) {
- return phabricator_format_units_generic(
- $duration,
- array(60, 60, 24, 7),
- array('s', 'm', 'h', 'd', 'w'),
- $precision = 0);
-}
-
-/**
- * Format a relative time (duration) into weeks, days, hours, minutes,
- * seconds, but unlike phabricator_format_relative_time, does so for more than
- * just the largest unit.
- *
- * @param int Duration in seconds.
- * @param int Levels to render - will render the three highest levels, ie:
- * 5 h, 37 m, 1 s
- * @return string Human-readable description.
- */
-function phabricator_format_relative_time_detailed($duration, $levels = 2) {
- if ($duration == 0) {
- return 'now';
- }
- $levels = max(1, min($levels, 5));
- $remainder = 0;
-
- $is_negative = false;
- if ($duration < 0) {
- $is_negative = true;
- $duration = abs($duration);
- }
-
- $this_level = 1;
- $detailed_relative_time = phabricator_format_units_generic(
- $duration,
- array(60, 60, 24, 7),
- array('s', 'm', 'h', 'd', 'w'),
- $precision = 0,
- $remainder);
- $duration = $remainder;
-
- while ($remainder > 0 && $this_level < $levels) {
- $detailed_relative_time .= ', '.phabricator_format_units_generic(
- $duration,
- array(60, 60, 24, 7),
- array('s', 'm', 'h', 'd', 'w'),
- $precision = 0,
- $remainder);
- $duration = $remainder;
- $this_level++;
- };
-
- if ($is_negative) {
- $detailed_relative_time .= ' ago';
- }
-
- return $detailed_relative_time;
-}
-
-/**
- * Format a byte count for human consumption, e.g. "10MB" instead of
- * "10000000".
- *
- * @param int Number of bytes.
- * @return string Human-readable description.
- */
-function phabricator_format_bytes($bytes) {
- return phabricator_format_units_generic(
- $bytes,
- // NOTE: Using the SI version of these units rather than the 1024 version.
- array(1000, 1000, 1000, 1000, 1000),
- array('B', 'KB', 'MB', 'GB', 'TB', 'PB'),
- $precision = 0);
-}
-
-
-/**
- * Parse a human-readable byte description (like "6MB") into an integer.
- *
- * @param string Human-readable description.
- * @return int Number of represented bytes.
- */
-function phabricator_parse_bytes($input) {
- $bytes = trim($input);
- if (!strlen($bytes)) {
- return null;
- }
-
- // NOTE: Assumes US-centric numeral notation.
- $bytes = preg_replace('/[ ,]/', '', $bytes);
-
- $matches = null;
- if (!preg_match('/^(?:\d+(?:[.]\d+)?)([kmgtp]?)b?$/i', $bytes, $matches)) {
- throw new Exception("Unable to parse byte size '{$input}'!");
- }
-
- $scale = array(
- 'k' => 1000,
- 'm' => 1000 * 1000,
- 'g' => 1000 * 1000 * 1000,
- 't' => 1000 * 1000 * 1000 * 1000,
- 'p' => 1000 * 1000 * 1000 * 1000 * 1000,
- );
-
- $bytes = (float)$bytes;
- if ($matches[1]) {
- $bytes *= $scale[strtolower($matches[1])];
- }
-
- return (int)$bytes;
-}
-
-
-function phabricator_format_units_generic(
- $n,
- array $scales,
- array $labels,
- $precision = 0,
- &$remainder = null) {
- $is_negative = false;
- if ($n < 0) {
- $is_negative = true;
- $n = abs($n);
- }
-
- $remainder = 0;
- $accum = 1;
-
- $scale = array_shift($scales);
- $label = array_shift($labels);
- while ($n >= $scale && count($labels)) {
- $remainder += ($n % $scale) * $accum;
- $n /= $scale;
- $accum *= $scale;
- $label = array_shift($labels);
- if (!count($scales)) {
- break;
- }
- $scale = array_shift($scales);
- }
-
- if ($is_negative) {
- $n = -$n;
- $remainder = -$remainder;
- }
-
- if ($precision) {
- $num_string = number_format($n, $precision);
- } else {
- $num_string = (int)floor($n);
- }
-
- if ($label) {
- $num_string .= ' '.$label;
- }
-
- return $num_string;
-}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 20, 5:39 AM (8 h, 51 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6726245
Default Alt Text
D9907.diff (19 KB)
Attached To
Mode
D9907: Remove user-independent date and time functions from Phabricator
Attached
Detach File
Event Timeline
Log In to Comment