Relative date helper, for 'today' and 'yesterday'
Summary:
Format a date as 'today', 'yesterday', or 'Mar 27 2012'. Optionally,
the final example can be rendered 'on Mar 27 2012' for things like:
$excuse =
'I fell out of a window '.
phabricator_on_rel_date($time, $me);
Test Plan: Tested in my sandbox!!!!
Reviewers: epriestley
Reviewed By: epriestley
CC: aran, epriestley
Differential Revision: https://secure.phabricator.com/D2035
This commit is contained in:
@@ -59,16 +59,12 @@ final class PhabricatorFeedBuilder {
|
|||||||
require_celerity_resource('phabricator-feed-css');
|
require_celerity_resource('phabricator-feed-css');
|
||||||
|
|
||||||
$last_date = null;
|
$last_date = null;
|
||||||
$today = phabricator_date(time(), $user);
|
|
||||||
foreach ($stories as $story) {
|
foreach ($stories as $story) {
|
||||||
$story->setHandles($handles);
|
$story->setHandles($handles);
|
||||||
$story->setObjects($objects);
|
$story->setObjects($objects);
|
||||||
$story->setFramed($this->framed);
|
$story->setFramed($this->framed);
|
||||||
|
|
||||||
$date = phabricator_date($story->getEpoch(), $user);
|
$date = ucfirst(phabricator_relative_date($story->getEpoch(), $user));
|
||||||
if ($date == $today) {
|
|
||||||
$date = 'Today';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($date !== $last_date) {
|
if ($date !== $last_date) {
|
||||||
if ($last_date !== null) {
|
if ($last_date !== null) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Facebook, Inc.
|
* Copyright 2012 Facebook, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,6 +23,33 @@ function phabricator_date($epoch, $user) {
|
|||||||
'M j Y');
|
'M j Y');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function phabricator_on_relative_date($epoch, $user) {
|
||||||
|
return phabricator_relative_date($epoch, $user, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function phabricator_relative_date($epoch, $user, $on = false) {
|
||||||
|
static $today;
|
||||||
|
static $yesterday;
|
||||||
|
|
||||||
|
if (!$today || !$yesterday) {
|
||||||
|
$now = time();
|
||||||
|
$today = phabricator_date($now, $user);
|
||||||
|
$yesterday = phabricator_date($now - 86400, $user);
|
||||||
|
}
|
||||||
|
|
||||||
|
$date = phabricator_date($epoch, $user);
|
||||||
|
|
||||||
|
if ($date === $today) {
|
||||||
|
return 'today';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($date === $yesterday) {
|
||||||
|
return 'yesterday';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (($on ? 'on ' : '').$date);
|
||||||
|
}
|
||||||
|
|
||||||
function phabricator_time($epoch, $user) {
|
function phabricator_time($epoch, $user) {
|
||||||
return __phabricator_format_local_time(
|
return __phabricator_format_local_time(
|
||||||
$epoch,
|
$epoch,
|
||||||
|
|||||||
Reference in New Issue
Block a user