浏览代码

Merge pull request #3369 from cakephp/3.0-cake-time

3.0 cake time
Christian Winther 12 年之前
父节点
当前提交
05b1bd6668

+ 2 - 1
composer.json

@@ -19,9 +19,10 @@
     },
     "require": {
         "php": ">=5.4.19",
+        "ext-intl": "*",
         "ext-mcrypt": "*",
         "ext-mbstring": "*",
-        "nesbot/Carbon": "1.*"
+        "nesbot/Carbon": "1.8.*"
     },
     "require-dev": {
         "phpunit/phpunit": "3.7.33"

+ 1 - 1
src/Database/Type/DateTimeType.php

@@ -28,7 +28,7 @@ class DateTimeType extends \Cake\Database\Type {
  *
  * @var string
  */
-	public static $dateTimeClass = 'Carbon\Carbon';
+	public static $dateTimeClass = 'Cake\Utility\Time';
 
 /**
  * String format to use for DateTime parsing

文件差异内容过多而无法显示
+ 216 - 608
src/Utility/Time.php


+ 52 - 165
src/View/Helper/TimeHelper.php

@@ -14,13 +14,9 @@
  */
 namespace Cake\View\Helper;
 
-use Cake\Core\App;
-use Cake\Core\Configure;
-use Cake\Error;
-use Cake\Utility\Hash;
+use Cake\Utility\Time;
 use Cake\View\Helper;
 use Cake\View\Helper\StringTemplateTrait;
-use Cake\View\View;
 
 /**
  * Time Helper class for easy use of time data.
@@ -35,209 +31,105 @@ class TimeHelper extends Helper {
 	use StringTemplateTrait;
 
 /**
- * Default config for this class
- *
- * @var array
- */
-	protected $_defaultConfig = [
-		'engine' => 'Cake\Utility\Time'
-	];
-
-/**
- * Cake\Utility\Time instance
- *
- * @var \Cake\Utility\Time
- */
-	protected $_engine = null;
-
-/**
- * Constructor
- *
- * ### Settings:
- *
- * - `engine` Class name to use to replace Cake\Utility\Time functionality
- *            The class needs to be placed in the `Utility` directory.
- *
- * @param View $View the view object the helper is attached to.
- * @param array $config Settings array
- * @throws \Cake\Error\Exception When the engine class could not be found.
- */
-	public function __construct(View $View, array $config = array()) {
-		parent::__construct($View, $config);
-
-		$config = $this->_config;
-
-		$engineClass = App::classname($config['engine'], 'Utility');
-		if ($engineClass) {
-			$this->_engine = new $engineClass($config);
-		} else {
-			throw new Error\Exception(sprintf('Class for %s could not be found', $config['engine']));
-		}
-	}
-
-/**
- * Call methods from Cake\Utility\Time utility class
- *
- * @param string $method Method to invoke
- * @param array $params Array of params for the method.
- * @return mixed Whatever is returned by called method, or false on failure
- */
-	public function __call($method, $params) {
-		return call_user_func_array(array($this->_engine, $method), $params);
-	}
-
-/**
- * Converts a string representing the format for the function strftime and returns a
- * windows safe and i18n aware format.
- *
- * @see \Cake\Utility\Time::convertSpecifiers()
- *
- * @param string $format Format with specifiers for strftime function.
- *    Accepts the special specifier %S which mimics the modifier S for date()
- * @param string $time UNIX timestamp
- * @return string windows safe and date() function compatible format for strftime
- * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
- */
-	public function convertSpecifiers($format, $time = null) {
-		return $this->_engine->convertSpecifiers($format, $time);
-	}
-
-/**
- * Converts given time (in server's time zone) to user's local time, given his/her timezone.
- *
- * @see \Cake\Utility\Time::convert()
- *
- * @param string $serverTime UNIX timestamp
- * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
- * @return int UNIX timestamp
- * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
- */
-	public function convert($serverTime, $timezone) {
-		return $this->_engine->convert($serverTime, $timezone);
-	}
-
-/**
  * Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
  *
- * @see \Cake\Utility\Time::fromString()
- *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
- * @return string Parsed timestamp
+ * @return Cake\Utility\Time
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 	public function fromString($dateString, $timezone = null) {
-		return $this->_engine->fromString($dateString, $timezone);
+		return (new Time($dateString))->timezone($timezone);
 	}
 
 /**
  * Returns a nicely formatted date string for given Datetime string.
  *
- * @see \Cake\Utility\Time::nice()
- *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
  * @param string $format The format to use. If null, `CakeTime::$niceFormat` is used
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function nice($dateString = null, $timezone = null, $format = null) {
-		return $this->_engine->nice($dateString, $timezone, $format);
+	public function nice($dateString = null, $timezone = null, $locale = null) {
+		return (new Time($dateString))->nice($timezone, $locale);
 	}
 
 /**
- * Returns a partial SQL string to search for all records between two dates.
- *
- * @see \Cake\Utility\Time::daysAsSql()
+ * Returns true if given datetime string is today.
  *
- * @param int|string|\DateTime $begin UNIX timestamp, strtotime() valid string or DateTime object
- * @param int|string|\DateTime $end UNIX timestamp, strtotime() valid string or DateTime object
- * @param string $fieldName Name of database field to compare with
+ * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
- * @return string Partial SQL string.
- * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
+ * @return bool True if datetime string is today
+ * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public function daysAsSql($begin, $end, $fieldName, $timezone = null) {
-		return $this->_engine->daysAsSql($begin, $end, $fieldName, $timezone);
+	public function isToday($dateString, $timezone = null) {
+		return (new Time($dateString, $timezone))->isToday();
 	}
 
 /**
- * Returns a partial SQL string to search for all records between two times
- * occurring on the same day.
- *
- * @see \Cake\Utility\Time::dayAsSql()
+ * Returns true if given datetime string is in the future.
  *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
- * @param string $fieldName Name of database field to compare with
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
- * @return string Partial SQL string.
- * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
+ * @return bool True if datetime string is today
+ * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public function dayAsSql($dateString, $fieldName, $timezone = null) {
-		return $this->_engine->dayAsSql($dateString, $fieldName, $timezone);
+	public function isFuture($dateString, $timezone = null) {
+		return (new Time($dateString, $timezone))->isFuture();
 	}
 
 /**
- * Returns true if given datetime string is today.
- *
- * @see \Cake\Utility\Time::isToday()
+ * Returns true if given datetime string is in the past.
  *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
  * @return bool True if datetime string is today
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
-	public function isToday($dateString, $timezone = null) {
-		return $this->_engine->isToday($dateString, $timezone);
+	public function isPast($dateString, $timezone = null) {
+		return (new Time($dateString, $timezone))->isPast();
 	}
 
 /**
  * Returns true if given datetime string is within this week.
  *
- * @see \Cake\Utility\Time::isThisWeek()
- *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
  * @return bool True if datetime string is within current week
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
 	public function isThisWeek($dateString, $timezone = null) {
-		return $this->_engine->isThisWeek($dateString, $timezone);
+		return (new Time($dateString, $timezone))->isThisWeek();
 	}
 
 /**
  * Returns true if given datetime string is within this month
  *
- * @see \Cake\Utility\Time::isThisMonth()
- *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
  * @return bool True if datetime string is within current month
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
 	public function isThisMonth($dateString, $timezone = null) {
-		return $this->_engine->isThisMonth($dateString, $timezone);
+		return (new Time($dateString, $timezone))->isThisMonth();
 	}
 
 /**
  * Returns true if given datetime string is within current year.
  *
- * @see \Cake\Utility\Time::isThisYear()
- *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
  * @return bool True if datetime string is within current year
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
 	public function isThisYear($dateString, $timezone = null) {
-		return $this->_engine->isThisYear($dateString, $timezone);
+		return (new Time($dateString, $timezone))->isThisYear();
 	}
 
 /**
  * Returns true if given datetime string was yesterday.
  *
- * @see \Cake\Utility\Time::wasYesterday()
- *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
  * @return bool True if datetime string was yesterday
@@ -245,21 +137,19 @@ class TimeHelper extends Helper {
  *
  */
 	public function wasYesterday($dateString, $timezone = null) {
-		return $this->_engine->wasYesterday($dateString, $timezone);
+		return (new Time($dateString, $timezone))->isYesterday();
 	}
 
 /**
  * Returns true if given datetime string is tomorrow.
  *
- * @see \Cake\Utility\Time::isTomorrow()
- *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
  * @return bool True if datetime string was yesterday
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
 	public function isTomorrow($dateString, $timezone = null) {
-		return $this->_engine->isTomorrow($dateString, $timezone);
+		return (new Time($dateString, $timezone))->isTomorrow();
 	}
 
 /**
@@ -273,7 +163,7 @@ class TimeHelper extends Helper {
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 	public function toQuarter($dateString, $range = false) {
-		return $this->_engine->toQuarter($dateString, $range);
+		return (new Time($dateString))->toQuarter($range);
 	}
 
 /**
@@ -287,7 +177,7 @@ class TimeHelper extends Helper {
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 	public function toUnix($dateString, $timezone = null) {
-		return $this->_engine->toUnix($dateString, $timezone);
+		return (new Time($dateString, $timezone))->toUnixString();
 	}
 
 /**
@@ -301,21 +191,21 @@ class TimeHelper extends Helper {
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 	public function toAtom($dateString, $timezone = null) {
-		return $this->_engine->toAtom($dateString, $timezone);
+		$timezone = $timezone ?: date_default_timezone_get();
+		return (new Time($dateString))->timezone($timezone)->toATOMString();
 	}
 
 /**
  * Formats date for RSS feeds
  *
- * @see \Cake\Utility\Time::toRSS()
- *
  * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
  * @return string Formatted date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 	public function toRSS($dateString, $timezone = null) {
-		return $this->_engine->toRSS($dateString, $timezone);
+		$timezone = $timezone ?: date_default_timezone_get();
+		return (new Time($dateString))->timezone($timezone)->toRSSString();
 	}
 
 /**
@@ -353,7 +243,7 @@ class TimeHelper extends Helper {
 			}
 			unset($options['element']);
 		}
-		$relativeDate = $this->_engine->timeAgoInWords($dateTime, $options);
+		$relativeDate = (new Time($dateTime))->timeAgoInWords($options);
 
 		if ($element) {
 			$relativeDate = sprintf(
@@ -369,7 +259,6 @@ class TimeHelper extends Helper {
 
 /**
  * Returns true if specified datetime was within the interval specified, else false.
- *
  * @see \Cake\Utility\Time::wasWithinLast()
  *
  * @param string|int $timeInterval the numeric value with space then time type.
@@ -380,7 +269,7 @@ class TimeHelper extends Helper {
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
 	public function wasWithinLast($timeInterval, $dateString, $timezone = null) {
-		return $this->_engine->wasWithinLast($timeInterval, $dateString, $timezone);
+		return (new Time($dateString, $timezone))->wasWithinLast($timeInterval);
 	}
 
 /**
@@ -396,7 +285,7 @@ class TimeHelper extends Helper {
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
  */
 	public function isWithinNext($timeInterval, $dateString, $timezone = null) {
-		return $this->_engine->isWithinNext($timeInterval, $dateString, $timezone);
+		return (new Time($dateString, $timezone))->isWithinNext($timeInterval);
 	}
 
 /**
@@ -409,36 +298,25 @@ class TimeHelper extends Helper {
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 	public function gmt($string = null) {
-		return $this->_engine->gmt($string);
+		return (new Time($string))->toUnixString();
 	}
 
 /**
  * Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
  * This function also accepts a time string and a format string as first and second parameters.
- * In that case this function behaves as a wrapper for TimeHelper::i18nFormat()
+ * In that case this function behaves as a wrapper for Time::i18nFormat()
  *
- * ## Examples
- *
- * Create localized & formatted time:
- *
- * {{{
- *   $this->Time->format('2012-02-15', '%m-%d-%Y'); // returns 02-15-2012
- *   $this->Time->format('2012-02-15 23:01:01', '%c'); // returns preferred date and time based on configured locale
- *   $this->Time->format('0000-00-00', '%d-%m-%Y', 'N/A'); // return N/A becuase an invalid date was passed
- *   $this->Time->format('2012-02-15 23:01:01', '%c', 'N/A', 'America/New_York'); // converts passed date to timezone
- * }}}
- *
- * @see \Cake\Utility\Time::format()
+ * @see \Cake\Utility\Time::i18nFormat()
  *
- * @param int|string|\DateTime $format date format string (or a UNIX timestamp, strtotime() valid string or DateTime object)
  * @param int|string|\DateTime $date UNIX timestamp, strtotime() valid string or DateTime object (or a date format string)
- * @param bool $invalid flag to ignore results of fromString == false
+ * @param int|string $format date format string (or a UNIX timestamp, strtotime() valid string or DateTime object)
+ * @param bool|string $invalid Default value to display on invalid dates
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
- * @return string Formatted date string
+ * @return string Formatted and translated date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
-	public function format($format, $date = null, $invalid = false, $timezone = null) {
-		return $this->_engine->format($format, $date, $invalid, $timezone);
+	public function format($date, $format = null, $invalid = false, $timezone = null) {
+		return $this->i18nFormat($date, $format, $invalid, $timezone);
 	}
 
 /**
@@ -449,13 +327,22 @@ class TimeHelper extends Helper {
  *
  * @param int|string|\DateTime $date UNIX timestamp, strtotime() valid string or DateTime object
  * @param string $format strftime format string.
- * @param bool $invalid flag to ignore results of fromString == false
+ * @param bool|string $invalid Default value to display on invalid dates
  * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object
  * @return string Formatted and translated date string
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
+ * @throws \InvalidArgumentException When the date cannot be parsed
  */
 	public function i18nFormat($date, $format = null, $invalid = false, $timezone = null) {
-		return $this->_engine->i18nFormat($date, $format, $invalid, $timezone);
+		try {
+			$time = new Time($date, $timezone);
+			return $time->i18nFormat($format, $timezone);
+		} catch (\Exception $e) {
+			if ($invalid === false) {
+				throw $e;
+			}
+			return $invalid;
+		}
 	}
 
 /**

+ 5 - 5
tests/TestCase/Controller/Component/Auth/BasicAuthenticateTest.php

@@ -23,7 +23,7 @@ use Cake\ORM\Entity;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
 use Cake\Utility\Security;
-use Carbon\Carbon;
+use Cake\Utility\Time;
 
 /**
  * Test case for BasicAuthentication
@@ -173,8 +173,8 @@ class BasicAuthenticateTest extends TestCase {
 		$expected = array(
 			'id' => 1,
 			'username' => 'mariano',
-			'created' => new Carbon('2007-03-17 01:16:23'),
-			'updated' => new Carbon('2007-03-17 01:18:31')
+			'created' => new Time('2007-03-17 01:16:23'),
+			'updated' => new Time('2007-03-17 01:18:31')
 		);
 		$this->assertEquals($expected, $result);
 	}
@@ -230,8 +230,8 @@ class BasicAuthenticateTest extends TestCase {
 		$expected = array(
 			'id' => 1,
 			'username' => 'mariano',
-			'created' => new Carbon('2007-03-17 01:16:23'),
-			'updated' => new Carbon('2007-03-17 01:18:31')
+			'created' => new Time('2007-03-17 01:16:23'),
+			'updated' => new Time('2007-03-17 01:18:31')
 		);
 		$this->assertEquals($expected, $result);
 	}

+ 3 - 3
tests/TestCase/Controller/Component/Auth/DigestAuthenticateTest.php

@@ -22,7 +22,7 @@ use Cake\Network\Request;
 use Cake\ORM\Entity;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
-use Carbon\Carbon;
+use Cake\Utility\Time;
 
 /**
  * Test case for DigestAuthentication
@@ -169,8 +169,8 @@ DIGEST;
 		$expected = array(
 			'id' => 1,
 			'username' => 'mariano',
-			'created' => new Carbon('2007-03-17 01:16:23'),
-			'updated' => new Carbon('2007-03-17 01:18:31')
+			'created' => new Time('2007-03-17 01:16:23'),
+			'updated' => new Time('2007-03-17 01:18:31')
 		);
 		$this->assertEquals($expected, $result);
 	}

+ 7 - 7
tests/TestCase/Controller/Component/Auth/FormAuthenticateTest.php

@@ -26,7 +26,7 @@ use Cake\ORM\Entity;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
 use Cake\Utility\Security;
-use Carbon\Carbon;
+use Cake\Utility\Time;
 
 /**
  * Test case for FormAuthentication
@@ -200,8 +200,8 @@ class FormAuthenticateTest extends TestCase {
 		$expected = [
 			'id' => 1,
 			'username' => 'mariano',
-			'created' => new Carbon('2007-03-17 01:16:23'),
-			'updated' => new Carbon('2007-03-17 01:18:31')
+			'created' => new Time('2007-03-17 01:16:23'),
+			'updated' => new Time('2007-03-17 01:18:31')
 		];
 		$this->assertEquals($expected, $result);
 	}
@@ -249,8 +249,8 @@ class FormAuthenticateTest extends TestCase {
 		$expected = [
 			'id' => 1,
 			'username' => 'gwoo',
-			'created' => new Carbon('2007-03-17 01:16:23'),
-			'updated' => new Carbon('2007-03-17 01:18:31')
+			'created' => new Time('2007-03-17 01:16:23'),
+			'updated' => new Time('2007-03-17 01:18:31')
 		];
 		$this->assertEquals($expected, $result);
 		Plugin::unload();
@@ -288,8 +288,8 @@ class FormAuthenticateTest extends TestCase {
 		$expected = [
 			'id' => 1,
 			'username' => 'mariano',
-			'created' => new Carbon('2007-03-17 01:16:23'),
-			'updated' => new Carbon('2007-03-17 01:18:31')
+			'created' => new Time('2007-03-17 01:16:23'),
+			'updated' => new Time('2007-03-17 01:18:31')
 		];
 		$this->assertEquals($expected, $result);
 

+ 15 - 15
tests/TestCase/Database/Type/DateTimeTypeTest.php

@@ -17,7 +17,7 @@ namespace Cake\Test\TestCase\Database\Type;
 use Cake\Database\Type;
 use Cake\Database\Type\DateTimeType;
 use Cake\TestSuite\TestCase;
-use Carbon\Carbon;
+use Cake\Utility\Time;
 
 /**
  * Test for the DateTime type.
@@ -44,7 +44,7 @@ class DateTimeTypeTest extends TestCase {
 		$this->assertNull($this->type->toPHP(null, $this->driver));
 
 		$result = $this->type->toPHP('2001-01-04 12:13:14', $this->driver);
-		$this->assertInstanceOf('Carbon\Carbon', $result);
+		$this->assertInstanceOf('Cake\Utility\Time', $result);
 		$this->assertEquals('2001', $result->format('Y'));
 		$this->assertEquals('01', $result->format('m'));
 		$this->assertEquals('04', $result->format('d'));
@@ -64,7 +64,7 @@ class DateTimeTypeTest extends TestCase {
 	public function testToPHPIncludingMilliseconds() {
 		$in = '2014-03-24 20:44:36.315113';
 		$result = $this->type->toPHP($in, $this->driver);
-		$this->assertInstanceOf('Carbon\Carbon', $result);
+		$this->assertInstanceOf('Cake\Utility\Time', $result);
 	}
 
 /**
@@ -77,7 +77,7 @@ class DateTimeTypeTest extends TestCase {
 		$result = $this->type->toDatabase($value, $this->driver);
 		$this->assertEquals($value, $result);
 
-		$date = new Carbon('2013-08-12 15:16:17');
+		$date = new Time('2013-08-12 15:16:17');
 		$result = $this->type->toDatabase($date, $this->driver);
 		$this->assertEquals('2013-08-12 15:16:17', $result);
 	}
@@ -98,15 +98,15 @@ class DateTimeTypeTest extends TestCase {
 			['2013-nope!', '2013-nope!'],
 
 			// valid string types
-			['1392387900', new Carbon('@1392387900')],
-			[1392387900, new Carbon('@1392387900')],
-			['2014-02-14', new Carbon('2014-02-14')],
-			['2014-02-14 13:14:15', new Carbon('2014-02-14 13:14:15')],
+			['1392387900', new Time('@1392387900')],
+			[1392387900, new Time('@1392387900')],
+			['2014-02-14', new Time('2014-02-14')],
+			['2014-02-14 13:14:15', new Time('2014-02-14 13:14:15')],
 
 			// valid array types
 			[
 				['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15],
-				new Carbon('2014-02-14 13:14:15')
+				new Time('2014-02-14 13:14:15')
 			],
 			[
 				[
@@ -114,7 +114,7 @@ class DateTimeTypeTest extends TestCase {
 					'hour' => 1, 'minute' => 14, 'second' => 15,
 					'meridian' => 'am'
 				],
-				new Carbon('2014-02-14 01:14:15')
+				new Time('2014-02-14 01:14:15')
 			],
 			[
 				[
@@ -122,30 +122,30 @@ class DateTimeTypeTest extends TestCase {
 					'hour' => 1, 'minute' => 14, 'second' => 15,
 					'meridian' => 'pm'
 				],
-				new Carbon('2014-02-14 13:14:15')
+				new Time('2014-02-14 13:14:15')
 			],
 			[
 				[
 					'year' => 2014, 'month' => 2, 'day' => 14,
 				],
-				new Carbon('2014-02-14 00:00:00')
+				new Time('2014-02-14 00:00:00')
 			],
 
 			// Invalid array types
 			[
 				['year' => 'farts', 'month' => 'derp'],
-				new Carbon(date('Y-m-d 00:00:00'))
+				new Time(date('Y-m-d 00:00:00'))
 			],
 			[
 				['year' => 'farts', 'month' => 'derp', 'day' => 'farts'],
-				new Carbon(date('Y-m-d 00:00:00'))
+				new Time(date('Y-m-d 00:00:00'))
 			],
 			[
 				[
 					'year' => '2014', 'month' => '02', 'day' => '14',
 					'hour' => 'farts', 'minute' => 'farts'
 				],
-				new Carbon('2014-02-14 00:00:00')
+				new Time('2014-02-14 00:00:00')
 			],
 		];
 	}

+ 13 - 13
tests/TestCase/Database/Type/DateTypeTest.php

@@ -17,7 +17,7 @@ namespace Cake\Test\TestCase\Database\Type;
 use Cake\Database\Type;
 use Cake\Database\Type\DateType;
 use Cake\TestSuite\TestCase;
-use Carbon\Carbon;
+use Cake\Utility\Time;
 
 /**
  * Test for the Date type.
@@ -70,11 +70,11 @@ class DateTypeTest extends TestCase {
 		$result = $this->type->toDatabase($value, $this->driver);
 		$this->assertEquals($value, $result);
 
-		$date = new Carbon('2013-08-12');
+		$date = new Time('2013-08-12');
 		$result = $this->type->toDatabase($date, $this->driver);
 		$this->assertEquals('2013-08-12', $result);
 
-		$date = new Carbon('2013-08-12 15:16:18');
+		$date = new Time('2013-08-12 15:16:18');
 		$result = $this->type->toDatabase($date, $this->driver);
 		$this->assertEquals('2013-08-12', $result);
 	}
@@ -85,7 +85,7 @@ class DateTypeTest extends TestCase {
  * @return array
  */
 	public function marshalProvider() {
-		$date = new Carbon('@1392387900');
+		$date = new Time('@1392387900');
 		$date->setTime(0, 0, 0);
 
 		return [
@@ -100,13 +100,13 @@ class DateTypeTest extends TestCase {
 			// valid string types
 			['1392387900', $date],
 			[1392387900, $date],
-			['2014-02-14', new Carbon('2014-02-14')],
-			['2014-02-14 13:14:15', new Carbon('2014-02-14 00:00:00')],
+			['2014-02-14', new Time('2014-02-14')],
+			['2014-02-14 13:14:15', new Time('2014-02-14 00:00:00')],
 
 			// valid array types
 			[
 				['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15],
-				new Carbon('2014-02-14 00:00:00')
+				new Time('2014-02-14 00:00:00')
 			],
 			[
 				[
@@ -114,7 +114,7 @@ class DateTypeTest extends TestCase {
 					'hour' => 1, 'minute' => 14, 'second' => 15,
 					'meridian' => 'am'
 				],
-				new Carbon('2014-02-14 00:00:00')
+				new Time('2014-02-14 00:00:00')
 			],
 			[
 				[
@@ -122,30 +122,30 @@ class DateTypeTest extends TestCase {
 					'hour' => 1, 'minute' => 14, 'second' => 15,
 					'meridian' => 'pm'
 				],
-				new Carbon('2014-02-14 00:00:00')
+				new Time('2014-02-14 00:00:00')
 			],
 			[
 				[
 					'year' => 2014, 'month' => 2, 'day' => 14,
 				],
-				new Carbon('2014-02-14 00:00:00')
+				new Time('2014-02-14 00:00:00')
 			],
 
 			// Invalid array types
 			[
 				['year' => 'farts', 'month' => 'derp'],
-				new Carbon(date('Y-m-d 00:00:00'))
+				new Time(date('Y-m-d 00:00:00'))
 			],
 			[
 				['year' => 'farts', 'month' => 'derp', 'day' => 'farts'],
-				new Carbon(date('Y-m-d 00:00:00'))
+				new Time(date('Y-m-d 00:00:00'))
 			],
 			[
 				[
 					'year' => '2014', 'month' => '02', 'day' => '14',
 					'hour' => 'farts', 'minute' => 'farts'
 				],
-				new Carbon('2014-02-14 00:00:00')
+				new Time('2014-02-14 00:00:00')
 			],
 		];
 	}

+ 12 - 12
tests/TestCase/Database/Type/TimeTypeTest.php

@@ -17,7 +17,7 @@ namespace Cake\Test\TestCase\Database\Type;
 use Cake\Database\Type;
 use Cake\Database\Type\TimeType;
 use Cake\TestSuite\TestCase;
-use Carbon\Carbon;
+use Cake\Utility\Time;
 
 /**
  * Test for the Time type.
@@ -70,11 +70,11 @@ class TimeTypeTest extends TestCase {
 		$result = $this->type->toDatabase($value, $this->driver);
 		$this->assertEquals($value, $result);
 
-		$date = new Carbon('16:30:15');
+		$date = new Time('16:30:15');
 		$result = $this->type->toDatabase($date, $this->driver);
 		$this->assertEquals('16:30:15', $result);
 
-		$date = new Carbon('2013-08-12 15:16:18');
+		$date = new Time('2013-08-12 15:16:18');
 		$result = $this->type->toDatabase($date, $this->driver);
 		$this->assertEquals('15:16:18', $result);
 	}
@@ -85,7 +85,7 @@ class TimeTypeTest extends TestCase {
  * @return array
  */
 	public function marshalProvider() {
-		$date = new Carbon('@1392387900');
+		$date = new Time('@1392387900');
 
 		return [
 			// invalid types.
@@ -99,13 +99,13 @@ class TimeTypeTest extends TestCase {
 			// valid string types
 			['1392387900', $date],
 			[1392387900, $date],
-			['13:10:10', new Carbon('13:10:10')],
-			['2014-02-14 13:14:15', new Carbon('2014-02-14 13:14:15')],
+			['13:10:10', new Time('13:10:10')],
+			['2014-02-14 13:14:15', new Time('2014-02-14 13:14:15')],
 
 			// valid array types
 			[
 				['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15],
-				new Carbon('2014-02-14 13:14:15')
+				new Time('2014-02-14 13:14:15')
 			],
 			[
 				[
@@ -113,7 +113,7 @@ class TimeTypeTest extends TestCase {
 					'hour' => 1, 'minute' => 14, 'second' => 15,
 					'meridian' => 'am'
 				],
-				new Carbon('2014-02-14 01:14:15')
+				new Time('2014-02-14 01:14:15')
 			],
 			[
 				[
@@ -121,26 +121,26 @@ class TimeTypeTest extends TestCase {
 					'hour' => 1, 'minute' => 14, 'second' => 15,
 					'meridian' => 'pm'
 				],
-				new Carbon('2014-02-14 13:14:15')
+				new Time('2014-02-14 13:14:15')
 			],
 			[
 				[
 					'hour' => 1, 'minute' => 14, 'second' => 15,
 				],
-				new Carbon('01:14:15')
+				new Time('01:14:15')
 			],
 
 			// Invalid array types
 			[
 				['hour' => 'nope', 'minute' => 14, 'second' => 15],
-				new Carbon(date('Y-m-d 00:14:15'))
+				new Time(date('Y-m-d 00:14:15'))
 			],
 			[
 				[
 					'year' => '2014', 'month' => '02', 'day' => '14',
 					'hour' => 'nope', 'minute' => 'nope'
 				],
-				new Carbon('2014-02-14 00:00:00')
+				new Time('2014-02-14 00:00:00')
 			],
 		];
 	}

+ 5 - 5
tests/TestCase/ORM/MarshallerTest.php

@@ -19,7 +19,7 @@ use Cake\ORM\Marshaller;
 use Cake\ORM\Table;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
-use Carbon\Carbon;
+use Cake\Utility\Time;
 
 /**
  * Test entity for mass assignment.
@@ -131,7 +131,7 @@ class MarshallerTest extends TestCase {
 		$marshall = new Marshaller($this->comments);
 		$result = $marshall->one($data, []);
 
-		$this->assertEquals(new Carbon('2014-02-14 00:00:00'), $result->created);
+		$this->assertEquals(new Time('2014-02-14 00:00:00'), $result->created);
 
 		$data['created'] = [
 			'year' => '2014',
@@ -142,7 +142,7 @@ class MarshallerTest extends TestCase {
 			'meridian' => 'pm'
 		];
 		$result = $marshall->one($data, []);
-		$this->assertEquals(new Carbon('2014-02-14 21:25:00'), $result->created);
+		$this->assertEquals(new Time('2014-02-14 21:25:00'), $result->created);
 
 		$data['created'] = [
 			'year' => '2014',
@@ -152,11 +152,11 @@ class MarshallerTest extends TestCase {
 			'minute' => 25,
 		];
 		$result = $marshall->one($data, []);
-		$this->assertEquals(new Carbon('2014-02-14 09:25:00'), $result->created);
+		$this->assertEquals(new Time('2014-02-14 09:25:00'), $result->created);
 
 		$data['created'] = '2014-02-14 09:25:00';
 		$result = $marshall->one($data, []);
-		$this->assertEquals(new Carbon('2014-02-14 09:25:00'), $result->created);
+		$this->assertEquals(new Time('2014-02-14 09:25:00'), $result->created);
 
 		$data['created'] = 1392387900;
 		$result = $marshall->one($data, []);

+ 3 - 3
tests/TestCase/ORM/QueryRegressionTest.php

@@ -18,7 +18,7 @@ use Cake\ORM\Query;
 use Cake\ORM\Table;
 use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
-use Carbon\Carbon;
+use Cake\Utility\Time;
 
 /**
  * Contains regression test for the Query builder
@@ -52,8 +52,8 @@ class QueryRegressionTest extends TestCase {
 	public function testSelectTimestampColumn() {
 		$table = TableRegistry::get('users');
 		$user = $table->find()->where(['id' => 1])->first();
-		$this->assertEquals(new Carbon('2007-03-17 01:16:23'), $user->created);
-		$this->assertEquals(new Carbon('2007-03-17 01:18:31'), $user->updated);
+		$this->assertEquals(new Time('2007-03-17 01:16:23'), $user->created);
+		$this->assertEquals(new Time('2007-03-17 01:18:31'), $user->updated);
 	}
 
 /**

+ 33 - 33
tests/TestCase/ORM/TableTest.php

@@ -21,8 +21,8 @@ use Cake\Database\TypeMap;
 use Cake\Datasource\ConnectionManager;
 use Cake\ORM\Table;
 use Cake\ORM\TableRegistry;
+use Cake\Utility\Time;
 use Cake\Validation\Validator;
-use Carbon\Carbon;
 
 /**
  * Used to test correct class is instantiated when using TableRegistry::get();
@@ -285,15 +285,15 @@ class TableTest extends \Cake\TestSuite\TestCase {
 				'id' => 1,
 				'username' => 'mariano',
 				'password' => '$2a$10$u05j8FjsvLBNdfhBhc21LOuVMpzpabVXQ9OpC2wO3pSO0q6t7HHMO',
-				'created' => new Carbon('2007-03-17 01:16:23'),
-				'updated' => new Carbon('2007-03-17 01:18:31'),
+				'created' => new Time('2007-03-17 01:16:23'),
+				'updated' => new Time('2007-03-17 01:18:31'),
 			],
 			[
 				'id' => 2,
 				'username' => 'nate',
 				'password' => '$2a$10$u05j8FjsvLBNdfhBhc21LOuVMpzpabVXQ9OpC2wO3pSO0q6t7HHMO',
-				'created' => new Carbon('2008-03-17 01:18:23'),
-				'updated' => new Carbon('2008-03-17 01:20:31'),
+				'created' => new Time('2008-03-17 01:18:23'),
+				'updated' => new Time('2008-03-17 01:20:31'),
 			],
 		];
 		$this->assertEquals($expected, $results);
@@ -348,7 +348,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		]);
 		$query = $table->find('all')
 			->select(['id', 'username'])
-			->where(['created >=' => new Carbon('2010-01-22 00:00')])
+			->where(['created >=' => new Time('2010-01-22 00:00')])
 			->hydrate(false)
 			->order('id');
 		$expected = [
@@ -357,7 +357,7 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		];
 		$this->assertSame($expected, $query->toArray());
 
-		$query->orWhere(['users.created' => new Carbon('2008-03-17 01:18:23')]);
+		$query->orWhere(['users.created' => new Time('2008-03-17 01:18:23')]);
 		$expected = [
 			['id' => 2, 'username' => 'nate'],
 			['id' => 3, 'username' => 'larry'],
@@ -1118,8 +1118,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$entity = new \Cake\ORM\Entity([
 			'username' => 'superuser',
 			'password' => 'root',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$table = TableRegistry::get('users');
 		$this->assertSame($entity, $table->save($entity));
@@ -1153,8 +1153,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 			'username' => 'superuser',
 			'password' => 'root',
 			'crazyness' => 'super crazy value',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00'),
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00'),
 		]);
 		$table = TableRegistry::get('users');
 		$this->assertSame($entity, $table->save($entity));
@@ -1175,8 +1175,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$table = TableRegistry::get('users');
 		$data = new \Cake\ORM\Entity([
 			'username' => 'superuser',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$listener = function($e, $entity, $options) use ($data) {
 			$this->assertSame($data, $entity);
@@ -1200,8 +1200,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$data = new \Cake\ORM\Entity([
 			'username' => 'superuser',
 			'password' => 'foo',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$listener1 = function($e, $entity, $options) {
 			$options['crazy'] = true;
@@ -1229,8 +1229,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$table = TableRegistry::get('users');
 		$data = new \Cake\ORM\Entity([
 			'username' => 'superuser',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$listener = function($e, $entity) {
 			$e->stopPropagation();
@@ -1253,8 +1253,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$table = TableRegistry::get('users');
 		$data = new \Cake\ORM\Entity([
 			'username' => 'superuser',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 
 		$called = false;
@@ -1288,8 +1288,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$statement = $this->getMock('\Cake\Database\Statement\StatementDecorator');
 		$data = new \Cake\ORM\Entity([
 			'username' => 'superuser',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 
 		$table->expects($this->once())->method('exists')
@@ -1336,8 +1336,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$connection->expects($this->once())->method('commit');
 		$data = new \Cake\ORM\Entity([
 			'username' => 'superuser',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$this->assertSame($data, $table->save($data));
 	}
@@ -1383,8 +1383,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 
 		$data = new \Cake\ORM\Entity([
 			'username' => 'superuser',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$table->save($data);
 	}
@@ -1434,8 +1434,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 
 		$data = new \Cake\ORM\Entity([
 			'username' => 'superuser',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$table->save($data);
 	}
@@ -1451,8 +1451,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$entity = new \Cake\ORM\Entity([
 			'username' => 'superuser',
 			'password' => 'root',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$entity->clean();
 		$entity->dirty('username', true);
@@ -1478,8 +1478,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$entity = new \Cake\ORM\Entity([
 			'username' => 'superuser',
 			'password' => 'root',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$table = TableRegistry::get('users');
 		$this->assertSame($entity, $table->save($entity));
@@ -1499,8 +1499,8 @@ class TableTest extends \Cake\TestSuite\TestCase {
 		$entity = new \Cake\ORM\Entity([
 			'username' => 'superuser',
 			'password' => 'root',
-			'created' => new Carbon('2013-10-10 00:00'),
-			'updated' => new Carbon('2013-10-10 00:00')
+			'created' => new Time('2013-10-10 00:00'),
+			'updated' => new Time('2013-10-10 00:00')
 		]);
 		$table = TableRegistry::get('users');
 		$this->assertSame($entity, $table->save($entity));

文件差异内容过多而无法显示
+ 232 - 783
tests/TestCase/Utility/TimeTest.php


+ 331 - 82
tests/TestCase/View/Helper/TimeHelperTest.php

@@ -24,29 +24,6 @@ use Cake\View\Helper\TimeHelper;
 use Cake\View\View;
 
 /**
- * TimeHelperTestObject class
- *
- */
-class TimeHelperTestObject extends TimeHelper {
-
-	public function attach(TimeMock $cakeTime) {
-		$this->_engine = $cakeTime;
-	}
-
-	public function engine() {
-		return $this->_engine;
-	}
-
-}
-
-/**
- * TimeMock class
- *
- */
-class TimeMock {
-}
-
-/**
  * TimeHelperTest class
  *
  */
@@ -54,8 +31,6 @@ class TimeHelperTest extends TestCase {
 
 	public $Time = null;
 
-	public $CakeTime = null;
-
 /**
  * setUp method
  *
@@ -64,63 +39,7 @@ class TimeHelperTest extends TestCase {
 	public function setUp() {
 		parent::setUp();
 		$this->View = new View();
-
-		$this->_appNamespace = Configure::read('App.namespace');
-		Configure::write('App.namespace', 'TestApp');
-	}
-
-/**
- * tearDown method
- *
- * @return void
- */
-	public function tearDown() {
-		unset($this->View);
-		Configure::write('App.namespace', $this->_appNamespace);
-		parent::tearDown();
-	}
-
-/**
- * test Cake\Utility\Time class methods are called correctly
- *
- * @return void
- */
-	public function testTimeHelperProxyMethodCalls() {
-		$methods = array(
-			'convertSpecifiers', 'convert', 'serverOffset', 'fromString',
-			'nice', 'niceShort', 'daysAsSql', 'dayAsSql',
-			'isToday', 'isThisMonth', 'isThisYear', 'wasYesterday',
-			'isTomorrow', 'toQuarter', 'toUnix', 'toAtom', 'toRSS',
-			'wasWithinLast', 'gmt', 'format', 'i18nFormat',
-		);
-		$CakeTime = $this->getMock(__NAMESPACE__ . '\TimeMock', $methods);
-		$Time = new TimeHelperTestObject($this->View, array('engine' => __NAMESPACE__ . '\TimeMock'));
-		$Time->attach($CakeTime);
-		foreach ($methods as $method) {
-			$CakeTime->expects($this->at(0))->method($method);
-			$Time->{$method}('who', 'what', 'when', 'where', 'how');
-		}
-
-		$CakeTime = $this->getMock(__NAMESPACE__ . '\TimeMock', array('timeAgoInWords'));
-		$Time = new TimeHelperTestObject($this->View, array('engine' => __NAMESPACE__ . '\TimeMock'));
-		$Time->attach($CakeTime);
-		$CakeTime->expects($this->at(0))->method('timeAgoInWords');
-		$Time->timeAgoInWords('who', array('what'), array('when'), array('where'), array('how'));
-	}
-
-/**
- * test engine override
- *
- * @return void
- */
-	public function testEngineOverride() {
-		$Time = new TimeHelperTestObject($this->View, array('engine' => 'TestAppEngine'));
-		$this->assertInstanceOf('TestApp\Utility\TestAppEngine', $Time->engine());
-
-		Plugin::load('TestPlugin');
-		$Time = new TimeHelperTestObject($this->View, array('engine' => 'TestPlugin.TestPluginEngine'));
-		$this->assertInstanceOf('TestPlugin\Utility\TestPluginEngine', $Time->engine());
-		Plugin::unload('TestPlugin');
+		$this->Time = new TimeHelper($this->View);
 	}
 
 /**
@@ -179,4 +98,334 @@ class TimeHelperTest extends TestCase {
 		$this->assertTags($result, $expected);
 	}
 
+/**
+ * testToQuarter method
+ *
+ * @return void
+ */
+	public function testToQuarter() {
+		$this->assertEquals(4, $this->Time->toQuarter('2007-12-25'));
+		$this->assertEquals(['2007-10-01', '2007-12-31'], $this->Time->toQuarter('2007-12-25', true));
+	}
+
+/**
+ * testNice method
+ *
+ * @return void
+ */
+	public function testNice() {
+		$time = '2014-04-20 20:00';
+		$this->assertTimeFormat('Apr 20, 2014, 8:00 PM', $this->Time->nice($time));
+
+		$result = $this->Time->nice($time, 'America/New_York');
+		$this->assertTimeFormat('Apr 20, 2014, 4:00 PM', $result);
+	}
+
+/**
+ * testToUnix method
+ *
+ * @return void
+ */
+	public function testToUnix() {
+		$this->assertEquals(1397980800, $this->Time->toUnix('2014-04-20 08:00:00'));
+	}
+
+/**
+ * testToAtom method
+ *
+ * @return void
+ */
+	public function testToAtom() {
+		$dateTime = new \DateTime;
+		$this->assertEquals($dateTime->format($dateTime::ATOM), $this->Time->toAtom($dateTime->getTimestamp()));
+	}
+
+/**
+ * testToRss method
+ *
+ * @return void
+ */
+	public function testToRss() {
+		$date = '2012-08-12 12:12:45';
+		$time = strtotime($date);
+		$this->assertEquals(date('r', $time), $this->Time->toRss($time));
+
+		$timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu');
+		foreach ($timezones as $timezone) {
+			$yourTimezone = new \DateTimeZone($timezone);
+			$yourTime = new \DateTime($date, $yourTimezone);
+			$time = $yourTime->format('U');
+			$this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $timezone), "Failed on $timezone");
+		}
+	}
+
+/**
+ * testOfGmt method
+ *
+ * @return void
+ */
+	public function testGmt() {
+		$this->assertEquals(1397980800, $this->Time->gmt('2014-04-20 08:00:00'));
+	}
+
+/**
+ * testIsToday method
+ *
+ * @return void
+ */
+	public function testIsToday() {
+		$result = $this->Time->isToday('+1 day');
+		$this->assertFalse($result);
+		$result = $this->Time->isToday('+1 days');
+		$this->assertFalse($result);
+		$result = $this->Time->isToday('+0 day');
+		$this->assertTrue($result);
+		$result = $this->Time->isToday('-1 day');
+		$this->assertFalse($result);
+	}
+/**
+ * testIsFuture method
+ *
+ * @return void
+ */
+	public function testIsFuture() {
+		$this->assertTrue($this->Time->isFuture('+1 month'));
+		$this->assertTrue($this->Time->isFuture('+1 days'));
+		$this->assertTrue($this->Time->isFuture('+1 minute'));
+		$this->assertTrue($this->Time->isFuture('+1 second'));
+
+		$this->assertFalse($this->Time->isFuture('-1 second'));
+		$this->assertFalse($this->Time->isFuture('-1 day'));
+		$this->assertFalse($this->Time->isFuture('-1 week'));
+		$this->assertFalse($this->Time->isFuture('-1 month'));
+	}
+
+/**
+ * testIsPast method
+ *
+ * @return void
+ */
+	public function testIsPast() {
+		$this->assertFalse($this->Time->isPast('+1 month'));
+		$this->assertFalse($this->Time->isPast('+1 days'));
+		$this->assertFalse($this->Time->isPast('+1 minute'));
+		$this->assertFalse($this->Time->isPast('+1 second'));
+
+		$this->assertTrue($this->Time->isPast('-1 second'));
+		$this->assertTrue($this->Time->isPast('-1 day'));
+		$this->assertTrue($this->Time->isPast('-1 week'));
+		$this->assertTrue($this->Time->isPast('-1 month'));
+	}
+
+/**
+ * testIsThisWeek method
+ *
+ * @return void
+ */
+	public function testIsThisWeek() {
+		// A map of days which goes from -1 day of week to +1 day of week
+		$map = array(
+			'Mon' => array(-1, 7), 'Tue' => array(-2, 6), 'Wed' => array(-3, 5),
+			'Thu' => array(-4, 4), 'Fri' => array(-5, 3), 'Sat' => array(-6, 2),
+			'Sun' => array(-7, 1)
+		);
+		$days = $map[date('D')];
+
+		for ($day = $days[0] + 1; $day < $days[1]; $day++) {
+			$this->assertTrue($this->Time->isThisWeek(($day > 0 ? '+' : '') . $day . ' days'));
+		}
+		$this->assertFalse($this->Time->isThisWeek($days[0] . ' days'));
+		$this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days'));
+	}
+
+/**
+ * testIsThisMonth method
+ *
+ * @return void
+ */
+	public function testIsThisMonth() {
+		$result = $this->Time->isThisMonth('+0 day');
+		$this->assertTrue($result);
+		$result = $this->Time->isThisMonth($time = mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y')));
+		$this->assertTrue($result);
+		$result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') - mt_rand(1, 12)));
+		$this->assertFalse($result);
+		$result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') + mt_rand(1, 12)));
+		$this->assertFalse($result);
+	}
+
+/**
+ * testIsThisYear method
+ *
+ * @return void
+ */
+	public function testIsThisYear() {
+		$result = $this->Time->isThisYear('+0 day');
+		$this->assertTrue($result);
+		$result = $this->Time->isThisYear(mktime(0, 0, 0, mt_rand(1, 12), mt_rand(1, 28), date('Y')));
+		$this->assertTrue($result);
+	}
+
+/**
+ * testWasYesterday method
+ *
+ * @return void
+ */
+	public function testWasYesterday() {
+		$result = $this->Time->wasYesterday('+1 day');
+		$this->assertFalse($result);
+		$result = $this->Time->wasYesterday('+1 days');
+		$this->assertFalse($result);
+		$result = $this->Time->wasYesterday('+0 day');
+		$this->assertFalse($result);
+		$result = $this->Time->wasYesterday('-1 day');
+		$this->assertTrue($result);
+		$result = $this->Time->wasYesterday('-1 days');
+		$this->assertTrue($result);
+		$result = $this->Time->wasYesterday('-2 days');
+		$this->assertFalse($result);
+	}
+
+/**
+ * testIsTomorrow method
+ *
+ * @return void
+ */
+	public function testIsTomorrow() {
+		$result = $this->Time->isTomorrow('+1 day');
+		$this->assertTrue($result);
+		$result = $this->Time->isTomorrow('+1 days');
+		$this->assertTrue($result);
+		$result = $this->Time->isTomorrow('+0 day');
+		$this->assertFalse($result);
+		$result = $this->Time->isTomorrow('-1 day');
+		$this->assertFalse($result);
+	}
+
+/**
+ * testWasWithinLast method
+ *
+ * @return void
+ */
+	public function testWasWithinLast() {
+		$this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
+		$this->assertTrue($this->Time->wasWithinLast('1 week', '-1 week'));
+		$this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
+		$this->assertTrue($this->Time->wasWithinLast('1 second', '-1 second'));
+		$this->assertTrue($this->Time->wasWithinLast('1 minute', '-1 minute'));
+		$this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
+		$this->assertTrue($this->Time->wasWithinLast('1 month', '-1 month'));
+		$this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
+
+		$this->assertTrue($this->Time->wasWithinLast('1 week', '-1 day'));
+		$this->assertTrue($this->Time->wasWithinLast('2 week', '-1 week'));
+		$this->assertFalse($this->Time->wasWithinLast('1 second', '-1 year'));
+		$this->assertTrue($this->Time->wasWithinLast('10 minutes', '-1 second'));
+		$this->assertTrue($this->Time->wasWithinLast('23 minutes', '-1 minute'));
+		$this->assertFalse($this->Time->wasWithinLast('0 year', '-1 year'));
+		$this->assertTrue($this->Time->wasWithinLast('13 month', '-1 month'));
+		$this->assertTrue($this->Time->wasWithinLast('2 days', '-1 day'));
+
+		$this->assertFalse($this->Time->wasWithinLast('1 week', '-2 weeks'));
+		$this->assertFalse($this->Time->wasWithinLast('1 second', '-2 seconds'));
+		$this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
+		$this->assertFalse($this->Time->wasWithinLast('1 hour', '-2 hours'));
+		$this->assertFalse($this->Time->wasWithinLast('1 month', '-2 months'));
+		$this->assertFalse($this->Time->wasWithinLast('1 year', '-2 years'));
+
+		$this->assertFalse($this->Time->wasWithinLast('1 day', '-2 weeks'));
+		$this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
+		$this->assertFalse($this->Time->wasWithinLast('0 days', '-2 days'));
+		$this->assertTrue($this->Time->wasWithinLast('1 hour', '-20 seconds'));
+		$this->assertTrue($this->Time->wasWithinLast('1 year', '-60 minutes -30 seconds'));
+		$this->assertTrue($this->Time->wasWithinLast('3 years', '-2 months'));
+		$this->assertTrue($this->Time->wasWithinLast('5 months', '-4 months'));
+
+		$this->assertTrue($this->Time->wasWithinLast('5 ', '-3 days'));
+		$this->assertTrue($this->Time->wasWithinLast('1   ', '-1 hour'));
+		$this->assertTrue($this->Time->wasWithinLast('1   ', '-1 minute'));
+		$this->assertTrue($this->Time->wasWithinLast('1   ', '-23 hours -59 minutes -59 seconds'));
+	}
+
+/**
+ * testWasWithinLast method
+ *
+ * @return void
+ */
+	public function testIsWithinNext() {
+		$this->assertFalse($this->Time->isWithinNext('1 day', '-1 day'));
+		$this->assertFalse($this->Time->isWithinNext('1 week', '-1 week'));
+		$this->assertFalse($this->Time->isWithinNext('1 year', '-1 year'));
+		$this->assertFalse($this->Time->isWithinNext('1 second', '-1 second'));
+		$this->assertFalse($this->Time->isWithinNext('1 minute', '-1 minute'));
+		$this->assertFalse($this->Time->isWithinNext('1 year', '-1 year'));
+		$this->assertFalse($this->Time->isWithinNext('1 month', '-1 month'));
+		$this->assertFalse($this->Time->isWithinNext('1 day', '-1 day'));
+
+		$this->assertFalse($this->Time->isWithinNext('1 week', '-1 day'));
+		$this->assertFalse($this->Time->isWithinNext('2 week', '-1 week'));
+		$this->assertFalse($this->Time->isWithinNext('1 second', '-1 year'));
+		$this->assertFalse($this->Time->isWithinNext('10 minutes', '-1 second'));
+		$this->assertFalse($this->Time->isWithinNext('23 minutes', '-1 minute'));
+		$this->assertFalse($this->Time->isWithinNext('0 year', '-1 year'));
+		$this->assertFalse($this->Time->isWithinNext('13 month', '-1 month'));
+		$this->assertFalse($this->Time->isWithinNext('2 days', '-1 day'));
+
+		$this->assertFalse($this->Time->isWithinNext('1 week', '-2 weeks'));
+		$this->assertFalse($this->Time->isWithinNext('1 second', '-2 seconds'));
+		$this->assertFalse($this->Time->isWithinNext('1 day', '-2 days'));
+		$this->assertFalse($this->Time->isWithinNext('1 hour', '-2 hours'));
+		$this->assertFalse($this->Time->isWithinNext('1 month', '-2 months'));
+		$this->assertFalse($this->Time->isWithinNext('1 year', '-2 years'));
+
+		$this->assertFalse($this->Time->isWithinNext('1 day', '-2 weeks'));
+		$this->assertFalse($this->Time->isWithinNext('1 day', '-2 days'));
+		$this->assertFalse($this->Time->isWithinNext('0 days', '-2 days'));
+		$this->assertFalse($this->Time->isWithinNext('1 hour', '-20 seconds'));
+		$this->assertFalse($this->Time->isWithinNext('1 year', '-60 minutes -30 seconds'));
+		$this->assertFalse($this->Time->isWithinNext('3 years', '-2 months'));
+		$this->assertFalse($this->Time->isWithinNext('5 months', '-4 months'));
+
+		$this->assertTrue($this->Time->isWithinNext('1 day', '+1 day'));
+		$this->assertTrue($this->Time->isWithinNext('7 day', '+1 week'));
+		$this->assertTrue($this->Time->isWithinNext('1 minute', '+1 second'));
+		$this->assertTrue($this->Time->isWithinNext('1 month', '+1 month'));
+	}
+
+/**
+ * test formatting dates taking in account preferred i18n locale file
+ *
+ * @return void
+ */
+	public function testFormat() {
+		$time = strtotime('Thu Jan 14 13:59:28 2010');
+
+		$result = $this->Time->format($time);
+		$expected = '1/14/10, 1:59 PM';
+		$this->assertTimeFormat($expected, $result);
+
+		$result = $this->Time->format($time, \IntlDateFormatter::FULL);
+		$expected = 'Thursday, January 14, 2010 at 1:59:28 PM GMT';
+		$this->assertTimeFormat($expected, $result);
+
+		$result = $this->Time->format('invalid date', null, 'Date invalid');
+		$expected = 'Date invalid';
+		$this->assertEquals($expected, $result);
+	}
+
+/**
+ * Cusotm assert to allow for variation in the version of the intl library, where
+ * some translations contain a few extra commas.
+ *
+ * @param string $expected
+ * @param string $result
+ * @return void
+ */
+	public function assertTimeFormat($expected, $result) {
+		return $this->assertEquals(
+			str_replace([',', '(', ')', ' at'], '', $expected),
+			str_replace([',', '(', ')', ' at'], '', $result)
+		);
+	}
+
 }