From caac0c6d0a161335a868677a578584c49e0d7b1b Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sun, 31 Aug 2014 22:08:37 +0200 Subject: [PATCH] Moving Utility\Time to I18n\Time --- src/Controller/Component/CookieComponent.php | 2 +- src/Database/Type/DateTimeType.php | 2 +- src/{Utility => I18n}/Time.php | 20 ++++++++-------- src/Model/Behavior/TimestampBehavior.php | 4 ++-- src/View/Helper/TimeHelper.php | 24 +++++++++---------- tests/TestCase/Auth/BasicAuthenticateTest.php | 2 +- .../TestCase/Auth/DigestAuthenticateTest.php | 2 +- tests/TestCase/Auth/FormAuthenticateTest.php | 2 +- .../Component/CookieComponentTest.php | 2 +- .../Database/Type/DateTimeTypeTest.php | 6 ++--- tests/TestCase/Database/Type/DateTypeTest.php | 2 +- tests/TestCase/Database/Type/TimeTypeTest.php | 2 +- .../Model/Behavior/TimestampBehaviorTest.php | 8 +++---- tests/TestCase/ORM/MarshallerTest.php | 2 +- tests/TestCase/ORM/QueryRegressionTest.php | 2 +- tests/TestCase/ORM/TableTest.php | 2 +- tests/TestCase/Utility/TimeTest.php | 2 +- tests/TestCase/View/Helper/TimeHelperTest.php | 2 +- 18 files changed, 44 insertions(+), 44 deletions(-) rename src/{Utility => I18n}/Time.php (97%) diff --git a/src/Controller/Component/CookieComponent.php b/src/Controller/Component/CookieComponent.php index 41d24363c29..bb9ac5da1e9 100644 --- a/src/Controller/Component/CookieComponent.php +++ b/src/Controller/Component/CookieComponent.php @@ -17,11 +17,11 @@ use Cake\Controller\Component; use Cake\Controller\ComponentRegistry; use Cake\Core\Configure; +use Cake\I18n\Time; use Cake\Network\Request; use Cake\Network\Response; use Cake\Utility\Hash; use Cake\Utility\Security; -use Cake\Utility\Time; /** * Cookie Component. diff --git a/src/Database/Type/DateTimeType.php b/src/Database/Type/DateTimeType.php index d4e51654c1b..ff19eb1efa6 100644 --- a/src/Database/Type/DateTimeType.php +++ b/src/Database/Type/DateTimeType.php @@ -28,7 +28,7 @@ class DateTimeType extends \Cake\Database\Type { * * @var string */ - public static $dateTimeClass = 'Cake\Utility\Time'; + public static $dateTimeClass = 'Cake\I18n\Time'; /** * String format to use for DateTime parsing diff --git a/src/Utility/Time.php b/src/I18n/Time.php similarity index 97% rename from src/Utility/Time.php rename to src/I18n/Time.php index 7082cae600a..564f7ec84fb 100644 --- a/src/Utility/Time.php +++ b/src/I18n/Time.php @@ -12,7 +12,7 @@ * @since 3.0.0 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ -namespace Cake\Utility; +namespace Cake\I18n; use Carbon\Carbon; use IntlDateFormatter; @@ -26,7 +26,7 @@ class Time extends Carbon implements JsonSerializable { /** - * The format to use when formatting a time using `Cake\Utility\Time::i18nFormat()` + * The format to use when formatting a time using `Cake\I18n\Time::i18nFormat()` * and `__toString` * * The format should be either the formatting constants from IntlDateFormatter as @@ -38,12 +38,12 @@ class Time extends Carbon implements JsonSerializable { * will be used to format the time part. * * @var mixed - * @see \Cake\Utility\Time::i18nFormat() + * @see \Cake\I18n\Time::i18nFormat() */ protected static $_toStringFormat = [IntlDateFormatter::SHORT, IntlDateFormatter::SHORT]; /** - * The format to use when formatting a time using `Cake\Utility\Time::nice()` + * The format to use when formatting a time using `Cake\I18n\Time::nice()` * * The format should be eiter the formatting constants from IntlDateFormatter as * described in (http://www.php.net/manual/en/class.intldateformatter.php) or a pattern @@ -54,7 +54,7 @@ class Time extends Carbon implements JsonSerializable { * will be used to format the time part. * * @var mixed - * @see \Cake\Utility\Time::nice() + * @see \Cake\I18n\Time::nice() */ public static $niceFormat = [IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT]; @@ -66,11 +66,11 @@ class Time extends Carbon implements JsonSerializable { public static $defaultLocale; /** - * The format to use when formatting a time using `Cake\Utility\Time::timeAgoInWords()` - * and the difference is more than `Cake\Utility\Time::$wordEnd` + * The format to use when formatting a time using `Cake\I18n\Time::timeAgoInWords()` + * and the difference is more than `Cake\I18n\Time::$wordEnd` * * @var string - * @see \Cake\Utility\Time::timeAgoInWords() + * @see \Cake\I18n\Time::timeAgoInWords() */ public static $wordFormat = [IntlDateFormatter::SHORT, -1]; @@ -79,7 +79,7 @@ class Time extends Carbon implements JsonSerializable { * and the difference is less than `Time::$wordEnd` * * @var array - * @see \Cake\Utility\Time::timeAgoInWords() + * @see \Cake\I18n\Time::timeAgoInWords() */ public static $wordAccuracy = array( 'year' => "day", @@ -95,7 +95,7 @@ class Time extends Carbon implements JsonSerializable { * The end of relative time telling * * @var string - * @see \Cake\Utility\Time::timeAgoInWords() + * @see \Cake\I18n\Time::timeAgoInWords() */ public static $wordEnd = '+1 month'; diff --git a/src/Model/Behavior/TimestampBehavior.php b/src/Model/Behavior/TimestampBehavior.php index cd833e3f07d..af98a531d7c 100644 --- a/src/Model/Behavior/TimestampBehavior.php +++ b/src/Model/Behavior/TimestampBehavior.php @@ -15,10 +15,10 @@ namespace Cake\Model\Behavior; use Cake\Event\Event; +use Cake\I18n\Time; use Cake\ORM\Behavior; use Cake\ORM\Entity; use Cake\ORM\Table; -use Cake\Utility\Time; class TimestampBehavior extends Behavior { @@ -130,7 +130,7 @@ public function implementedEvents() { * * @param \DateTime $ts Timestamp * @param bool $refreshTimestamp If true timestamp is refreshed. - * @return \Cake\Utility\Time + * @return \Cake\I18n\Time */ public function timestamp(\DateTime $ts = null, $refreshTimestamp = false) { if ($ts) { diff --git a/src/View/Helper/TimeHelper.php b/src/View/Helper/TimeHelper.php index 605d606a2ca..0620d4af47f 100644 --- a/src/View/Helper/TimeHelper.php +++ b/src/View/Helper/TimeHelper.php @@ -14,7 +14,7 @@ */ namespace Cake\View\Helper; -use Cake\Utility\Time; +use Cake\I18n\Time; use Cake\View\Helper; use Cake\View\Helper\StringTemplateTrait; @@ -24,7 +24,7 @@ * Manipulation of time data. * * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html - * @see \Cake\Utility\Time + * @see \Cake\I18n\Time */ class TimeHelper extends Helper { @@ -35,7 +35,7 @@ class TimeHelper extends Helper { * * @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 \Cake\Utility\Time + * @return \Cake\I18n\Time * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function fromString($dateString, $timezone = null) { @@ -158,7 +158,7 @@ public function isTomorrow($dateString, $timezone = null) { * @param int|string|\DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object * @param bool $range if true returns a range in Y-m-d format * @return mixed 1, 2, 3, or 4 quarter of year or array if $range true - * @see \Cake\Utility\Time::toQuarter() + * @see \Cake\I18n\Time::toQuarter() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function toQuarter($dateString, $range = false) { @@ -171,7 +171,7 @@ public function toQuarter($dateString, $range = false) { * @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 int Unix timestamp - * @see \Cake\Utility\Time::toUnix() + * @see \Cake\I18n\Time::toUnix() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function toUnix($dateString, $timezone = null) { @@ -184,7 +184,7 @@ public function toUnix($dateString, $timezone = null) { * @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 - * @see \Cake\Utility\Time::toAtom() + * @see \Cake\I18n\Time::toAtom() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function toAtom($dateString, $timezone = null) { @@ -219,7 +219,7 @@ public function toRSS($dateString, $timezone = null) { * @param int|string|\DateTime $dateTime UNIX timestamp, strtotime() valid string or DateTime object * @param array $options Default format if timestamp is used in $dateString * @return string Relative time string. - * @see \Cake\Utility\Time::timeAgoInWords() + * @see \Cake\I18n\Time::timeAgoInWords() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function timeAgoInWords($dateTime, array $options = array()) { @@ -261,7 +261,7 @@ public function timeAgoInWords($dateTime, array $options = array()) { * @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 - * @see \Cake\Utility\Time::wasWithinLast() + * @see \Cake\I18n\Time::wasWithinLast() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time */ public function wasWithinLast($timeInterval, $dateString, $timezone = null) { @@ -276,7 +276,7 @@ public function wasWithinLast($timeInterval, $dateString, $timezone = null) { * @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 - * @see \Cake\Utility\Time::wasWithinLast() + * @see \Cake\I18n\Time::wasWithinLast() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time */ public function isWithinNext($timeInterval, $dateString, $timezone = null) { @@ -288,7 +288,7 @@ public function isWithinNext($timeInterval, $dateString, $timezone = null) { * * @param int|string|\DateTime $string UNIX timestamp, strtotime() valid string or DateTime object * @return int UNIX timestamp - * @see \Cake\Utility\Time::gmt() + * @see \Cake\I18n\Time::gmt() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function gmt($string = null) { @@ -306,7 +306,7 @@ public function gmt($string = null) { * @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 - * @see \Cake\Utility\Time::i18nFormat() + * @see \Cake\I18n\Time::i18nFormat() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function format($date, $format = null, $invalid = false, $timezone = null) { @@ -324,7 +324,7 @@ public function format($date, $format = null, $invalid = false, $timezone = null * @param string|\DateTimeZone $timezone User's timezone string or DateTimeZone object * @return string Formatted and translated date string * @throws \InvalidArgumentException When the date cannot be parsed - * @see \Cake\Utility\Time::i18nFormat() + * @see \Cake\I18n\Time::i18nFormat() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function i18nFormat($date, $format = null, $invalid = false, $timezone = null) { diff --git a/tests/TestCase/Auth/BasicAuthenticateTest.php b/tests/TestCase/Auth/BasicAuthenticateTest.php index 9e6cd063986..e080c1e80f7 100644 --- a/tests/TestCase/Auth/BasicAuthenticateTest.php +++ b/tests/TestCase/Auth/BasicAuthenticateTest.php @@ -15,13 +15,13 @@ namespace Cake\Test\TestCase\Auth; use Cake\Auth\BasicAuthenticate; +use Cake\I18n\Time; use Cake\Network\Exception\UnauthorizedException; use Cake\Network\Request; use Cake\ORM\Entity; use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; use Cake\Utility\Security; -use Cake\Utility\Time; /** * Test case for BasicAuthentication diff --git a/tests/TestCase/Auth/DigestAuthenticateTest.php b/tests/TestCase/Auth/DigestAuthenticateTest.php index daf42d8fba3..9922dd170a9 100644 --- a/tests/TestCase/Auth/DigestAuthenticateTest.php +++ b/tests/TestCase/Auth/DigestAuthenticateTest.php @@ -17,12 +17,12 @@ namespace Cake\Test\TestCase\Auth; use Cake\Auth\DigestAuthenticate; +use Cake\I18n\Time; use Cake\Network\Exception\UnauthorizedException; use Cake\Network\Request; use Cake\ORM\Entity; use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; -use Cake\Utility\Time; /** * Test case for DigestAuthentication diff --git a/tests/TestCase/Auth/FormAuthenticateTest.php b/tests/TestCase/Auth/FormAuthenticateTest.php index dee16b420e3..6bd16bcc620 100644 --- a/tests/TestCase/Auth/FormAuthenticateTest.php +++ b/tests/TestCase/Auth/FormAuthenticateTest.php @@ -19,12 +19,12 @@ use Cake\Core\App; use Cake\Core\Configure; use Cake\Core\Plugin; +use Cake\I18n\Time; use Cake\Network\Request; use Cake\ORM\Entity; use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; use Cake\Utility\Security; -use Cake\Utility\Time; /** * Test case for FormAuthentication diff --git a/tests/TestCase/Controller/Component/CookieComponentTest.php b/tests/TestCase/Controller/Component/CookieComponentTest.php index dea4d4b0ca2..c4c2d9bc03a 100644 --- a/tests/TestCase/Controller/Component/CookieComponentTest.php +++ b/tests/TestCase/Controller/Component/CookieComponentTest.php @@ -18,11 +18,11 @@ use Cake\Controller\Component\CookieComponent; use Cake\Controller\Controller; use Cake\Event\Event; +use Cake\I18n\Time; use Cake\Network\Request; use Cake\Network\Response; use Cake\TestSuite\TestCase; use Cake\Utility\Security; -use Cake\Utility\Time; /** * CookieComponentTest class diff --git a/tests/TestCase/Database/Type/DateTimeTypeTest.php b/tests/TestCase/Database/Type/DateTimeTypeTest.php index 417fa920871..fc03245d16c 100644 --- a/tests/TestCase/Database/Type/DateTimeTypeTest.php +++ b/tests/TestCase/Database/Type/DateTimeTypeTest.php @@ -17,7 +17,7 @@ use Cake\Database\Type; use Cake\Database\Type\DateTimeType; use Cake\TestSuite\TestCase; -use Cake\Utility\Time; +use Cake\I18n\Time; /** * Test for the DateTime type. @@ -44,7 +44,7 @@ public function testToPHP() { $this->assertNull($this->type->toPHP(null, $this->driver)); $result = $this->type->toPHP('2001-01-04 12:13:14', $this->driver); - $this->assertInstanceOf('Cake\Utility\Time', $result); + $this->assertInstanceOf('Cake\I18n\Time', $result); $this->assertEquals('2001', $result->format('Y')); $this->assertEquals('01', $result->format('m')); $this->assertEquals('04', $result->format('d')); @@ -64,7 +64,7 @@ public function testToPHP() { public function testToPHPIncludingMilliseconds() { $in = '2014-03-24 20:44:36.315113'; $result = $this->type->toPHP($in, $this->driver); - $this->assertInstanceOf('Cake\Utility\Time', $result); + $this->assertInstanceOf('Cake\I18n\Time', $result); } /** diff --git a/tests/TestCase/Database/Type/DateTypeTest.php b/tests/TestCase/Database/Type/DateTypeTest.php index 778085fcaff..5f1fbc81ec1 100644 --- a/tests/TestCase/Database/Type/DateTypeTest.php +++ b/tests/TestCase/Database/Type/DateTypeTest.php @@ -17,7 +17,7 @@ use Cake\Database\Type; use Cake\Database\Type\DateType; use Cake\TestSuite\TestCase; -use Cake\Utility\Time; +use Cake\I18n\Time; /** * Test for the Date type. diff --git a/tests/TestCase/Database/Type/TimeTypeTest.php b/tests/TestCase/Database/Type/TimeTypeTest.php index ca8329c5a06..3e44e190455 100644 --- a/tests/TestCase/Database/Type/TimeTypeTest.php +++ b/tests/TestCase/Database/Type/TimeTypeTest.php @@ -17,7 +17,7 @@ use Cake\Database\Type; use Cake\Database\Type\TimeType; use Cake\TestSuite\TestCase; -use Cake\Utility\Time; +use Cake\I18n\Time; /** * Test for the Time type. diff --git a/tests/TestCase/Model/Behavior/TimestampBehaviorTest.php b/tests/TestCase/Model/Behavior/TimestampBehaviorTest.php index ddf9c2bbe6c..010528ede28 100644 --- a/tests/TestCase/Model/Behavior/TimestampBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/TimestampBehaviorTest.php @@ -15,11 +15,11 @@ namespace Cake\Test\TestCase\Model\Behavior; use Cake\Event\Event; +use Cake\I18n\Time; use Cake\Model\Behavior\TimestampBehavior; use Cake\ORM\Entity; use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; -use Cake\Utility\Time; /** * Behavior test case @@ -93,7 +93,7 @@ public function testCreatedAbsent() { $return = $this->Behavior->handleEvent($event, $entity); $this->assertTrue($return, 'Handle Event is expected to always return true'); - $this->assertInstanceOf('Cake\Utility\Time', $entity->created); + $this->assertInstanceOf('Cake\I18n\Time', $entity->created); $this->assertSame($ts->format('c'), $entity->created->format('c'), 'Created timestamp is not the same'); } @@ -154,7 +154,7 @@ public function testModifiedAbsent() { $return = $this->Behavior->handleEvent($event, $entity); $this->assertTrue($return, 'Handle Event is expected to always return true'); - $this->assertInstanceOf('Cake\Utility\Time', $entity->modified); + $this->assertInstanceOf('Cake\I18n\Time', $entity->modified); $this->assertSame($ts->format('c'), $entity->modified->format('c'), 'Modified timestamp is not the same'); } @@ -177,7 +177,7 @@ public function testModifiedPresent() { $return = $this->Behavior->handleEvent($event, $entity); $this->assertTrue($return, 'Handle Event is expected to always return true'); - $this->assertInstanceOf('Cake\Utility\Time', $entity->modified); + $this->assertInstanceOf('Cake\I18n\Time', $entity->modified); $this->assertSame($ts->format('c'), $entity->modified->format('c'), 'Modified timestamp is expected to be updated'); } diff --git a/tests/TestCase/ORM/MarshallerTest.php b/tests/TestCase/ORM/MarshallerTest.php index 552c54a00cf..13e8990df7f 100644 --- a/tests/TestCase/ORM/MarshallerTest.php +++ b/tests/TestCase/ORM/MarshallerTest.php @@ -14,12 +14,12 @@ */ namespace Cake\Test\TestCase\ORM; +use Cake\I18n\Time; use Cake\ORM\Entity; use Cake\ORM\Marshaller; use Cake\ORM\Table; use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; -use Cake\Utility\Time; /** * Test entity for mass assignment. diff --git a/tests/TestCase/ORM/QueryRegressionTest.php b/tests/TestCase/ORM/QueryRegressionTest.php index 6aefe668cd9..439ff5306a9 100644 --- a/tests/TestCase/ORM/QueryRegressionTest.php +++ b/tests/TestCase/ORM/QueryRegressionTest.php @@ -15,11 +15,11 @@ namespace Cake\Test\TestCase\ORM; use Cake\Core\Plugin; +use Cake\I18n\Time; use Cake\ORM\Query; use Cake\ORM\Table; use Cake\ORM\TableRegistry; use Cake\TestSuite\TestCase; -use Cake\Utility\Time; /** * Contains regression test for the Query builder diff --git a/tests/TestCase/ORM/TableTest.php b/tests/TestCase/ORM/TableTest.php index 08781f2b49e..d9633c721fe 100644 --- a/tests/TestCase/ORM/TableTest.php +++ b/tests/TestCase/ORM/TableTest.php @@ -19,9 +19,9 @@ use Cake\Database\Expression\QueryExpression; use Cake\Database\TypeMap; use Cake\Datasource\ConnectionManager; +use Cake\I18n\Time; use Cake\ORM\Table; use Cake\ORM\TableRegistry; -use Cake\Utility\Time; use Cake\Validation\Validator; /** diff --git a/tests/TestCase/Utility/TimeTest.php b/tests/TestCase/Utility/TimeTest.php index 2e3636bd1f4..1ddd9097892 100644 --- a/tests/TestCase/Utility/TimeTest.php +++ b/tests/TestCase/Utility/TimeTest.php @@ -16,8 +16,8 @@ */ namespace Cake\Test\TestCase\Utility; +use Cake\I18n\Time; use Cake\TestSuite\TestCase; -use Cake\Utility\Time; /** * TimeTest class diff --git a/tests/TestCase/View/Helper/TimeHelperTest.php b/tests/TestCase/View/Helper/TimeHelperTest.php index 5789258511c..d40ae4d59f2 100644 --- a/tests/TestCase/View/Helper/TimeHelperTest.php +++ b/tests/TestCase/View/Helper/TimeHelperTest.php @@ -17,8 +17,8 @@ use Cake\Core\App; use Cake\Core\Configure; use Cake\Core\Plugin; +use Cake\I18n\Time; use Cake\TestSuite\TestCase; -use Cake\Utility\Time; use Cake\View\Helper\TimeHelper; use Cake\View\View;