Skip to content
Permalink
Browse files

Remove Time::niceShort()

  • Loading branch information...
bcrowe committed Jan 7, 2014
1 parent 4fa33ef commit 998c68c6bf1955876c9c749880dc35e95d88d4d2
Showing with 0 additions and 98 deletions.
  1. +0 −65 Cake/Utility/Time.php
  2. +0 −33 Test/TestCase/Utility/TimeTest.php
@@ -47,15 +47,6 @@ class Time {
*/
public static $wordFormat = 'j/n/y';
/**
* The format to use when formatting a time using `Cake\Utility\Time::niceShort()`
* and the difference is between 3 and 7 days
*
* @var string
* @see Cake\Utility\Time::niceShort()
*/
public static $niceShortFormat = '%B %d, %H:%M';
/**
* The format to use when formatting a time using `Cake\Utility\Time::timeAgoInWords()`
* and the difference is less than `Cake\Utility\Time::$wordEnd`
@@ -332,62 +323,6 @@ public static function nice($dateString = null, $timezone = null, $format = null
return static::_strftime(static::convertSpecifiers($format, $date), $date);
}
/**
* Returns a formatted descriptive date string for given datetime string.
*
* If the given date is today, the returned string could be "Today, 16:54".
* If the given date is tomorrow, the returned string could be "Tomorrow, 16:54".
* If the given date was yesterday, the returned string could be "Yesterday, 16:54".
* If the given date is within next or last week, the returned string could be "On Thursday, 16:54".
* If $dateString's year is the current year, the returned string does not
* include mention of the year.
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone Timezone string or DateTimeZone object
* @return string Described, relative date string
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::niceShort
*/
public static function niceShort($dateString = null, $timezone = null) {
if (!$dateString) {
$dateTime = new \DateTime;
$dateString = $dateTime->getTimestamp();
}
$date = static::fromString($dateString, $timezone);
if (static::isToday($dateString, $timezone)) {
return __d('cake', 'Today, %s', static::_strftime("%H:%M", $date));
}
if (static::wasYesterday($dateString, $timezone)) {
return __d('cake', 'Yesterday, %s', static::_strftime("%H:%M", $date));
}
if (static::isTomorrow($dateString, $timezone)) {
return __d('cake', 'Tomorrow, %s', static::_strftime("%H:%M", $date));
}
$d = static::_strftime("%w", $date);
$day = array(
__d('cake', 'Sunday'),
__d('cake', 'Monday'),
__d('cake', 'Tuesday'),
__d('cake', 'Wednesday'),
__d('cake', 'Thursday'),
__d('cake', 'Friday'),
__d('cake', 'Saturday')
);
if (static::wasWithinLast('7 days', $dateString, $timezone)) {
return sprintf('%s %s', $day[$d], static::_strftime(static::$niceShortFormat, $date));
}
if (static::isWithinNext('7 days', $dateString, $timezone)) {
return __d('cake', 'On %s %s', $day[$d], static::_strftime(static::$niceShortFormat, $date));
}
$y = '';
if (!static::isThisYear($date)) {
$y = ' %Y';
}
return static::_strftime(static::convertSpecifiers("%b %eS{$y}, %H:%M", $date), $date);
}
/**
* Returns a partial SQL string to search for all records between two dates.
*
@@ -405,39 +405,6 @@ public function testNice() {
$this->_restoreSystemTimezone();
}
/**
* testNiceShort method
*
* @return void
*/
public function testNiceShort() {
$time = time();
$this->assertEquals('Today, ' . date('H:i', $time), $this->Time->niceShort($time));
$time = time() - DAY;
$this->assertEquals('Yesterday, ' . date('H:i', $time), $this->Time->niceShort($time));
$time = time() + DAY;
$this->assertEquals('Tomorrow, ' . date('H:i', $time), $this->Time->niceShort($time));
$time = strtotime('+6 days');
$this->assertEquals('On ' . date('l F d, H:i', $time), $this->Time->niceShort($time));
$time = strtotime('-6 days');
$this->assertEquals(date('l F d, H:i', $time), $this->Time->niceShort($time));
date_default_timezone_set('Europe/London');
$result = $this->Time->niceShort('2005-01-15 10:00:00', new \DateTimeZone('Europe/Brussels'));
$this->assertEquals('Jan 15th 2005, 11:00', $result);
date_default_timezone_set('UTC');
$result = $this->Time->niceShort(null, 'America/New_York');
$expected = $this->Time->niceShort(time(), 'America/New_York');
$this->assertEquals($expected, $result);
$this->_restoreSystemTimezone();
}
/**
* testDaysAsSql method
*

0 comments on commit 998c68c

Please sign in to comment.
You can’t perform that action at this time.