Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Cake\Test\TestCase\I18n; use Cake\Chronos\Chronos; use Cake\I18n\DateTim..
Decoded Output download
<?php
namespace Cake\Test\TestCase\I18n; use Cake\Chronos\Chronos; use Cake\I18n\DateTime; use Cake\I18n\I18n; use Cake\TestSuite\TestCase; use DateTime as NativeDateTime; use DateTimeZone; use IntlDateFormatter; class DateTimeTest extends TestCase { protected $now; public function setUp() : void { parent::setUp(); $this->now = DateTime::getTestNow(); } public function tearDown() : void { parent::tearDown(); DateTime::setTestNow($this->now); DateTime::setDefaultLocale(null); DateTime::resetToStringFormat(); DateTime::setJsonEncodeFormat("yyyy-MM-dd'T'HH':'mm':'ssxxx"); date_default_timezone_set("UTC"); I18n::setLocale(I18n::getDefaultLocale()); } public function testConstructFromAnotherInstance() : void { $time = "2015-01-22 10:33:44.123456"; $mut = new DateTime($time, "America/Chicago"); $subject = new DateTime($mut); $this->assertSame($time, $subject->format("Y-m-d H:i:s.u"), "time construction"); $mut = new Chronos($time, "America/Chicago"); $subject = new DateTime($mut); $this->assertSame($time, $subject->format("Y-m-d H:i:s.u"), "time construction"); $mut = new NativeDateTime($time, new DateTimeZone("America/Chicago")); $subject = new DateTime($mut); $this->assertSame($time, $subject->format("Y-m-d H:i:s.u"), "time construction"); } public static function timeAgoProvider() : array { return array(array("-12 seconds", "12 seconds ago"), array("-12 minutes", "12 minutes ago"), array("-2 hours", "2 hours ago"), array("-1 day", "1 day ago"), array("-2 days", "2 days ago"), array("-2 days -3 hours", "2 days, 3 hours ago"), array("-1 week", "1 week ago"), array("-2 weeks -2 days", "2 weeks, 2 days ago"), array("+1 week", "1 week"), array("+1 week 1 day", "1 week, 1 day"), array("+2 weeks 2 day", "2 weeks, 2 days"), array("2007-9-24", "on 9/24/07"), array("now", "just now")); } public function testTimeAgoInWords(string $input, string $expected) : void { $time = new DateTime($input); $result = $time->timeAgoInWords(); $this->assertEquals($expected, $result); } public static function timeAgoEndProvider() : array { return array(array("+4 months +2 weeks +3 days", "4 months, 2 weeks, 3 days", "8 years"), array("+4 months +2 weeks +1 day", "4 months, 2 weeks, 1 day", "8 years"), array("+3 months +2 weeks", "3 months, 2 weeks", "8 years"), array("+3 months +2 weeks +1 day", "3 months, 2 weeks, 1 day", "8 years"), array("+1 months +1 week +1 day", "1 month, 1 week, 1 day", "8 years"), array("+2 months +2 days", "2 months, 2 days", "+2 months +2 days"), array("+2 months +12 days", "2 months, 1 week, 5 days", "3 months")); } public function testTimeAgoInWordsTimezone() : void { $time = new DateTime("1990-07-31 20:33:00 UTC"); $result = $time->timeAgoInWords(array("timezone" => "America/Vancouver", "end" => "+1month", "format" => "dd-MM-YYYY HH:mm:ss")); $this->assertSame("on 31-07-1990 13:33:00", $result); } public function testTimeAgoInWordsEnd(string $input, string $expected, string $end) : void { $time = new DateTime($input); $result = $time->timeAgoInWords(array("end" => $end)); $this->assertEquals($expected, $result); } public function testTimeAgoInWordsCustomStrings() : void { $time = new DateTime("-8 years -4 months -2 weeks -3 days"); $result = $time->timeAgoInWords(array("relativeString" => "at least %s ago", "accuracy" => array("year" => "year"), "end" => "+10 years")); $expected = "at least 8 years ago"; $this->assertSame($expected, $result); $time = new DateTime("+4 months +2 weeks +3 days"); $result = $time->timeAgoInWords(array("absoluteString" => "exactly on %s", "accuracy" => array("year" => "year"), "end" => "+2 months")); $expected = "exactly on " . date("n/j/y", strtotime("+4 months +2 weeks +3 days")); $this->assertSame($expected, $result); } public function testTimeAgoInWordsAccuracy() : void { $time = new DateTime("+8 years +4 months +2 weeks +3 days"); $result = $time->timeAgoInWords(array("accuracy" => array("year" => "year"), "end" => "+10 years")); $expected = "8 years"; $this->assertSame($expected, $result); $time = new DateTime("+8 years +4 months +2 weeks +3 days"); $result = $time->timeAgoInWords(array("accuracy" => array("year" => "month"), "end" => "+10 years")); $expected = "8 years, 4 months"; $this->assertSame($expected, $result); $time = new DateTime("+8 years +4 months +2 weeks +3 days"); $result = $time->timeAgoInWords(array("accuracy" => array("year" => "week"), "end" => "+10 years")); $expected = "8 years, 4 months, 2 weeks"; $this->assertSame($expected, $result); $time = new DateTime("+8 years +4 months +2 weeks +3 days"); $result = $time->timeAgoInWords(array("accuracy" => array("year" => "day"), "end" => "+10 years")); $expected = "8 years, 4 months, 2 weeks, 3 days"; $this->assertSame($expected, $result); $time = new DateTime("+1 years +5 weeks"); $result = $time->timeAgoInWords(array("accuracy" => array("year" => "year"), "end" => "+10 years")); $expected = "1 year"; $this->assertSame($expected, $result); $time = new DateTime("+58 minutes"); $result = $time->timeAgoInWords(array("accuracy" => "hour")); $expected = "in about an hour"; $this->assertSame($expected, $result); $time = new DateTime("+23 hours"); $result = $time->timeAgoInWords(array("accuracy" => "day")); $expected = "in about a day"; $this->assertSame($expected, $result); $time = new DateTime("+20 days"); $result = $time->timeAgoInWords(array("accuracy" => "month")); $this->assertSame("in about a month", $result); } public function testTimeAgoInWordsWithFormat() : void { $time = new DateTime("2007-9-25"); $result = $time->timeAgoInWords(array("format" => "yyyy-MM-dd")); $this->assertSame("on 2007-09-25", $result); $time = new DateTime("+2 weeks +2 days"); $result = $time->timeAgoInWords(array("format" => "yyyy-MM-dd")); $this->assertMatchesRegularExpression("/^2 weeks, [1|2] day(s)?$/", $result); $time = new DateTime("+2 months +2 days"); $result = $time->timeAgoInWords(array("end" => "1 month", "format" => "yyyy-MM-dd")); $this->assertSame("on " . date("Y-m-d", strtotime("+2 months +2 days")), $result); } public function testTimeAgoInWordsNegativeValues() : void { $time = new DateTime("-2 months -2 days"); $result = $time->timeAgoInWords(array("end" => "3 month")); $this->assertSame("2 months, 2 days ago", $result); $time = new DateTime("-2 months -2 days"); $result = $time->timeAgoInWords(array("end" => "3 month")); $this->assertSame("2 months, 2 days ago", $result); $time = new DateTime("-2 months -2 days"); $result = $time->timeAgoInWords(array("end" => "1 month", "format" => "yyyy-MM-dd")); $this->assertSame("on " . date("Y-m-d", strtotime("-2 months -2 days")), $result); $time = new DateTime("-2 years -5 months -2 days"); $result = $time->timeAgoInWords(array("end" => "3 years")); $this->assertSame("2 years, 5 months, 2 days ago", $result); $time = new DateTime("-2 weeks -2 days"); $result = $time->timeAgoInWords(array("format" => "yyyy-MM-dd")); $this->assertSame("2 weeks, 2 days ago", $result); $time = new DateTime("-3 years -12 months"); $result = $time->timeAgoInWords(); $expected = "on " . $time->format("n/j/y"); $this->assertSame($expected, $result); $time = new DateTime("-1 month -1 week -6 days"); $result = $time->timeAgoInWords(array("end" => "1 year", "accuracy" => array("month" => "month"))); $this->assertSame("1 month ago", $result); $time = new DateTime("-1 years -2 weeks -3 days"); $result = $time->timeAgoInWords(array("accuracy" => array("year" => "year"))); $expected = "on " . $time->format("n/j/y"); $this->assertSame($expected, $result); $time = new DateTime("-13 months -5 days"); $result = $time->timeAgoInWords(array("end" => "2 years")); $this->assertSame("1 year, 1 month, 5 days ago", $result); $time = new DateTime("-58 minutes"); $result = $time->timeAgoInWords(array("accuracy" => "hour")); $this->assertSame("about an hour ago", $result); $time = new DateTime("-23 hours"); $result = $time->timeAgoInWords(array("accuracy" => "day")); $this->assertSame("about a day ago", $result); $time = new DateTime("-20 days"); $result = $time->timeAgoInWords(array("accuracy" => "month")); $this->assertSame("about a month ago", $result); } public function testNice() : void { $time = new DateTime("2014-04-20 20:00", "UTC"); $result = preg_replace("/[\pZ\pC]/u", " ", $time->nice()); $this->assertTimeFormat("Apr 20, 2014, 8:00 PM", $result); $result = $time->nice("America/New_York"); $result = preg_replace("/[\pZ\pC]/u", " ", $result); $this->assertTimeFormat("Apr 20, 2014, 4:00 PM", $result); $this->assertSame("UTC", $time->getTimezone()->getName()); $this->assertTimeFormat("20 avr. 2014 20:00", $time->nice(null, "fr-FR")); $this->assertTimeFormat("20 avr. 2014 16:00", $time->nice("America/New_York", "fr-FR")); DateTime::setDefaultLocale("fr-FR"); $this->assertTimeFormat("20 avr. 2014 20:00", $time->nice()); } public function testI18nFormat() : void { $time = new DateTime("Thu Jan 14 13:59:28 2010"); $result = preg_replace("/[\pZ\pC]/u", " ", $time->i18nFormat()); $this->assertTimeFormat("1/14/10, 1:59 PM", $result); $result = $time->i18nFormat("HH:mm:ss", "Australia/Sydney"); $expected = "00:59:28"; $this->assertTimeFormat($expected, $result); $format = array(IntlDateFormatter::NONE, IntlDateFormatter::SHORT); $result = preg_replace("/[\pZ\pC]/u", " ", $time->i18nFormat($format)); $this->assertTimeFormat("1:59 PM", $result); $result = $time->i18nFormat(IntlDateFormatter::FULL, null, "es-ES"); $expected = "jueves, 14 de enero de 2010, 13:59:28 (GMT)"; $this->assertTimeFormat($expected, $result); DateTime::setDefaultLocale("fr-FR"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $expected = "jeudi 14 janvier 2010 13:59:28 UTC"; $this->assertTimeFormat($expected, $result); $result = $time->i18nFormat(IntlDateFormatter::FULL, "Asia/Tokyo", "ja-JP@calendar=japanese"); $expected = "22114 225928 "; $this->assertTimeFormat($expected, $result); $timeMillis = new DateTime("2014-07-06T13:09:01.523000+00:00"); $result = $timeMillis->i18nFormat("yyyy-MM-dd'T'HH':'mm':'ss.SSSxxx", null, "en-US"); $expected = "2014-07-06T13:09:01.523+00:00"; $this->assertSame($expected, $result); } public function testI18nFormatUsingSystemLocale() : void { $time = new DateTime(1556864870); I18n::setLocale("ar"); $this->assertSame("--", $time->i18nFormat("yyyy-MM-dd")); I18n::setLocale("en"); $this->assertSame("2019-05-03", $time->i18nFormat("yyyy-MM-dd")); } public function testI18nFormatWithOffsetTimezone() : void { $time = new DateTime("2014-01-01T00:00:00+00"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $result = preg_replace("/[\pZ\pC]/u", " ", $result); $expected = "Wednesday January 1 2014 12:00:00 AM GMT"; $this->assertTimeFormat($expected, $result); $time = new DateTime("2014-01-01T00:00:00+09"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $result = preg_replace("/[\pZ\pC]/u", " ", $result); $expected = "Wednesday January 1 2014 12:00:00 AM GMT+09:00"; $this->assertTimeFormat($expected, $result); $time = new DateTime("2014-01-01T00:00:00-01:30"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $result = preg_replace("/[\pZ\pC]/u", " ", $result); $expected = "Wednesday January 1 2014 12:00:00 AM GMT-01:30"; $this->assertTimeFormat($expected, $result); $time = new DateTime("2014-01-01T00:00Z"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $result = preg_replace("/[\pZ\pC]/u", " ", $result); $expected = "Wednesday January 1 2014 12:00:00 AM GMT"; $this->assertTimeFormat($expected, $result); } public function testListTimezones() : void { $return = DateTime::listTimezones(); $this->assertTrue(isset($return["Asia"]["Asia/Bangkok"])); $this->assertSame("Bangkok", $return["Asia"]["Asia/Bangkok"]); $this->assertTrue(isset($return["America"]["America/Argentina/Buenos_Aires"])); $this->assertSame("Argentina/Buenos_Aires", $return["America"]["America/Argentina/Buenos_Aires"]); $this->assertTrue(isset($return["UTC"]["UTC"])); $this->assertArrayNotHasKey("Cuba", $return); $this->assertArrayNotHasKey("US", $return); $return = DateTime::listTimezones("#^Asia/#"); $this->assertTrue(isset($return["Asia"]["Asia/Bangkok"])); $this->assertArrayNotHasKey("Pacific", $return); $return = DateTime::listTimezones(null, null, array("abbr" => true)); $this->assertTrue(isset($return["Asia"]["Asia/Jakarta"])); $this->assertSame("Jakarta - WIB", $return["Asia"]["Asia/Jakarta"]); $this->assertSame("Regina - CST", $return["America"]["America/Regina"]); $return = DateTime::listTimezones(null, null, array("abbr" => true, "before" => " (", "after" => ")")); $this->assertSame("Jayapura (WIT)", $return["Asia"]["Asia/Jayapura"]); $this->assertSame("Regina (CST)", $return["America"]["America/Regina"]); $return = DateTime::listTimezones("#^(America|Pacific)/#", null, false); $this->assertArrayHasKey("America/Argentina/Buenos_Aires", $return); $this->assertArrayHasKey("Pacific/Tahiti", $return); $return = DateTime::listTimezones(DateTimeZone::ASIA); $this->assertTrue(isset($return["Asia"]["Asia/Bangkok"])); $this->assertArrayNotHasKey("Pacific", $return); $return = DateTime::listTimezones(DateTimeZone::PER_COUNTRY, "US", false); $this->assertArrayHasKey("Pacific/Honolulu", $return); $this->assertArrayNotHasKey("Asia/Bangkok", $return); } public function testToString() : void { $time = new DateTime("2014-04-20 22:10"); DateTime::setDefaultLocale("fr-FR"); DateTime::setToStringFormat(IntlDateFormatter::FULL); $expected = "dimanche 20 avril 2014 22:10:00 UTC"; $this->assertTimeFormat($expected, (string) $time); } public static function invalidDataProvider() : array { return array(array(null), array('')); } public function testToStringInvalid($value) : void { $time = new DateTime($value); $this->assertIsString((string) $time); $this->assertNotEmpty((string) $time); } public function testToStringInvalidFrozen($value) : void { $time = new DateTime($value); $this->assertIsString((string) $time); $this->assertNotEmpty((string) $time); } public function testToStringInvalidZeros() : void { $this->skipIf(DS === "\", "All zeros are valid on windows."); $this->skipIf(PHP_INT_SIZE === 4, "IntlDateFormatter throws exceptions on 32-bit systems"); $time = new DateTime("0000-00-00"); $this->assertIsString((string) $time); $this->assertNotEmpty((string) $time); $time = new DateTime("0000-00-00 00:00:00"); $this->assertIsString((string) $time); $this->assertNotEmpty((string) $time); } public function testDiffForHumans() : void { $time = new DateTime("2014-04-20 10:10:10"); $other = new DateTime("2014-04-27 10:10:10"); $this->assertSame("1 week before", $time->diffForHumans($other)); $other = new DateTime("2014-04-21 09:10:10"); $this->assertSame("23 hours before", $time->diffForHumans($other)); $other = new DateTime("2014-04-13 09:10:10"); $this->assertSame("1 week after", $time->diffForHumans($other)); $other = new DateTime("2014-04-06 09:10:10"); $this->assertSame("2 weeks after", $time->diffForHumans($other)); $other = new DateTime("2014-04-21 10:10:10"); $this->assertSame("1 day before", $time->diffForHumans($other)); $other = new DateTime("2014-04-22 10:10:10"); $this->assertSame("2 days before", $time->diffForHumans($other)); $other = new DateTime("2014-04-20 10:11:10"); $this->assertSame("1 minute before", $time->diffForHumans($other)); $other = new DateTime("2014-04-20 10:12:10"); $this->assertSame("2 minutes before", $time->diffForHumans($other)); $other = new DateTime("2014-04-20 10:10:09"); $this->assertSame("1 second after", $time->diffForHumans($other)); $other = new DateTime("2014-04-20 10:10:08"); $this->assertSame("2 seconds after", $time->diffForHumans($other)); } public function testDiffForHumansAbsolute() : void { DateTime::setTestNow(new DateTime("2015-12-12 10:10:10")); $time = new DateTime("2014-04-20 10:10:10"); $this->assertSame("1 year", $time->diffForHumans(null, true)); $other = new DateTime("2014-04-27 10:10:10"); $this->assertSame("1 week", $time->diffForHumans($other, true)); $time = new DateTime("2016-04-20 10:10:10"); $this->assertSame("4 months", $time->diffForHumans(null, true)); } public function testDiffForHumansNow() : void { DateTime::setTestNow(new DateTime("2015-12-12 10:10:10")); $time = new DateTime("2014-04-20 10:10:10"); $this->assertSame("1 year ago", $time->diffForHumans()); $time = new DateTime("2016-04-20 10:10:10"); $this->assertSame("4 months from now", $time->diffForHumans()); } public function testJsonEncode() : void { if (version_compare(INTL_ICU_VERSION, "50.0", "<")) { $this->markTestSkipped("ICU 5x is needed"); } $time = new DateTime("2014-04-20 10:10:10"); $this->assertSame(""2014-04-20T10:10:10+00:00"", json_encode($time)); DateTime::setJsonEncodeFormat("yyyy-MM-dd HH:mm:ss"); $this->assertSame(""2014-04-20 10:10:10"", json_encode($time)); DateTime::setJsonEncodeFormat(DateTime::UNIX_TIMESTAMP_FORMAT); $this->assertSame("1397988610", json_encode($time)); } public function testJsonEncodeSideEffectFree() : void { if (version_compare(INTL_ICU_VERSION, "50.0", "<")) { $this->markTestSkipped("ICU 5x is needed"); } $date = new DateTime("2016-11-29 09:00:00"); $this->assertInstanceOf("DateTimeZone", $date->timezone); $result = json_encode($date); $this->assertSame(""2016-11-29T09:00:00+00:00"", $result); $this->assertInstanceOf("DateTimeZone", $date->getTimezone()); } public function testSetJsonEncodeFormat() : void { $time = new DateTime("2014-04-20 10:10:10"); DateTime::setJsonEncodeFormat(static function ($t) { return $t->format(DATE_ATOM); }); $this->assertSame(""2014-04-20T10:10:10+00:00"", json_encode($time)); DateTime::setJsonEncodeFormat("yyyy-MM-dd'T'HH':'mm':'ssZZZZZ"); $this->assertSame(""2014-04-20T10:10:10Z"", json_encode($time)); } public function testParseDateTime() : void { $time = DateTime::parseDateTime("01/01/1970 00:00am"); $this->assertNotNull($time); $this->assertSame("1970-01-01 00:00", $time->format("Y-m-d H:i")); $this->assertSame(date_default_timezone_get(), $time->tzName); $time = DateTime::parseDateTime("10/13/2013 12:54am"); $this->assertNotNull($time); $this->assertSame("2013-10-13 00:54", $time->format("Y-m-d H:i")); $this->assertSame(date_default_timezone_get(), $time->tzName); $time = DateTime::parseDateTime("10/13/2013 12:54am GMT+08:00"); $this->assertNotNull($time); $this->assertSame("2013-10-13 00:54", $time->format("Y-m-d H:i")); $this->assertSame(date_default_timezone_get(), $time->tzName); $time = DateTime::parseDateTime("10/13/2013 12:54:00am GMT+08:00", array(IntlDateFormatter::SHORT, IntlDateFormatter::FULL)); $this->assertNotNull($time); $this->assertSame("2013-10-12 16:54", $time->format("Y-m-d H:i")); $this->assertSame(date_default_timezone_get(), $time->tzName); $time = DateTime::parseDateTime("10/13/2013 12:54am", null, "Europe/London"); $this->assertNotNull($time); $this->assertSame("2013-10-13 00:54", $time->format("Y-m-d H:i")); $this->assertSame("Europe/London", $time->tzName); DateTime::setDefaultLocale("fr-FR"); $time = DateTime::parseDateTime("13 10, 2013 12:54"); $this->assertNotNull($time); $this->assertSame("2013-10-13 12:54", $time->format("Y-m-d H:i")); $time = DateTime::parseDateTime("13 foo 10 2013 12:54"); $this->assertNull($time); } public function testParseDate() : void { $time = DateTime::parseDate("10/13/2013 12:54am"); $this->assertNotNull($time); $this->assertSame("2013-10-13 00:00", $time->format("Y-m-d H:i")); $time = DateTime::parseDate("10/13/2013"); $this->assertNotNull($time); $this->assertSame("2013-10-13 00:00", $time->format("Y-m-d H:i")); DateTime::setDefaultLocale("fr-FR"); $time = DateTime::parseDate("13 10, 2013 12:54"); $this->assertNotNull($time); $this->assertSame("2013-10-13 00:00", $time->format("Y-m-d H:i")); $time = DateTime::parseDate("13 foo 10 2013 12:54"); $this->assertNull($time); $time = DateTime::parseDate("13 10, 2013", "dd M, y"); $this->assertNotNull($time); $this->assertSame("2013-10-13", $time->format("Y-m-d")); } public function testParseTime() : void { $time = DateTime::parseTime("12:54am"); $this->assertNotNull($time); $this->assertSame("00:54:00", $time->format("H:i:s")); DateTime::setDefaultLocale("fr-FR"); $time = DateTime::parseTime("23:54"); $this->assertNotNull($time); $this->assertSame("23:54:00", $time->format("H:i:s")); $time = DateTime::parseTime("31c2:54"); $this->assertNull($time); } public function testLenientParseDate() : void { DateTime::setDefaultLocale("pt_BR"); DateTime::disableLenientParsing(); $time = DateTime::parseDate("04/21/2013"); $this->assertSame(null, $time); DateTime::enableLenientParsing(); $time = DateTime::parseDate("04/21/2013"); $this->assertSame("2014-09-04", $time->format("Y-m-d")); } public function testRussianTimeAgoInWords() : void { I18n::setLocale("ru_RU"); $time = new DateTime("5 days ago"); $result = $time->timeAgoInWords(); $this->assertSame("5 days ago", $result); } public function testParseDateDifferentTimezone() : void { date_default_timezone_set("Europe/Paris"); DateTime::setDefaultLocale("fr-FR"); $result = DateTime::parseDate("12/03/2015"); $this->assertSame("2015-03-12", $result->format("Y-m-d")); $this->assertEquals(new DateTimeZone("Europe/Paris"), $result->tz); } public function testGetSetDefaultLocale() : void { DateTime::setDefaultLocale("fr-FR"); $this->assertSame("fr-FR", DateTime::getDefaultLocale()); } public function assertTimeFormat(string $expected, string $result, string $message = '') : void { $expected = str_replace(array(",", "(", ")", " at", " .", " ..", " AP", " AH", " SAKA", " "), '', $expected); $expected = str_replace(array(" "), " ", $expected); $result = str_replace("temps universel coordonn", "UTC", $result); $result = str_replace("Temps universel coordonn", "UTC", $result); $result = str_replace("tiempo universal coordinado", "GMT", $result); $result = str_replace("Coordinated Universal Time", "GMT", $result); $result = str_replace(array(",", "(", ")", " at", " .", " ..", " AP", " AH", " SAKA", " "), '', $result); $result = str_replace(array(" "), " ", $result); $this->assertSame($expected, $result, $message); } } ?>
Did this file decode correctly?
Original Code
<?php
namespace Cake\Test\TestCase\I18n; use Cake\Chronos\Chronos; use Cake\I18n\DateTime; use Cake\I18n\I18n; use Cake\TestSuite\TestCase; use DateTime as NativeDateTime; use DateTimeZone; use IntlDateFormatter; class DateTimeTest extends TestCase { protected $now; public function setUp() : void { parent::setUp(); $this->now = DateTime::getTestNow(); } public function tearDown() : void { parent::tearDown(); DateTime::setTestNow($this->now); DateTime::setDefaultLocale(null); DateTime::resetToStringFormat(); DateTime::setJsonEncodeFormat("\171\171\171\x79\x2d\115\x4d\55\x64\144\47\x54\x27\110\110\x27\x3a\x27\x6d\155\47\x3a\x27\x73\163\170\x78\170"); date_default_timezone_set("\x55\124\x43"); I18n::setLocale(I18n::getDefaultLocale()); } public function testConstructFromAnotherInstance() : void { $time = "\62\60\x31\65\x2d\x30\x31\55\62\x32\40\61\60\x3a\x33\63\72\x34\64\x2e\61\x32\x33\x34\x35\66"; $mut = new DateTime($time, "\x41\x6d\145\162\x69\143\141\57\103\x68\x69\143\141\147\157"); $subject = new DateTime($mut); $this->assertSame($time, $subject->format("\x59\x2d\x6d\x2d\144\x20\x48\x3a\x69\x3a\x73\56\x75"), "\164\151\155\145\x20\x63\157\x6e\163\x74\x72\165\x63\x74\151\157\x6e"); $mut = new Chronos($time, "\101\x6d\x65\162\x69\x63\141\57\x43\150\x69\x63\141\x67\x6f"); $subject = new DateTime($mut); $this->assertSame($time, $subject->format("\131\x2d\x6d\55\144\40\110\72\x69\x3a\163\56\x75"), "\x74\151\x6d\x65\x20\x63\157\x6e\x73\x74\162\165\x63\164\x69\157\156"); $mut = new NativeDateTime($time, new DateTimeZone("\101\x6d\x65\x72\x69\x63\x61\x2f\103\x68\x69\x63\x61\x67\157")); $subject = new DateTime($mut); $this->assertSame($time, $subject->format("\131\x2d\155\x2d\x64\40\x48\72\x69\72\163\x2e\x75"), "\164\x69\x6d\x65\x20\143\x6f\x6e\163\164\162\x75\143\x74\x69\x6f\x6e"); } public static function timeAgoProvider() : array { return array(array("\x2d\61\62\40\163\x65\x63\157\x6e\144\163", "\61\62\40\x73\145\143\157\x6e\x64\x73\x20\x61\147\157"), array("\55\x31\62\40\155\151\x6e\165\x74\145\x73", "\x31\x32\40\155\x69\156\x75\164\145\163\40\141\147\x6f"), array("\55\x32\x20\150\x6f\x75\x72\x73", "\62\x20\x68\x6f\165\x72\x73\x20\141\x67\x6f"), array("\55\61\x20\144\x61\171", "\x31\x20\144\141\171\40\141\x67\x6f"), array("\55\x32\x20\144\141\171\163", "\x32\40\144\141\171\x73\40\x61\x67\157"), array("\x2d\x32\40\144\141\x79\x73\40\55\63\40\150\157\165\162\163", "\x32\40\144\x61\171\x73\54\40\x33\40\x68\x6f\x75\x72\x73\40\x61\147\x6f"), array("\55\61\x20\167\x65\x65\x6b", "\61\x20\x77\x65\145\x6b\40\141\147\157"), array("\55\62\x20\x77\145\145\x6b\163\x20\x2d\x32\x20\144\x61\171\x73", "\62\x20\167\x65\x65\153\x73\54\40\x32\40\x64\141\171\x73\x20\x61\x67\x6f"), array("\53\x31\40\x77\x65\145\153", "\61\40\167\145\145\x6b"), array("\x2b\x31\40\167\x65\x65\x6b\40\61\40\144\141\171", "\x31\40\x77\145\145\x6b\x2c\x20\x31\40\144\141\171"), array("\53\x32\x20\167\x65\x65\153\163\40\x32\x20\x64\x61\x79", "\62\40\167\x65\x65\153\163\54\40\62\x20\144\141\171\x73"), array("\62\60\x30\x37\x2d\x39\55\62\64", "\x6f\156\40\x39\x2f\62\64\57\60\67"), array("\x6e\x6f\x77", "\x6a\x75\163\x74\x20\x6e\x6f\x77")); } public function testTimeAgoInWords(string $input, string $expected) : void { $time = new DateTime($input); $result = $time->timeAgoInWords(); $this->assertEquals($expected, $result); } public static function timeAgoEndProvider() : array { return array(array("\53\64\40\x6d\157\156\164\150\x73\x20\x2b\x32\40\x77\x65\145\153\x73\40\53\63\40\144\x61\x79\163", "\x34\40\155\157\x6e\x74\150\x73\x2c\40\x32\40\167\145\145\153\163\54\40\x33\40\x64\141\x79\x73", "\x38\40\171\145\141\162\x73"), array("\x2b\x34\x20\x6d\157\156\164\x68\163\40\53\x32\x20\167\x65\145\153\x73\x20\x2b\x31\40\x64\141\171", "\64\x20\x6d\157\156\164\x68\x73\54\x20\x32\x20\x77\x65\x65\x6b\163\54\x20\61\40\144\141\x79", "\x38\x20\x79\x65\x61\162\x73"), array("\53\63\x20\x6d\157\156\x74\150\x73\40\x2b\x32\40\167\145\x65\153\x73", "\63\40\155\x6f\x6e\164\150\x73\x2c\40\62\x20\x77\145\145\x6b\163", "\70\40\171\x65\141\162\163"), array("\x2b\x33\x20\155\157\x6e\x74\150\163\x20\x2b\62\x20\x77\x65\145\x6b\x73\40\53\61\40\144\141\171", "\x33\40\x6d\157\156\164\150\x73\x2c\40\62\40\x77\x65\x65\x6b\x73\54\x20\x31\x20\x64\141\171", "\x38\x20\171\145\141\162\x73"), array("\x2b\x31\40\x6d\157\156\x74\x68\x73\x20\x2b\61\x20\167\x65\145\153\x20\53\61\40\x64\141\171", "\x31\40\155\x6f\x6e\164\x68\54\x20\61\x20\x77\145\145\x6b\54\40\x31\x20\x64\x61\171", "\x38\40\x79\x65\141\x72\163"), array("\x2b\x32\x20\x6d\x6f\x6e\164\x68\163\x20\x2b\62\x20\144\x61\x79\x73", "\62\x20\x6d\157\x6e\x74\x68\163\54\40\x32\x20\x64\141\x79\163", "\x2b\62\x20\155\x6f\x6e\164\x68\x73\40\x2b\62\40\x64\141\x79\x73"), array("\x2b\62\x20\155\x6f\x6e\164\150\x73\40\x2b\x31\x32\x20\144\141\171\x73", "\x32\40\155\157\156\164\x68\163\54\40\x31\40\167\145\145\153\54\x20\65\x20\144\141\171\163", "\x33\40\x6d\x6f\x6e\164\150\x73")); } public function testTimeAgoInWordsTimezone() : void { $time = new DateTime("\x31\71\x39\60\x2d\x30\x37\55\63\x31\40\62\x30\x3a\63\63\72\60\60\40\x55\x54\103"); $result = $time->timeAgoInWords(array("\164\151\155\145\x7a\x6f\156\145" => "\101\155\x65\162\151\x63\141\x2f\x56\141\x6e\x63\x6f\165\x76\145\162", "\x65\156\144" => "\53\x31\155\x6f\x6e\x74\x68", "\146\x6f\162\x6d\141\x74" => "\144\x64\55\x4d\x4d\x2d\131\x59\x59\131\x20\110\110\72\155\x6d\x3a\x73\163")); $this->assertSame("\157\156\40\x33\x31\x2d\x30\x37\x2d\61\71\71\x30\x20\x31\x33\x3a\x33\63\x3a\60\60", $result); } public function testTimeAgoInWordsEnd(string $input, string $expected, string $end) : void { $time = new DateTime($input); $result = $time->timeAgoInWords(array("\145\156\x64" => $end)); $this->assertEquals($expected, $result); } public function testTimeAgoInWordsCustomStrings() : void { $time = new DateTime("\55\70\40\x79\145\x61\162\x73\40\55\x34\x20\155\157\156\x74\x68\163\40\55\62\x20\167\145\x65\x6b\x73\40\x2d\63\x20\x64\x61\171\x73"); $result = $time->timeAgoInWords(array("\162\x65\154\x61\x74\151\x76\145\123\x74\x72\151\156\147" => "\141\x74\40\154\145\x61\163\164\40\45\163\40\x61\147\x6f", "\x61\x63\x63\165\x72\141\143\x79" => array("\171\145\x61\162" => "\171\145\x61\x72"), "\x65\156\x64" => "\53\x31\x30\40\171\x65\x61\162\x73")); $expected = "\x61\x74\x20\x6c\145\x61\x73\x74\x20\x38\x20\x79\x65\141\x72\x73\x20\141\147\157"; $this->assertSame($expected, $result); $time = new DateTime("\x2b\x34\40\155\x6f\156\164\x68\x73\40\53\x32\40\167\145\x65\153\163\x20\x2b\x33\x20\144\x61\x79\163"); $result = $time->timeAgoInWords(array("\x61\x62\x73\157\x6c\x75\x74\145\x53\164\x72\x69\x6e\147" => "\x65\x78\x61\x63\x74\x6c\x79\x20\x6f\156\x20\45\163", "\x61\143\x63\165\x72\141\143\171" => array("\171\x65\141\x72" => "\x79\145\141\162"), "\145\x6e\x64" => "\53\x32\x20\155\157\156\164\x68\x73")); $expected = "\145\x78\141\x63\164\x6c\x79\x20\x6f\156\40" . date("\156\57\152\x2f\171", strtotime("\53\x34\40\x6d\x6f\156\x74\x68\x73\40\x2b\x32\x20\167\145\x65\x6b\163\x20\53\63\x20\x64\141\171\x73")); $this->assertSame($expected, $result); } public function testTimeAgoInWordsAccuracy() : void { $time = new DateTime("\53\x38\x20\171\x65\x61\162\x73\40\x2b\x34\x20\155\x6f\156\x74\150\163\x20\53\x32\40\x77\145\145\153\163\40\x2b\63\x20\x64\x61\x79\x73"); $result = $time->timeAgoInWords(array("\141\143\143\x75\x72\141\x63\x79" => array("\171\145\141\162" => "\171\x65\141\x72"), "\x65\156\x64" => "\53\x31\x30\x20\171\145\141\162\163")); $expected = "\x38\40\171\145\141\x72\x73"; $this->assertSame($expected, $result); $time = new DateTime("\x2b\x38\40\171\145\x61\162\163\x20\53\x34\40\x6d\x6f\x6e\164\150\163\40\53\62\x20\167\145\145\153\163\40\x2b\x33\40\x64\x61\x79\x73"); $result = $time->timeAgoInWords(array("\x61\x63\143\x75\162\x61\x63\171" => array("\x79\x65\x61\x72" => "\155\x6f\156\164\x68"), "\145\x6e\144" => "\53\61\x30\40\x79\x65\141\x72\163")); $expected = "\x38\x20\x79\x65\x61\x72\163\54\40\64\x20\x6d\x6f\156\x74\x68\163"; $this->assertSame($expected, $result); $time = new DateTime("\53\x38\x20\171\145\141\x72\163\40\53\x34\x20\x6d\157\156\x74\150\163\40\53\x32\x20\167\x65\x65\x6b\163\40\53\63\40\x64\141\x79\163"); $result = $time->timeAgoInWords(array("\141\143\x63\x75\162\141\143\171" => array("\x79\145\141\x72" => "\x77\145\145\153"), "\145\x6e\x64" => "\53\x31\x30\40\x79\145\141\162\x73")); $expected = "\70\40\171\145\x61\162\163\54\x20\64\x20\x6d\157\156\x74\x68\x73\54\40\62\x20\x77\x65\x65\x6b\163"; $this->assertSame($expected, $result); $time = new DateTime("\x2b\x38\x20\171\145\141\x72\163\x20\x2b\x34\40\155\x6f\156\164\150\x73\40\53\62\x20\x77\145\145\x6b\x73\x20\53\x33\x20\144\141\x79\x73"); $result = $time->timeAgoInWords(array("\x61\x63\143\x75\x72\141\143\x79" => array("\x79\145\x61\x72" => "\144\x61\171"), "\x65\156\x64" => "\53\61\60\x20\x79\145\x61\162\163")); $expected = "\70\40\171\x65\x61\162\163\54\40\x34\40\x6d\x6f\156\164\150\163\x2c\40\x32\40\167\145\145\x6b\x73\54\40\x33\40\144\x61\x79\163"; $this->assertSame($expected, $result); $time = new DateTime("\x2b\x31\40\x79\x65\141\162\x73\x20\x2b\x35\x20\x77\145\x65\153\163"); $result = $time->timeAgoInWords(array("\x61\x63\x63\x75\x72\x61\143\x79" => array("\x79\x65\141\162" => "\x79\145\x61\x72"), "\x65\156\144" => "\x2b\61\60\40\x79\145\141\x72\163")); $expected = "\x31\40\171\x65\141\162"; $this->assertSame($expected, $result); $time = new DateTime("\53\x35\x38\x20\x6d\x69\x6e\165\164\x65\163"); $result = $time->timeAgoInWords(array("\x61\x63\x63\165\162\141\143\x79" => "\150\157\165\162")); $expected = "\x69\x6e\x20\x61\142\x6f\x75\164\x20\141\x6e\x20\150\x6f\x75\x72"; $this->assertSame($expected, $result); $time = new DateTime("\53\62\x33\x20\x68\157\165\162\x73"); $result = $time->timeAgoInWords(array("\x61\143\x63\x75\x72\x61\x63\x79" => "\x64\x61\171")); $expected = "\x69\x6e\40\141\x62\157\x75\164\x20\141\40\x64\141\171"; $this->assertSame($expected, $result); $time = new DateTime("\x2b\62\x30\40\x64\141\x79\x73"); $result = $time->timeAgoInWords(array("\x61\x63\x63\165\162\141\x63\x79" => "\x6d\x6f\156\x74\150")); $this->assertSame("\151\x6e\40\141\x62\x6f\x75\x74\x20\141\40\x6d\x6f\x6e\164\x68", $result); } public function testTimeAgoInWordsWithFormat() : void { $time = new DateTime("\62\x30\60\67\x2d\71\55\62\65"); $result = $time->timeAgoInWords(array("\146\157\162\155\x61\x74" => "\x79\171\x79\171\55\x4d\115\55\144\144")); $this->assertSame("\x6f\x6e\x20\x32\60\60\67\55\60\71\x2d\x32\65", $result); $time = new DateTime("\x2b\62\40\x77\x65\x65\x6b\163\40\x2b\x32\40\x64\x61\171\163"); $result = $time->timeAgoInWords(array("\146\157\162\155\x61\x74" => "\x79\x79\171\x79\55\115\x4d\x2d\x64\x64")); $this->assertMatchesRegularExpression("\57\136\62\40\167\x65\145\x6b\x73\x2c\40\133\61\x7c\x32\135\x20\144\x61\x79\x28\163\x29\77\x24\x2f", $result); $time = new DateTime("\53\x32\x20\x6d\157\156\x74\150\x73\x20\53\62\40\144\141\x79\x73"); $result = $time->timeAgoInWords(array("\145\x6e\144" => "\x31\x20\x6d\157\156\164\x68", "\146\157\162\155\141\164" => "\171\x79\x79\171\x2d\x4d\115\x2d\144\144")); $this->assertSame("\x6f\156\x20" . date("\x59\x2d\155\x2d\144", strtotime("\53\62\x20\x6d\157\x6e\x74\x68\163\x20\53\62\x20\144\x61\x79\x73")), $result); } public function testTimeAgoInWordsNegativeValues() : void { $time = new DateTime("\55\62\40\155\157\156\164\x68\163\40\55\62\40\x64\141\x79\163"); $result = $time->timeAgoInWords(array("\145\x6e\144" => "\63\40\x6d\157\156\x74\150")); $this->assertSame("\62\40\x6d\157\x6e\164\x68\x73\x2c\x20\x32\40\x64\141\x79\x73\x20\x61\x67\157", $result); $time = new DateTime("\55\x32\40\155\x6f\x6e\164\x68\163\x20\55\x32\40\144\x61\171\x73"); $result = $time->timeAgoInWords(array("\x65\156\144" => "\x33\x20\155\157\x6e\x74\150")); $this->assertSame("\62\x20\x6d\157\156\x74\150\163\54\x20\62\40\144\141\x79\x73\x20\141\147\x6f", $result); $time = new DateTime("\x2d\x32\40\155\157\156\164\150\x73\40\55\62\x20\x64\x61\x79\163"); $result = $time->timeAgoInWords(array("\145\156\144" => "\61\40\x6d\157\156\164\x68", "\x66\x6f\162\x6d\x61\x74" => "\x79\x79\x79\x79\55\x4d\115\x2d\144\x64")); $this->assertSame("\157\156\x20" . date("\131\55\x6d\x2d\144", strtotime("\x2d\x32\40\x6d\x6f\x6e\x74\x68\163\x20\x2d\x32\x20\144\141\171\163")), $result); $time = new DateTime("\55\62\x20\171\145\x61\162\163\40\x2d\x35\x20\155\x6f\156\x74\x68\163\40\55\x32\x20\144\141\x79\163"); $result = $time->timeAgoInWords(array("\145\156\x64" => "\63\40\x79\145\141\162\163")); $this->assertSame("\x32\x20\171\145\141\x72\x73\x2c\40\x35\x20\x6d\x6f\156\164\x68\163\x2c\40\62\40\x64\141\x79\163\x20\x61\x67\157", $result); $time = new DateTime("\x2d\x32\x20\167\145\x65\x6b\163\40\55\62\x20\x64\141\171\163"); $result = $time->timeAgoInWords(array("\x66\x6f\162\155\x61\x74" => "\171\x79\x79\x79\x2d\115\115\x2d\144\144")); $this->assertSame("\62\x20\x77\145\x65\153\x73\54\x20\62\x20\144\x61\171\x73\x20\141\x67\x6f", $result); $time = new DateTime("\x2d\x33\x20\171\145\141\162\x73\x20\55\x31\x32\40\155\157\x6e\164\150\163"); $result = $time->timeAgoInWords(); $expected = "\157\156\40" . $time->format("\x6e\x2f\x6a\x2f\171"); $this->assertSame($expected, $result); $time = new DateTime("\x2d\61\40\155\157\156\164\150\x20\x2d\x31\40\x77\145\145\x6b\40\55\66\x20\x64\x61\x79\x73"); $result = $time->timeAgoInWords(array("\x65\x6e\x64" => "\x31\x20\x79\145\141\x72", "\141\x63\143\165\162\141\143\171" => array("\155\157\156\164\150" => "\155\x6f\x6e\164\150"))); $this->assertSame("\x31\40\155\157\156\x74\x68\40\141\x67\157", $result); $time = new DateTime("\x2d\x31\40\171\145\141\162\x73\40\55\62\x20\x77\145\x65\153\163\x20\x2d\63\x20\x64\141\171\163"); $result = $time->timeAgoInWords(array("\141\143\x63\x75\x72\141\x63\x79" => array("\x79\145\x61\x72" => "\171\145\141\x72"))); $expected = "\x6f\156\x20" . $time->format("\x6e\x2f\x6a\57\x79"); $this->assertSame($expected, $result); $time = new DateTime("\x2d\61\63\x20\155\157\x6e\164\150\163\40\x2d\x35\x20\144\x61\171\163"); $result = $time->timeAgoInWords(array("\145\156\x64" => "\62\x20\171\145\141\x72\163")); $this->assertSame("\x31\40\x79\145\x61\162\54\40\x31\40\155\x6f\x6e\x74\x68\x2c\40\65\40\144\141\171\x73\x20\141\x67\157", $result); $time = new DateTime("\x2d\x35\x38\x20\x6d\151\x6e\165\164\145\x73"); $result = $time->timeAgoInWords(array("\141\x63\x63\165\x72\x61\143\x79" => "\x68\x6f\165\x72")); $this->assertSame("\x61\x62\x6f\165\x74\x20\141\x6e\x20\x68\x6f\165\162\x20\141\x67\x6f", $result); $time = new DateTime("\x2d\x32\x33\40\150\x6f\165\x72\163"); $result = $time->timeAgoInWords(array("\x61\143\x63\x75\162\141\143\171" => "\144\x61\171")); $this->assertSame("\x61\142\x6f\165\x74\40\141\40\144\141\171\x20\x61\147\x6f", $result); $time = new DateTime("\55\62\x30\40\x64\x61\171\x73"); $result = $time->timeAgoInWords(array("\141\143\143\x75\162\141\143\171" => "\155\157\156\x74\x68")); $this->assertSame("\141\142\157\165\x74\40\141\40\155\x6f\156\x74\150\40\x61\147\x6f", $result); } public function testNice() : void { $time = new DateTime("\x32\x30\x31\x34\55\60\x34\x2d\62\x30\x20\62\60\x3a\60\60", "\125\x54\103"); $result = preg_replace("\57\133\134\160\132\x5c\160\x43\135\x2f\165", "\40", $time->nice()); $this->assertTimeFormat("\101\x70\162\40\62\60\x2c\40\x32\x30\x31\64\54\x20\x38\x3a\60\x30\x20\120\x4d", $result); $result = $time->nice("\x41\155\x65\162\x69\x63\141\57\116\145\x77\x5f\131\x6f\x72\153"); $result = preg_replace("\57\x5b\134\160\x5a\134\x70\x43\x5d\57\165", "\40", $result); $this->assertTimeFormat("\x41\160\x72\x20\62\x30\54\x20\62\60\61\64\54\40\x34\x3a\x30\x30\x20\120\115", $result); $this->assertSame("\125\x54\103", $time->getTimezone()->getName()); $this->assertTimeFormat("\x32\x30\40\141\166\x72\56\40\x32\60\x31\x34\x20\62\x30\72\60\60", $time->nice(null, "\146\x72\55\x46\122")); $this->assertTimeFormat("\62\60\40\x61\x76\x72\56\40\62\x30\x31\x34\40\61\x36\x3a\x30\x30", $time->nice("\101\x6d\x65\x72\x69\143\x61\57\x4e\x65\x77\x5f\131\157\x72\x6b", "\146\x72\x2d\106\122")); DateTime::setDefaultLocale("\x66\x72\x2d\106\122"); $this->assertTimeFormat("\x32\x30\x20\x61\x76\162\56\40\x32\x30\x31\64\x20\62\x30\x3a\60\60", $time->nice()); } public function testI18nFormat() : void { $time = new DateTime("\x54\x68\x75\x20\112\141\156\40\x31\x34\x20\61\x33\x3a\65\x39\72\x32\x38\x20\62\60\61\x30"); $result = preg_replace("\57\x5b\134\160\x5a\x5c\160\x43\135\x2f\x75", "\40", $time->i18nFormat()); $this->assertTimeFormat("\61\57\61\64\57\61\60\54\x20\x31\x3a\65\x39\x20\120\115", $result); $result = $time->i18nFormat("\110\x48\72\155\x6d\x3a\163\x73", "\x41\x75\163\164\162\141\154\x69\x61\x2f\x53\x79\x64\x6e\145\x79"); $expected = "\60\60\72\x35\x39\x3a\x32\x38"; $this->assertTimeFormat($expected, $result); $format = array(IntlDateFormatter::NONE, IntlDateFormatter::SHORT); $result = preg_replace("\x2f\x5b\x5c\x70\x5a\134\x70\x43\135\x2f\x75", "\40", $time->i18nFormat($format)); $this->assertTimeFormat("\x31\x3a\x35\71\40\120\115", $result); $result = $time->i18nFormat(IntlDateFormatter::FULL, null, "\145\163\x2d\105\x53"); $expected = "\152\x75\145\x76\145\163\x2c\x20\x31\x34\40\144\x65\40\145\156\145\162\x6f\x20\144\145\40\x32\x30\61\x30\x2c\x20\x31\63\x3a\65\x39\72\62\x38\x20\x28\107\115\x54\51"; $this->assertTimeFormat($expected, $result); DateTime::setDefaultLocale("\x66\x72\55\106\x52"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $expected = "\x6a\145\165\144\x69\x20\x31\x34\40\x6a\141\156\x76\x69\x65\162\40\x32\60\x31\60\x20\61\63\72\65\x39\72\62\70\x20\x55\124\x43"; $this->assertTimeFormat($expected, $result); $result = $time->i18nFormat(IntlDateFormatter::FULL, "\x41\163\151\141\x2f\x54\157\x6b\171\157", "\x6a\x61\55\x4a\x50\x40\143\x61\154\x65\156\x64\141\x72\x3d\x6a\141\x70\141\x6e\x65\x73\x65"); $expected = "\345\xb9\xb3\xe6\210\220\62\62\xe5\xb9\xb4\x31\xe6\234\x88\61\64\xe6\x97\245\346\x9c\250\xe6\233\x9c\xe6\x97\245\40\x32\x32\xe6\231\x82\65\x39\xe5\210\x86\62\70\347\247\222\40\346\x97\xa5\346\x9c\254\346\250\x99\xe6\xba\x96\xe6\231\x82"; $this->assertTimeFormat($expected, $result); $timeMillis = new DateTime("\62\x30\x31\x34\55\x30\67\55\x30\x36\x54\x31\63\72\x30\71\x3a\x30\61\x2e\65\x32\63\60\60\x30\x2b\60\x30\72\60\x30"); $result = $timeMillis->i18nFormat("\171\x79\x79\171\55\115\x4d\x2d\x64\144\x27\124\x27\110\110\47\72\47\x6d\155\47\72\47\x73\163\x2e\123\123\x53\170\x78\x78", null, "\145\x6e\55\125\123"); $expected = "\x32\x30\61\64\x2d\x30\67\55\x30\66\124\x31\x33\x3a\60\x39\x3a\60\x31\x2e\x35\62\63\x2b\x30\60\72\x30\60"; $this->assertSame($expected, $result); } public function testI18nFormatUsingSystemLocale() : void { $time = new DateTime(1556864870); I18n::setLocale("\141\x72"); $this->assertSame("\331\242\xd9\240\xd9\241\xd9\xa9\x2d\331\240\xd9\245\x2d\331\240\xd9\xa3", $time->i18nFormat("\x79\x79\171\x79\55\x4d\x4d\55\x64\x64")); I18n::setLocale("\145\x6e"); $this->assertSame("\x32\60\61\71\x2d\60\65\x2d\60\63", $time->i18nFormat("\x79\171\x79\171\x2d\x4d\x4d\55\144\x64")); } public function testI18nFormatWithOffsetTimezone() : void { $time = new DateTime("\x32\60\x31\x34\x2d\60\61\x2d\60\x31\124\60\60\72\x30\60\72\x30\x30\53\x30\x30"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $result = preg_replace("\57\x5b\x5c\x70\132\x5c\x70\103\x5d\57\x75", "\40", $result); $expected = "\127\x65\144\156\x65\x73\144\141\171\x20\x4a\141\156\x75\141\x72\x79\40\61\x20\62\x30\x31\x34\40\61\x32\x3a\x30\60\72\x30\60\40\x41\x4d\x20\107\x4d\124"; $this->assertTimeFormat($expected, $result); $time = new DateTime("\62\60\61\x34\x2d\60\x31\55\x30\61\124\x30\60\72\x30\60\72\x30\x30\53\x30\x39"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $result = preg_replace("\x2f\x5b\134\160\132\x5c\x70\x43\135\57\165", "\40", $result); $expected = "\x57\145\x64\156\145\163\144\x61\171\40\x4a\141\x6e\165\141\x72\171\40\x31\40\62\x30\61\64\x20\x31\62\72\x30\x30\x3a\60\60\40\101\x4d\40\107\x4d\124\53\x30\71\x3a\x30\60"; $this->assertTimeFormat($expected, $result); $time = new DateTime("\62\x30\61\64\x2d\60\x31\55\60\x31\124\x30\x30\72\60\x30\x3a\60\x30\x2d\x30\x31\x3a\63\x30"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $result = preg_replace("\x2f\133\x5c\x70\x5a\x5c\x70\x43\x5d\x2f\x75", "\x20", $result); $expected = "\x57\145\x64\156\x65\163\144\x61\171\x20\112\141\156\x75\141\x72\171\x20\x31\40\x32\x30\61\x34\40\x31\x32\72\x30\60\72\60\x30\40\101\115\40\x47\x4d\x54\x2d\x30\x31\72\x33\x30"; $this->assertTimeFormat($expected, $result); $time = new DateTime("\62\x30\61\64\x2d\60\x31\55\60\61\x54\60\60\72\60\60\132"); $result = $time->i18nFormat(IntlDateFormatter::FULL); $result = preg_replace("\57\x5b\x5c\x70\132\x5c\x70\x43\135\57\x75", "\40", $result); $expected = "\127\145\x64\156\145\x73\x64\141\x79\x20\112\x61\156\165\141\x72\171\x20\x31\x20\62\60\x31\64\x20\x31\x32\x3a\x30\x30\x3a\60\x30\40\101\115\40\x47\115\124"; $this->assertTimeFormat($expected, $result); } public function testListTimezones() : void { $return = DateTime::listTimezones(); $this->assertTrue(isset($return["\101\x73\x69\x61"]["\101\x73\x69\x61\57\x42\x61\156\x67\x6b\x6f\153"])); $this->assertSame("\102\x61\x6e\x67\x6b\x6f\x6b", $return["\101\x73\x69\141"]["\101\163\x69\141\x2f\102\141\x6e\147\x6b\x6f\153"]); $this->assertTrue(isset($return["\101\155\x65\162\x69\143\x61"]["\x41\155\145\x72\151\x63\x61\x2f\101\162\147\145\x6e\164\x69\x6e\x61\x2f\x42\x75\x65\156\x6f\163\137\101\151\x72\x65\x73"])); $this->assertSame("\x41\162\147\145\x6e\164\151\x6e\x61\57\102\165\145\156\157\163\x5f\x41\151\x72\x65\x73", $return["\101\155\x65\x72\x69\143\141"]["\101\155\145\162\x69\143\x61\x2f\101\x72\147\x65\156\x74\151\156\141\x2f\102\x75\x65\156\x6f\x73\x5f\x41\151\162\145\x73"]); $this->assertTrue(isset($return["\125\x54\103"]["\x55\x54\x43"])); $this->assertArrayNotHasKey("\x43\165\142\x61", $return); $this->assertArrayNotHasKey("\125\x53", $return); $return = DateTime::listTimezones("\43\136\x41\163\x69\x61\57\43"); $this->assertTrue(isset($return["\101\163\151\141"]["\101\x73\151\141\x2f\102\x61\x6e\147\x6b\157\x6b"])); $this->assertArrayNotHasKey("\120\141\x63\x69\x66\151\x63", $return); $return = DateTime::listTimezones(null, null, array("\141\142\x62\x72" => true)); $this->assertTrue(isset($return["\x41\x73\x69\x61"]["\101\x73\x69\x61\x2f\112\141\x6b\141\x72\164\141"])); $this->assertSame("\x4a\141\x6b\x61\x72\164\141\40\x2d\40\x57\111\x42", $return["\101\163\x69\x61"]["\x41\x73\x69\x61\57\x4a\141\153\x61\162\164\x61"]); $this->assertSame("\122\145\147\x69\156\141\x20\55\40\x43\123\x54", $return["\x41\155\145\x72\151\x63\141"]["\101\x6d\145\162\x69\143\141\57\122\x65\147\x69\x6e\x61"]); $return = DateTime::listTimezones(null, null, array("\141\142\x62\162" => true, "\142\145\x66\x6f\162\145" => "\x20\50", "\141\146\x74\x65\162" => "\51")); $this->assertSame("\x4a\141\171\141\160\x75\x72\141\40\x28\127\x49\x54\51", $return["\x41\x73\x69\x61"]["\x41\163\x69\x61\57\x4a\141\x79\141\x70\x75\x72\141"]); $this->assertSame("\122\145\x67\x69\x6e\141\x20\50\x43\123\124\x29", $return["\x41\x6d\x65\x72\x69\143\x61"]["\x41\x6d\x65\x72\x69\x63\x61\x2f\122\145\147\151\x6e\x61"]); $return = DateTime::listTimezones("\x23\136\50\x41\x6d\x65\x72\x69\143\141\174\120\x61\x63\x69\x66\151\143\x29\57\x23", null, false); $this->assertArrayHasKey("\x41\155\x65\x72\151\x63\x61\x2f\x41\x72\147\x65\156\164\151\156\141\x2f\102\165\145\156\157\x73\137\x41\151\x72\x65\x73", $return); $this->assertArrayHasKey("\120\x61\x63\x69\146\x69\x63\x2f\x54\141\x68\151\x74\151", $return); $return = DateTime::listTimezones(DateTimeZone::ASIA); $this->assertTrue(isset($return["\101\163\x69\x61"]["\101\163\x69\x61\x2f\102\141\156\147\153\x6f\x6b"])); $this->assertArrayNotHasKey("\120\x61\x63\151\x66\x69\x63", $return); $return = DateTime::listTimezones(DateTimeZone::PER_COUNTRY, "\x55\x53", false); $this->assertArrayHasKey("\120\x61\x63\151\x66\x69\143\57\x48\157\x6e\157\x6c\x75\x6c\165", $return); $this->assertArrayNotHasKey("\101\163\151\x61\57\x42\x61\156\147\153\157\x6b", $return); } public function testToString() : void { $time = new DateTime("\x32\x30\61\x34\55\60\x34\55\x32\60\x20\x32\x32\72\61\60"); DateTime::setDefaultLocale("\146\162\55\106\x52"); DateTime::setToStringFormat(IntlDateFormatter::FULL); $expected = "\x64\151\x6d\x61\x6e\143\150\145\x20\62\60\x20\141\x76\162\151\154\40\x32\60\61\x34\40\62\x32\x3a\x31\x30\72\60\60\40\x55\x54\103"; $this->assertTimeFormat($expected, (string) $time); } public static function invalidDataProvider() : array { return array(array(null), array('')); } public function testToStringInvalid($value) : void { $time = new DateTime($value); $this->assertIsString((string) $time); $this->assertNotEmpty((string) $time); } public function testToStringInvalidFrozen($value) : void { $time = new DateTime($value); $this->assertIsString((string) $time); $this->assertNotEmpty((string) $time); } public function testToStringInvalidZeros() : void { $this->skipIf(DS === "\x5c", "\x41\x6c\154\40\x7a\145\162\x6f\163\40\141\x72\x65\x20\x76\141\x6c\x69\144\x20\157\x6e\40\x77\151\x6e\144\157\167\163\x2e"); $this->skipIf(PHP_INT_SIZE === 4, "\111\x6e\164\154\104\141\164\x65\106\157\162\x6d\x61\x74\164\x65\x72\x20\x74\150\162\x6f\167\163\x20\x65\170\x63\145\160\164\151\x6f\156\x73\40\157\156\x20\x33\62\55\x62\x69\x74\40\163\x79\x73\x74\145\155\x73"); $time = new DateTime("\60\60\60\60\55\60\x30\x2d\60\x30"); $this->assertIsString((string) $time); $this->assertNotEmpty((string) $time); $time = new DateTime("\x30\x30\60\x30\55\60\60\55\60\60\40\x30\60\72\60\x30\x3a\x30\60"); $this->assertIsString((string) $time); $this->assertNotEmpty((string) $time); } public function testDiffForHumans() : void { $time = new DateTime("\x32\x30\61\x34\55\60\64\x2d\62\60\x20\x31\60\72\x31\60\x3a\61\60"); $other = new DateTime("\62\x30\x31\x34\x2d\60\x34\x2d\x32\67\x20\61\x30\x3a\61\x30\72\61\x30"); $this->assertSame("\61\40\x77\x65\x65\x6b\x20\x62\x65\146\x6f\x72\x65", $time->diffForHumans($other)); $other = new DateTime("\x32\x30\61\64\55\x30\x34\x2d\62\x31\40\x30\71\x3a\x31\60\x3a\x31\60"); $this->assertSame("\62\63\x20\x68\x6f\165\x72\163\x20\142\x65\x66\x6f\162\145", $time->diffForHumans($other)); $other = new DateTime("\x32\60\x31\x34\x2d\60\x34\55\x31\x33\x20\x30\x39\72\x31\60\72\x31\60"); $this->assertSame("\61\40\x77\145\145\x6b\40\141\146\x74\x65\x72", $time->diffForHumans($other)); $other = new DateTime("\x32\x30\x31\64\55\x30\x34\55\x30\66\x20\60\x39\72\x31\x30\72\x31\60"); $this->assertSame("\x32\x20\167\145\x65\x6b\163\x20\x61\x66\164\x65\x72", $time->diffForHumans($other)); $other = new DateTime("\62\x30\61\x34\x2d\x30\64\x2d\62\61\x20\x31\60\x3a\61\x30\72\61\x30"); $this->assertSame("\61\x20\x64\x61\x79\40\x62\145\x66\157\162\x65", $time->diffForHumans($other)); $other = new DateTime("\62\x30\61\x34\x2d\x30\64\x2d\62\62\40\x31\60\x3a\x31\x30\72\61\60"); $this->assertSame("\62\x20\144\141\171\163\x20\142\145\x66\x6f\x72\145", $time->diffForHumans($other)); $other = new DateTime("\62\60\61\x34\55\x30\64\x2d\x32\x30\x20\61\60\72\x31\61\x3a\61\x30"); $this->assertSame("\61\40\x6d\151\156\165\x74\145\x20\142\145\x66\x6f\162\x65", $time->diffForHumans($other)); $other = new DateTime("\x32\60\x31\64\55\60\x34\55\62\x30\40\x31\x30\72\61\62\72\61\60"); $this->assertSame("\x32\40\x6d\151\156\x75\x74\x65\x73\40\142\145\x66\157\162\x65", $time->diffForHumans($other)); $other = new DateTime("\62\x30\x31\64\55\x30\x34\55\x32\x30\x20\61\60\72\61\x30\x3a\60\x39"); $this->assertSame("\x31\x20\163\145\x63\x6f\156\x64\40\141\x66\164\x65\162", $time->diffForHumans($other)); $other = new DateTime("\62\x30\61\x34\x2d\x30\x34\55\x32\60\40\x31\60\72\x31\x30\72\x30\x38"); $this->assertSame("\62\x20\x73\x65\x63\157\156\144\163\x20\141\x66\164\x65\x72", $time->diffForHumans($other)); } public function testDiffForHumansAbsolute() : void { DateTime::setTestNow(new DateTime("\62\x30\x31\x35\x2d\x31\x32\55\61\x32\40\61\60\x3a\61\x30\x3a\61\x30")); $time = new DateTime("\x32\60\x31\x34\55\60\64\x2d\x32\60\40\x31\x30\x3a\x31\60\x3a\61\x30"); $this->assertSame("\61\40\171\x65\141\x72", $time->diffForHumans(null, true)); $other = new DateTime("\62\x30\x31\64\55\60\x34\x2d\x32\67\x20\x31\60\x3a\61\60\x3a\x31\x30"); $this->assertSame("\x31\x20\x77\x65\x65\x6b", $time->diffForHumans($other, true)); $time = new DateTime("\62\60\x31\66\55\x30\x34\55\x32\x30\40\x31\60\72\x31\x30\72\x31\60"); $this->assertSame("\x34\x20\x6d\157\156\x74\150\x73", $time->diffForHumans(null, true)); } public function testDiffForHumansNow() : void { DateTime::setTestNow(new DateTime("\x32\60\x31\65\x2d\x31\62\x2d\x31\62\x20\x31\x30\72\x31\60\x3a\61\x30")); $time = new DateTime("\62\x30\61\x34\x2d\x30\x34\x2d\x32\x30\40\x31\60\72\x31\x30\72\x31\60"); $this->assertSame("\61\40\171\145\141\162\40\141\147\x6f", $time->diffForHumans()); $time = new DateTime("\62\60\61\x36\x2d\60\x34\x2d\62\x30\40\61\x30\x3a\x31\x30\x3a\x31\x30"); $this->assertSame("\x34\40\x6d\157\x6e\164\150\x73\x20\146\162\x6f\x6d\x20\x6e\157\x77", $time->diffForHumans()); } public function testJsonEncode() : void { if (version_compare(INTL_ICU_VERSION, "\x35\x30\x2e\60", "\74")) { $this->markTestSkipped("\x49\103\125\x20\65\x78\40\x69\163\40\x6e\x65\x65\144\145\144"); } $time = new DateTime("\62\x30\61\x34\x2d\60\64\55\x32\60\40\61\x30\72\x31\x30\x3a\61\60"); $this->assertSame("\x22\x32\60\x31\64\x2d\60\x34\x2d\62\60\124\61\60\x3a\x31\60\72\61\60\x2b\60\x30\x3a\60\x30\42", json_encode($time)); DateTime::setJsonEncodeFormat("\x79\171\x79\171\x2d\x4d\x4d\x2d\x64\144\x20\x48\110\x3a\x6d\x6d\x3a\163\x73"); $this->assertSame("\x22\x32\x30\61\64\55\x30\64\55\62\x30\40\61\x30\72\x31\60\x3a\x31\x30\x22", json_encode($time)); DateTime::setJsonEncodeFormat(DateTime::UNIX_TIMESTAMP_FORMAT); $this->assertSame("\x31\63\x39\67\71\x38\70\x36\x31\60", json_encode($time)); } public function testJsonEncodeSideEffectFree() : void { if (version_compare(INTL_ICU_VERSION, "\65\x30\x2e\x30", "\x3c")) { $this->markTestSkipped("\111\103\x55\40\x35\x78\x20\x69\x73\40\156\x65\x65\x64\145\144"); } $date = new DateTime("\x32\60\x31\x36\55\61\61\55\x32\x39\x20\60\71\x3a\x30\60\72\60\x30"); $this->assertInstanceOf("\x44\141\x74\145\x54\x69\155\x65\132\x6f\156\145", $date->timezone); $result = json_encode($date); $this->assertSame("\42\62\x30\x31\x36\x2d\x31\x31\55\62\71\124\x30\x39\72\60\x30\72\60\x30\x2b\60\x30\x3a\60\x30\x22", $result); $this->assertInstanceOf("\104\141\x74\145\x54\151\155\x65\132\157\156\x65", $date->getTimezone()); } public function testSetJsonEncodeFormat() : void { $time = new DateTime("\62\x30\x31\64\55\x30\64\x2d\62\x30\40\x31\60\72\x31\60\x3a\61\x30"); DateTime::setJsonEncodeFormat(static function ($t) { return $t->format(DATE_ATOM); }); $this->assertSame("\x22\62\x30\x31\64\x2d\x30\64\x2d\x32\x30\124\x31\60\x3a\x31\60\x3a\x31\x30\53\60\60\x3a\x30\x30\42", json_encode($time)); DateTime::setJsonEncodeFormat("\x79\x79\x79\x79\x2d\x4d\x4d\55\144\144\47\x54\47\x48\x48\x27\x3a\x27\x6d\x6d\x27\x3a\x27\x73\163\132\132\132\132\x5a"); $this->assertSame("\42\62\x30\x31\64\55\60\x34\x2d\x32\x30\x54\61\60\72\x31\60\72\x31\x30\132\42", json_encode($time)); } public function testParseDateTime() : void { $time = DateTime::parseDateTime("\x30\61\57\x30\x31\57\61\71\67\60\x20\x30\x30\72\x30\60\x61\155"); $this->assertNotNull($time); $this->assertSame("\x31\x39\67\x30\x2d\x30\61\x2d\60\61\40\x30\60\72\x30\60", $time->format("\131\55\x6d\x2d\144\x20\x48\x3a\x69")); $this->assertSame(date_default_timezone_get(), $time->tzName); $time = DateTime::parseDateTime("\x31\x30\x2f\61\63\x2f\x32\x30\x31\x33\40\61\x32\72\x35\64\x61\155"); $this->assertNotNull($time); $this->assertSame("\62\60\61\63\x2d\x31\60\55\x31\63\x20\60\60\x3a\65\x34", $time->format("\131\55\x6d\x2d\x64\x20\x48\72\x69")); $this->assertSame(date_default_timezone_get(), $time->tzName); $time = DateTime::parseDateTime("\x31\x30\57\61\63\57\62\60\61\x33\x20\61\x32\72\x35\x34\141\155\x20\107\x4d\124\x2b\x30\70\72\x30\60"); $this->assertNotNull($time); $this->assertSame("\62\x30\61\63\55\61\x30\55\61\63\40\x30\60\x3a\x35\64", $time->format("\x59\x2d\155\x2d\x64\40\110\72\x69")); $this->assertSame(date_default_timezone_get(), $time->tzName); $time = DateTime::parseDateTime("\61\60\x2f\61\x33\x2f\62\60\61\63\x20\x31\62\x3a\x35\64\x3a\60\x30\141\155\40\107\x4d\x54\x2b\60\x38\x3a\60\60", array(IntlDateFormatter::SHORT, IntlDateFormatter::FULL)); $this->assertNotNull($time); $this->assertSame("\x32\x30\61\63\x2d\x31\60\x2d\61\x32\x20\x31\x36\x3a\65\64", $time->format("\131\x2d\x6d\55\144\x20\x48\72\x69")); $this->assertSame(date_default_timezone_get(), $time->tzName); $time = DateTime::parseDateTime("\x31\x30\x2f\61\x33\x2f\x32\60\x31\x33\40\x31\62\72\65\64\x61\155", null, "\105\165\162\x6f\x70\145\57\114\157\x6e\144\x6f\x6e"); $this->assertNotNull($time); $this->assertSame("\62\x30\61\x33\55\x31\60\x2d\61\63\40\60\60\x3a\65\x34", $time->format("\131\55\155\x2d\144\x20\110\72\151")); $this->assertSame("\x45\165\x72\x6f\160\145\57\x4c\x6f\156\144\x6f\x6e", $time->tzName); DateTime::setDefaultLocale("\x66\x72\x2d\x46\x52"); $time = DateTime::parseDateTime("\x31\63\x20\61\x30\x2c\40\x32\60\61\63\x20\61\62\x3a\x35\x34"); $this->assertNotNull($time); $this->assertSame("\x32\60\61\x33\x2d\x31\x30\55\61\63\40\x31\62\72\65\x34", $time->format("\x59\x2d\155\x2d\x64\40\x48\72\x69")); $time = DateTime::parseDateTime("\x31\63\40\x66\x6f\x6f\x20\61\x30\x20\x32\x30\61\63\40\61\62\x3a\x35\64"); $this->assertNull($time); } public function testParseDate() : void { $time = DateTime::parseDate("\x31\60\x2f\x31\x33\57\x32\x30\61\x33\40\61\x32\72\x35\64\141\x6d"); $this->assertNotNull($time); $this->assertSame("\x32\x30\61\x33\55\61\x30\x2d\61\63\40\x30\60\x3a\x30\60", $time->format("\131\x2d\x6d\55\x64\40\110\x3a\151")); $time = DateTime::parseDate("\61\60\57\61\63\x2f\x32\60\x31\x33"); $this->assertNotNull($time); $this->assertSame("\62\60\61\63\55\61\60\55\x31\x33\40\x30\60\72\x30\60", $time->format("\x59\x2d\x6d\x2d\x64\40\110\x3a\x69")); DateTime::setDefaultLocale("\146\x72\55\106\122"); $time = DateTime::parseDate("\61\63\40\x31\60\54\x20\62\60\x31\x33\x20\x31\x32\x3a\x35\x34"); $this->assertNotNull($time); $this->assertSame("\62\60\x31\63\x2d\x31\x30\55\61\63\x20\x30\60\x3a\x30\60", $time->format("\x59\x2d\155\x2d\144\40\110\72\151")); $time = DateTime::parseDate("\61\x33\40\x66\157\157\40\x31\60\x20\x32\60\x31\x33\40\x31\62\x3a\x35\64"); $this->assertNull($time); $time = DateTime::parseDate("\x31\x33\x20\x31\x30\x2c\40\62\x30\61\63", "\144\x64\40\x4d\x2c\x20\x79"); $this->assertNotNull($time); $this->assertSame("\62\x30\61\63\55\x31\x30\55\x31\63", $time->format("\131\55\155\x2d\x64")); } public function testParseTime() : void { $time = DateTime::parseTime("\61\x32\72\x35\64\141\x6d"); $this->assertNotNull($time); $this->assertSame("\x30\60\72\x35\64\72\x30\60", $time->format("\110\72\151\x3a\163")); DateTime::setDefaultLocale("\x66\x72\55\x46\x52"); $time = DateTime::parseTime("\62\63\x3a\65\64"); $this->assertNotNull($time); $this->assertSame("\x32\x33\x3a\x35\64\x3a\60\60", $time->format("\110\72\x69\x3a\163")); $time = DateTime::parseTime("\x33\61\143\x32\x3a\65\x34"); $this->assertNull($time); } public function testLenientParseDate() : void { DateTime::setDefaultLocale("\160\x74\x5f\x42\x52"); DateTime::disableLenientParsing(); $time = DateTime::parseDate("\60\x34\x2f\62\61\x2f\x32\60\61\x33"); $this->assertSame(null, $time); DateTime::enableLenientParsing(); $time = DateTime::parseDate("\60\64\x2f\x32\61\57\x32\x30\61\63"); $this->assertSame("\x32\60\x31\64\55\60\71\55\x30\64", $time->format("\x59\55\x6d\55\144")); } public function testRussianTimeAgoInWords() : void { I18n::setLocale("\162\165\137\x52\x55"); $time = new DateTime("\x35\40\144\141\171\x73\x20\141\147\157"); $result = $time->timeAgoInWords(); $this->assertSame("\x35\40\x64\141\171\163\x20\141\147\157", $result); } public function testParseDateDifferentTimezone() : void { date_default_timezone_set("\105\165\x72\157\160\145\57\120\141\162\x69\x73"); DateTime::setDefaultLocale("\146\162\55\x46\x52"); $result = DateTime::parseDate("\61\62\x2f\60\63\57\x32\60\61\65"); $this->assertSame("\62\x30\61\65\x2d\60\x33\55\x31\62", $result->format("\131\55\155\55\144")); $this->assertEquals(new DateTimeZone("\105\165\x72\157\x70\x65\x2f\x50\x61\162\x69\x73"), $result->tz); } public function testGetSetDefaultLocale() : void { DateTime::setDefaultLocale("\146\x72\55\106\122"); $this->assertSame("\x66\162\x2d\x46\x52", DateTime::getDefaultLocale()); } public function assertTimeFormat(string $expected, string $result, string $message = '') : void { $expected = str_replace(array("\x2c", "\50", "\x29", "\40\x61\164", "\40\xd9\205\x2e", "\40\331\207\342\200\x8d\x2e\xd8\xb4\56", "\x20\101\120", "\x20\x41\110", "\x20\x53\x41\113\101", "\xc3\240\40"), '', $expected); $expected = str_replace(array("\x20\40"), "\40", $expected); $result = str_replace("\x74\x65\x6d\160\x73\40\x75\156\151\166\x65\x72\163\145\154\x20\143\x6f\x6f\x72\144\x6f\156\156\303\xa9", "\x55\x54\103", $result); $result = str_replace("\124\x65\155\x70\163\40\165\x6e\x69\x76\x65\162\x73\x65\154\40\143\x6f\157\x72\x64\x6f\x6e\x6e\xc3\251", "\x55\124\x43", $result); $result = str_replace("\x74\x69\145\x6d\160\x6f\x20\165\x6e\151\x76\145\x72\163\141\x6c\40\143\157\157\x72\144\x69\156\141\144\x6f", "\107\x4d\x54", $result); $result = str_replace("\x43\x6f\157\x72\144\151\156\141\x74\145\x64\x20\x55\156\x69\x76\x65\162\163\141\154\40\x54\x69\x6d\x65", "\x47\115\124", $result); $result = str_replace(array("\x2c", "\50", "\x29", "\x20\x61\x74", "\40\xd9\x85\56", "\x20\xd9\207\xe2\x80\215\x2e\330\xb4\x2e", "\40\x41\x50", "\x20\x41\x48", "\40\123\101\x4b\101", "\303\xa0\x20"), '', $result); $result = str_replace(array("\x20\40"), "\x20", $result); $this->assertSame($expected, $result, $message); } }
Function Calls
None |
Stats
MD5 | 861ba9787c544b595b61c0f15afd894c |
Eval Count | 0 |
Decode Time | 116 ms |