2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2012-02-06 10:55:12 +00:00
|
|
|
* CakeTimeTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2013-05-30 22:11:14 +00:00
|
|
|
|
2012-02-06 10:55:12 +00:00
|
|
|
App::uses('CakeTime', 'Utility');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2012-02-06 10:55:12 +00:00
|
|
|
* CakeTimeTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-02-06 10:55:12 +00:00
|
|
|
class CakeTimeTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-05-13 10:22:29 +00:00
|
|
|
/**
|
|
|
|
* Default system timezone identifier
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_systemTimezoneIdentifier = null;
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2013-06-08 13:47:46 +00:00
|
|
|
parent::setUp();
|
2012-02-06 10:55:12 +00:00
|
|
|
$this->Time = new CakeTime();
|
2012-05-13 10:22:29 +00:00
|
|
|
$this->_systemTimezoneIdentifier = date_default_timezone_get();
|
2013-06-08 08:25:28 +00:00
|
|
|
Configure::write('Config.language', 'eng');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2013-07-28 23:22:52 +00:00
|
|
|
parent::tearDown();
|
2009-03-18 17:55:58 +00:00
|
|
|
unset($this->Time);
|
2012-05-13 10:22:29 +00:00
|
|
|
$this->_restoreSystemTimezone();
|
2009-03-18 17:55:58 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-05-13 10:22:29 +00:00
|
|
|
/**
|
|
|
|
* Restored the original system timezone
|
|
|
|
*
|
|
|
|
* @param string $timezoneIdentifier Timezone string
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _restoreSystemTimezone() {
|
|
|
|
date_default_timezone_set($this->_systemTimezoneIdentifier);
|
|
|
|
}
|
2012-06-25 01:57:00 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testToQuarter method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testToQuarter() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Time->toQuarter('2007-12-25');
|
2015-03-02 11:08:11 +00:00
|
|
|
$this->assertSame(4, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Time->toQuarter('2007-9-25');
|
2015-03-02 11:08:11 +00:00
|
|
|
$this->assertSame(3, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Time->toQuarter('2007-3-25');
|
2015-03-02 11:08:11 +00:00
|
|
|
$this->assertSame(1, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Time->toQuarter('2007-3-25', true);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('2007-01-01', '2007-03-31'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Time->toQuarter('2007-5-25', true);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('2007-04-01', '2007-06-30'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Time->toQuarter('2007-8-25', true);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('2007-07-01', '2007-09-30'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$result = $this->Time->toQuarter('2007-12-25', true);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(array('2007-10-01', '2007-12-31'), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2012-06-25 01:57:00 +00:00
|
|
|
* provider for timeAgoInWords() tests
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2012-06-25 01:57:00 +00:00
|
|
|
* @return array
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2012-06-25 01:57:00 +00:00
|
|
|
public static function timeAgoProvider() {
|
|
|
|
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'),
|
2014-10-01 08:35:41 +00:00
|
|
|
array('+1 week', 'in 1 week'),
|
|
|
|
array('+1 week 1 day', 'in 1 week, 1 day'),
|
|
|
|
array('+2 weeks 2 day', 'in 2 weeks, 2 days'),
|
2012-06-25 01:57:00 +00:00
|
|
|
array('2007-9-24', 'on 24/9/07'),
|
|
|
|
array('now', 'just now'),
|
2012-05-13 01:09:04 +00:00
|
|
|
);
|
2012-06-25 01:57:00 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-06-25 01:57:00 +00:00
|
|
|
/**
|
|
|
|
* testTimeAgoInWords method
|
|
|
|
*
|
|
|
|
* @dataProvider timeAgoProvider
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeAgoInWords($input, $expected) {
|
|
|
|
$result = $this->Time->timeAgoInWords($input);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-06-25 01:57:00 +00:00
|
|
|
/**
|
|
|
|
* provider for timeAgo with an end date.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function timeAgoEndProvider() {
|
|
|
|
return array(
|
|
|
|
array(
|
|
|
|
'+4 months +2 weeks +3 days',
|
2014-10-01 08:35:41 +00:00
|
|
|
'in 4 months, 2 weeks, 3 days',
|
2012-06-25 01:57:00 +00:00
|
|
|
'8 years'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'+4 months +2 weeks +1 day',
|
2014-10-01 08:35:41 +00:00
|
|
|
'in 4 months, 2 weeks, 1 day',
|
2012-06-25 01:57:00 +00:00
|
|
|
'8 years'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'+3 months +2 weeks',
|
2014-10-01 08:35:41 +00:00
|
|
|
'in 3 months, 2 weeks',
|
2012-06-25 01:57:00 +00:00
|
|
|
'8 years'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'+3 months +2 weeks +1 day',
|
2014-10-01 08:35:41 +00:00
|
|
|
'in 3 months, 2 weeks, 1 day',
|
2012-06-25 01:57:00 +00:00
|
|
|
'8 years'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'+1 months +1 week +1 day',
|
2014-10-01 08:35:41 +00:00
|
|
|
'in 1 month, 1 week, 1 day',
|
2012-06-25 01:57:00 +00:00
|
|
|
'8 years'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'+2 months +2 days',
|
2014-10-01 08:35:41 +00:00
|
|
|
'in 2 months, 2 days',
|
2012-06-25 01:57:00 +00:00
|
|
|
'on ' . date('j/n/y', strtotime('+2 months +2 days'))
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'+2 months +12 days',
|
2014-10-01 08:35:41 +00:00
|
|
|
'in 2 months, 1 week, 5 days',
|
2012-06-25 01:57:00 +00:00
|
|
|
'3 months'
|
|
|
|
),
|
2012-05-13 01:09:04 +00:00
|
|
|
);
|
2012-06-25 01:57:00 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-06-25 01:57:00 +00:00
|
|
|
/**
|
|
|
|
* test the end option for timeAgoInWords
|
|
|
|
*
|
|
|
|
* @dataProvider timeAgoEndProvider
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeAgoInWordsEnd($input, $expected, $end) {
|
2012-05-13 01:09:04 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
2012-06-25 01:57:00 +00:00
|
|
|
$input, array('end' => $end)
|
2012-05-13 01:09:04 +00:00
|
|
|
);
|
2012-06-25 01:57:00 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-07-16 13:16:30 +00:00
|
|
|
/**
|
|
|
|
* test the custom string options for timeAgoInWords
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeAgoInWordsCustomStrings() {
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('-8 years -4 months -2 weeks -3 days'),
|
|
|
|
array('relativeString' => 'at least %s ago', 'accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
|
|
|
);
|
|
|
|
$expected = 'at least 8 years ago';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2014-10-01 08:35:41 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+8 years +4 months +2 weeks +3 days'),
|
|
|
|
array('relativeStringFuture' => 'not in the next %s', 'accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
|
|
|
);
|
|
|
|
$expected = 'not in the next 8 years';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2013-07-16 13:16:30 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+4 months +2 weeks +3 days'),
|
|
|
|
array('absoluteString' => 'exactly on %s', 'accuracy' => array('year' => 'year'), 'end' => '+2 months')
|
|
|
|
);
|
2013-07-17 10:18:06 +00:00
|
|
|
$expected = 'exactly on ' . date('j/n/y', strtotime('+4 months +2 weeks +3 days'));
|
2013-07-16 13:16:30 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2012-06-25 01:57:00 +00:00
|
|
|
/**
|
|
|
|
* Test the accuracy option for timeAgoInWords()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeAgoInWordsAccuracy() {
|
2012-05-13 01:09:04 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+8 years +4 months +2 weeks +3 days'),
|
2012-05-13 02:18:18 +00:00
|
|
|
array('accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
2012-05-13 01:09:04 +00:00
|
|
|
);
|
2014-10-01 08:35:41 +00:00
|
|
|
$expected = 'in 8 years';
|
2012-05-07 20:32:30 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-05-13 01:09:04 +00:00
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+8 years +4 months +2 weeks +3 days'),
|
2012-05-13 02:18:18 +00:00
|
|
|
array('accuracy' => array('year' => 'month'), 'end' => '+10 years')
|
2012-05-13 01:09:04 +00:00
|
|
|
);
|
2014-10-01 08:35:41 +00:00
|
|
|
$expected = 'in 8 years, 4 months';
|
2012-05-07 20:32:30 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-05-13 01:09:04 +00:00
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+8 years +4 months +2 weeks +3 days'),
|
2012-05-13 02:18:18 +00:00
|
|
|
array('accuracy' => array('year' => 'week'), 'end' => '+10 years')
|
2012-05-13 01:09:04 +00:00
|
|
|
);
|
2014-10-01 08:35:41 +00:00
|
|
|
$expected = 'in 8 years, 4 months, 2 weeks';
|
2012-05-07 20:32:30 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-05-13 01:09:04 +00:00
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+8 years +4 months +2 weeks +3 days'),
|
2012-05-13 02:18:18 +00:00
|
|
|
array('accuracy' => array('year' => 'day'), 'end' => '+10 years')
|
|
|
|
);
|
2014-10-01 08:35:41 +00:00
|
|
|
$expected = 'in 8 years, 4 months, 2 weeks, 3 days';
|
2012-05-07 20:32:30 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-05-13 01:09:04 +00:00
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+1 years +5 weeks'),
|
2012-05-13 02:18:18 +00:00
|
|
|
array('accuracy' => array('year' => 'year'), 'end' => '+10 years')
|
2012-05-13 01:09:04 +00:00
|
|
|
);
|
2014-10-01 08:35:41 +00:00
|
|
|
$expected = 'in 1 year';
|
2012-05-07 20:32:30 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2013-08-12 11:15:27 +00:00
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+58 minutes'),
|
|
|
|
array('accuracy' => 'hour')
|
|
|
|
);
|
|
|
|
$expected = 'in about an hour';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+23 hours'),
|
|
|
|
array('accuracy' => 'day')
|
|
|
|
);
|
|
|
|
$expected = 'in about a day';
|
|
|
|
$this->assertEquals($expected, $result);
|
2012-06-25 01:57:00 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-06-25 01:57:00 +00:00
|
|
|
/**
|
2014-09-09 14:09:00 +00:00
|
|
|
* Test the format option of timeAgoInWords() with date() and strftime compatible strings
|
2012-06-25 01:57:00 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeAgoInWordsWithFormat() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Time->timeAgoInWords('2007-9-25', 'Y-m-d');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('on 2007-09-25', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2014-09-09 14:09:00 +00:00
|
|
|
$result = $this->Time->timeAgoInWords('2007-9-25', '%x');
|
2014-10-01 09:25:24 +00:00
|
|
|
$this->assertEquals('on ' . strftime('%x', strtotime('2007-9-25')), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-05-13 01:09:04 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+2 weeks +2 days'),
|
2012-05-13 02:18:18 +00:00
|
|
|
'Y-m-d'
|
2012-05-13 01:09:04 +00:00
|
|
|
);
|
2014-10-01 08:35:41 +00:00
|
|
|
$this->assertRegExp('/^in 2 weeks, [1|2] day(s)?$/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2014-09-09 14:09:00 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+2 weeks +2 days'),
|
|
|
|
'%x'
|
|
|
|
);
|
2014-10-01 08:35:41 +00:00
|
|
|
$this->assertRegExp('/^in 2 weeks, [1|2] day(s)?$/', $result);
|
2014-09-09 14:09:00 +00:00
|
|
|
|
2012-06-25 00:54:47 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+2 months +2 days'),
|
|
|
|
array('end' => '1 month', 'format' => 'Y-m-d')
|
|
|
|
);
|
|
|
|
$this->assertEquals('on ' . date('Y-m-d', strtotime('+2 months +2 days')), $result);
|
2014-09-09 14:09:00 +00:00
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('+2 months +2 days'),
|
|
|
|
array('end' => '1 month', 'format' => '%x')
|
|
|
|
);
|
|
|
|
$this->assertEquals('on ' . strftime('%x', strtotime('+2 months +2 days')), $result);
|
2012-06-25 00:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test timeAgoInWords() with negative values.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTimeAgoInWordsNegativeValues() {
|
2012-05-13 01:09:04 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('-2 months -2 days'),
|
|
|
|
array('end' => '3 month')
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('2 months, 2 days ago', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-05-13 01:09:04 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
2012-06-25 00:54:47 +00:00
|
|
|
strtotime('-2 months -2 days'),
|
2012-05-13 01:09:04 +00:00
|
|
|
array('end' => '3 month')
|
|
|
|
);
|
2012-06-25 00:54:47 +00:00
|
|
|
$this->assertEquals('2 months, 2 days ago', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-05-13 01:09:04 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
2012-06-25 00:54:47 +00:00
|
|
|
strtotime('-2 months -2 days'),
|
2012-05-13 01:09:04 +00:00
|
|
|
array('end' => '1 month', 'format' => 'Y-m-d')
|
|
|
|
);
|
2012-06-25 00:54:47 +00:00
|
|
|
$this->assertEquals('on ' . date('Y-m-d', strtotime('-2 months -2 days')), $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-05-13 01:09:04 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
2012-06-25 00:54:47 +00:00
|
|
|
strtotime('-2 years -5 months -2 days'),
|
|
|
|
array('end' => '3 years')
|
2012-05-13 01:09:04 +00:00
|
|
|
);
|
2012-06-25 00:54:47 +00:00
|
|
|
$this->assertEquals('2 years, 5 months, 2 days ago', $result);
|
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('-2 weeks -2 days'),
|
|
|
|
'Y-m-d'
|
|
|
|
);
|
|
|
|
$this->assertEquals('2 weeks, 2 days ago', $result);
|
|
|
|
|
|
|
|
$time = strtotime('-3 years -12 months');
|
|
|
|
$result = $this->Time->timeAgoInWords($time);
|
|
|
|
$expected = 'on ' . date('j/n/y', $time);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('-1 month -1 week -6 days'),
|
|
|
|
array('end' => '1 year', 'accuracy' => array('month' => 'month'))
|
|
|
|
);
|
|
|
|
$this->assertEquals('1 month ago', $result);
|
|
|
|
|
|
|
|
$timestamp = strtotime('-1 years -2 weeks -3 days');
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
$timestamp,
|
|
|
|
array('accuracy' => array('year' => 'year'))
|
|
|
|
);
|
|
|
|
$expected = 'on ' . date('j/n/y', $timestamp);
|
|
|
|
$this->assertEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-05-13 01:09:04 +00:00
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('-13 months -5 days'),
|
|
|
|
array('end' => '2 years')
|
|
|
|
);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('1 year, 1 month, 5 days ago', $result);
|
2013-08-12 11:15:27 +00:00
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('-58 minutes'),
|
|
|
|
array('accuracy' => 'hour')
|
|
|
|
);
|
|
|
|
$this->assertEquals('about an hour ago', $result);
|
|
|
|
|
|
|
|
$result = $this->Time->timeAgoInWords(
|
|
|
|
strtotime('-23 hours'),
|
|
|
|
array('accuracy' => 'day')
|
|
|
|
);
|
|
|
|
$this->assertEquals('about a day ago', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-08 17:19:07 +00:00
|
|
|
* testNice method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNice() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$time = time() + 2 * DAY;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(date('D, M jS Y, H:i', $time), $this->Time->nice($time));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$time = time() - 2 * DAY;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(date('D, M jS Y, H:i', $time), $this->Time->nice($time));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$time = time();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(date('D, M jS Y, H:i', $time), $this->Time->nice($time));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$time = 0;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(date('D, M jS Y, H:i', time()), $this->Time->nice($time));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$time = null;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(date('D, M jS Y, H:i', time()), $this->Time->nice($time));
|
2011-01-06 03:06:52 +00:00
|
|
|
|
|
|
|
$time = time();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(date('D', $time), $this->Time->nice($time, null, '%a'));
|
|
|
|
$this->assertEquals(date('M d, Y', $time), $this->Time->nice($time, null, '%b %d, %Y'));
|
2011-01-06 03:06:52 +00:00
|
|
|
|
|
|
|
$this->Time->niceFormat = '%Y-%d-%m';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(date('Y-d-m', $time), $this->Time->nice($time));
|
2012-02-13 02:14:33 +00:00
|
|
|
$this->assertEquals('%Y-%d-%m', $this->Time->niceFormat);
|
|
|
|
|
2012-10-28 20:15:20 +00:00
|
|
|
CakeTime::$niceFormat = '%Y-%d-%m %H:%M';
|
|
|
|
$this->assertEquals(date('Y-d-m H:i', $time), $this->Time->nice($time));
|
|
|
|
$this->assertEquals('%Y-%d-%m %H:%M', $this->Time->niceFormat);
|
2012-05-13 10:22:29 +00:00
|
|
|
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
$result = $this->Time->nice(null, 'America/New_York');
|
|
|
|
$expected = $this->Time->nice(time(), 'America/New_York');
|
2012-10-28 20:15:20 +00:00
|
|
|
$this->assertEquals(substr($expected, 0, -1), substr($result, 0, -1));
|
2012-05-13 10:22:29 +00:00
|
|
|
|
|
|
|
$this->_restoreSystemTimezone();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2019-01-25 12:04:41 +00:00
|
|
|
public function testNiceTimezoneConversion() {
|
|
|
|
date_default_timezone_set('Europe/Copenhagen'); // server timezone
|
|
|
|
$clientTimeZone = new DateTimeZone('Asia/Bangkok');
|
|
|
|
$clientDateTime = new DateTime('2019-01-31 10:00:00', $clientTimeZone);
|
|
|
|
// Convert to UTC.
|
|
|
|
$actual = CakeTime::nice($clientDateTime, 'UTC', '%Y-%m-%d %H:%M:%S');
|
|
|
|
$clientDateTime->setTimezone(new DateTimeZone('UTC'));
|
|
|
|
$expected = $clientDateTime->format('Y-m-d H:i:s');
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
$this->_restoreSystemTimezone();
|
|
|
|
}
|
|
|
|
|
2008-10-08 17:19:07 +00:00
|
|
|
/**
|
|
|
|
* testNiceShort method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testNiceShort() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$time = time();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('Today, ' . date('H:i', $time), $this->Time->niceShort($time));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$time = time() - DAY;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals('Yesterday, ' . date('H:i', $time), $this->Time->niceShort($time));
|
2012-05-13 00:50:29 +00:00
|
|
|
|
2012-05-07 20:32:30 +00:00
|
|
|
$time = time() + DAY;
|
|
|
|
$this->assertEquals('Tomorrow, ' . date('H:i', $time), $this->Time->niceShort($time));
|
|
|
|
|
2013-01-15 02:12:11 +00:00
|
|
|
$time = strtotime('+6 days');
|
|
|
|
$this->assertEquals('On ' . date('l F d, H:i', $time), $this->Time->niceShort($time));
|
|
|
|
|
|
|
|
$time = strtotime('-6 days');
|
|
|
|
$this->assertEquals(date('l F d, H:i', $time), $this->Time->niceShort($time));
|
2012-05-07 20:32:30 +00:00
|
|
|
|
2012-05-13 00:50:29 +00:00
|
|
|
date_default_timezone_set('Europe/London');
|
|
|
|
$result = $this->Time->niceShort('2005-01-15 10:00:00', new DateTimeZone('Europe/Brussels'));
|
2012-05-13 13:51:47 +00:00
|
|
|
$this->assertEquals('Jan 15th 2005, 11:00', $result);
|
2012-05-13 10:22:29 +00:00
|
|
|
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
$result = $this->Time->niceShort(null, 'America/New_York');
|
|
|
|
$expected = $this->Time->niceShort(time(), 'America/New_York');
|
2012-05-13 13:51:47 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2012-05-13 10:22:29 +00:00
|
|
|
|
|
|
|
$this->_restoreSystemTimezone();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2016-07-01 03:08:43 +00:00
|
|
|
/**
|
|
|
|
* testNiceShort translations
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testNiceShortI18n() {
|
2016-07-01 21:15:23 +00:00
|
|
|
$restore = setlocale(LC_ALL, 0);
|
2016-07-01 03:08:43 +00:00
|
|
|
setlocale(LC_ALL, 'es_ES');
|
|
|
|
$time = strtotime('2015-01-07 03:05:00');
|
|
|
|
$this->assertEquals('ene 7th 2015, 03:05', $this->Time->niceShort($time));
|
2016-07-01 21:15:23 +00:00
|
|
|
setlocale(LC_ALL, $restore);
|
2016-07-01 03:08:43 +00:00
|
|
|
}
|
|
|
|
|
2008-10-08 17:19:07 +00:00
|
|
|
/**
|
|
|
|
* testDaysAsSql method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDaysAsSql() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$begin = time();
|
|
|
|
$end = time() + DAY;
|
|
|
|
$field = 'my_field';
|
2012-03-14 02:59:20 +00:00
|
|
|
$expected = '(my_field >= \'' . date('Y-m-d', $begin) . ' 00:00:00\') AND (my_field <= \'' . date('Y-m-d', $end) . ' 23:59:59\')';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Time->daysAsSql($begin, $end, $field));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-08 17:19:07 +00:00
|
|
|
* testDayAsSql method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDayAsSql() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$time = time();
|
|
|
|
$field = 'my_field';
|
2012-03-14 02:59:20 +00:00
|
|
|
$expected = '(my_field >= \'' . date('Y-m-d', $time) . ' 00:00:00\') AND (my_field <= \'' . date('Y-m-d', $time) . ' 23:59:59\')';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Time->dayAsSql($time, $field));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testToUnix method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testToUnix() {
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(time(), $this->Time->toUnix(time()));
|
|
|
|
$this->assertEquals(strtotime('+1 day'), $this->Time->toUnix('+1 day'));
|
|
|
|
$this->assertEquals(strtotime('+0 days'), $this->Time->toUnix('+0 days'));
|
|
|
|
$this->assertEquals(strtotime('-1 days'), $this->Time->toUnix('-1 days'));
|
|
|
|
$this->assertEquals(false, $this->Time->toUnix(''));
|
|
|
|
$this->assertEquals(false, $this->Time->toUnix(null));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2012-04-18 20:33:39 +00:00
|
|
|
/**
|
|
|
|
* testToServer method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testToServer() {
|
2012-05-13 13:51:47 +00:00
|
|
|
date_default_timezone_set('Europe/Paris');
|
|
|
|
|
|
|
|
$time = time();
|
|
|
|
$this->assertEquals(date('Y-m-d H:i:s', $time), $this->Time->toServer($time));
|
|
|
|
|
|
|
|
date_default_timezone_set('America/New_York');
|
|
|
|
$time = time();
|
|
|
|
date_default_timezone_set('Europe/Paris');
|
|
|
|
$result = $this->Time->toServer($time, 'America/New_York');
|
|
|
|
$this->assertEquals(date('Y-m-d H:i:s', $time), $result);
|
|
|
|
|
|
|
|
date_default_timezone_set('Europe/Paris');
|
|
|
|
$time = '2005-10-25 10:00:00';
|
|
|
|
$result = $this->Time->toServer($time);
|
|
|
|
$date = new DateTime($time, new DateTimeZone('UTC'));
|
|
|
|
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
|
|
|
$expected = $date->format('Y-m-d H:i:s');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$time = '2002-01-01 05:15:30';
|
|
|
|
$result = $this->Time->toServer($time, 'America/New_York');
|
|
|
|
$date = new DateTime($time, new DateTimeZone('America/New_York'));
|
|
|
|
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
|
|
|
$expected = $date->format('Y-m-d H:i:s');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$time = '2010-01-28T15:00:00+10:00';
|
|
|
|
$result = $this->Time->toServer($time, 'America/New_York');
|
|
|
|
$date = new DateTime($time);
|
|
|
|
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
|
|
|
$expected = $date->format('Y-m-d H:i:s');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$date = new DateTime(null, new DateTimeZone('America/New_York'));
|
|
|
|
$result = $this->Time->toServer($date, 'Pacific/Tahiti');
|
|
|
|
$date->setTimezone(new DateTimeZone(date_default_timezone_get()));
|
|
|
|
$expected = $date->format('Y-m-d H:i:s');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$this->_restoreSystemTimezone();
|
|
|
|
|
|
|
|
$time = time();
|
|
|
|
$result = $this->Time->toServer($time, null, 'l jS \of F Y h:i:s A');
|
|
|
|
$expected = date('l jS \of F Y h:i:s A', $time);
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2016-04-08 12:33:26 +00:00
|
|
|
$this->assertFalse($this->Time->toServer(time(), new CakeObject()));
|
2012-05-13 13:51:47 +00:00
|
|
|
|
2012-04-18 20:33:39 +00:00
|
|
|
date_default_timezone_set('UTC');
|
2012-05-13 10:22:29 +00:00
|
|
|
|
2012-10-28 01:12:34 +00:00
|
|
|
$serverTime = new DateTime('2012-12-11 14:15:20');
|
2012-04-18 20:33:39 +00:00
|
|
|
|
|
|
|
$timezones = array('Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu');
|
|
|
|
foreach ($timezones as $timezone) {
|
|
|
|
$result = $this->Time->toServer($serverTime->format('Y-m-d H:i:s'), $timezone, 'U');
|
|
|
|
$tz = new DateTimeZone($timezone);
|
|
|
|
$this->assertEquals($serverTime->format('U'), $result + $tz->getOffset($serverTime));
|
|
|
|
}
|
|
|
|
|
2012-05-13 13:51:47 +00:00
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
$date = new DateTime('now', new DateTimeZone('America/New_York'));
|
|
|
|
|
|
|
|
$result = $this->Time->toServer($date, null, 'Y-m-d H:i:s');
|
|
|
|
$date->setTimezone($this->Time->timezone());
|
|
|
|
$expected = $date->format('Y-m-d H:i:s');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2012-05-13 10:22:29 +00:00
|
|
|
$this->_restoreSystemTimezone();
|
2012-04-18 20:33:39 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-08 17:19:07 +00:00
|
|
|
* testToAtom method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testToAtom() {
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(date('Y-m-d\TH:i:s\Z'), $this->Time->toAtom(time()));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-08 17:19:07 +00:00
|
|
|
* testToRss method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testToRss() {
|
2012-10-28 01:12:34 +00:00
|
|
|
$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);
|
|
|
|
$userOffset = $yourTimezone->getOffset($yourTime) / HOUR;
|
2012-10-28 02:49:43 +00:00
|
|
|
$time = $yourTime->format('U');
|
2012-10-28 01:12:34 +00:00
|
|
|
$this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $userOffset), "Failed on $timezone");
|
|
|
|
$this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $timezone), "Failed on $timezone");
|
2011-08-26 21:16:49 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-08 17:19:07 +00:00
|
|
|
* testFormat method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormat() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$format = 'D-M-Y';
|
2012-05-17 11:52:47 +00:00
|
|
|
$tz = date_default_timezone_get();
|
2008-05-30 11:40:08 +00:00
|
|
|
$arr = array(time(), strtotime('+1 days'), strtotime('+1 days'), strtotime('+0 days'));
|
|
|
|
foreach ($arr as $val) {
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(date($format, $val), $this->Time->format($format, $val));
|
2012-05-17 11:52:47 +00:00
|
|
|
$this->assertEquals(date($format, $val), $this->Time->format($format, $val, false, $tz));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-07-05 14:31:22 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Time->format('Y-m-d', null, 'never');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('never', $result);
|
2012-06-09 12:58:39 +00:00
|
|
|
|
2014-08-19 22:25:01 +00:00
|
|
|
$result = $this->Time->format('Y-m-d', '');
|
|
|
|
$this->assertSame('', $result);
|
|
|
|
|
|
|
|
$result = $this->Time->format('Y-m-d', false);
|
|
|
|
$this->assertSame('', $result);
|
|
|
|
|
2012-06-24 17:41:52 +00:00
|
|
|
$result = $this->Time->format('2012-01-13', '%d-%m-%Y', 'invalid');
|
2012-06-09 12:58:39 +00:00
|
|
|
$this->assertEquals('13-01-2012', $result);
|
|
|
|
|
|
|
|
$result = $this->Time->format('nonsense', '%d-%m-%Y', 'invalid', 'UTC');
|
|
|
|
$this->assertEquals('invalid', $result);
|
2013-08-15 06:58:05 +00:00
|
|
|
|
|
|
|
$result = $this->Time->format('0000-00-00', '%d-%m-%Y', 'invalid');
|
|
|
|
$this->assertEquals('invalid', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testOfGmt method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGmt() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$hour = 3;
|
|
|
|
$min = 4;
|
|
|
|
$sec = 2;
|
|
|
|
$month = 5;
|
|
|
|
$day = 14;
|
|
|
|
$year = 2007;
|
|
|
|
$time = mktime($hour, $min, $sec, $month, $day, $year);
|
|
|
|
$expected = gmmktime($hour, $min, $sec, $month, $day, $year);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Time->gmt(date('Y-n-j G:i:s', $time)));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$hour = date('H');
|
|
|
|
$min = date('i');
|
|
|
|
$sec = date('s');
|
|
|
|
$month = date('m');
|
|
|
|
$day = date('d');
|
|
|
|
$year = date('Y');
|
|
|
|
$expected = gmmktime($hour, $min, $sec, $month, $day, $year);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $this->Time->gmt(null));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-10-08 17:19:07 +00:00
|
|
|
* testIsToday method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testIsToday() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$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);
|
|
|
|
}
|
2013-03-31 02:23:47 +00:00
|
|
|
|
2013-03-20 18:38:39 +00:00
|
|
|
/**
|
|
|
|
* testIsFuture method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testIsFuture() {
|
2013-03-31 02:23:47 +00:00
|
|
|
$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'));
|
2013-03-20 18:38:39 +00:00
|
|
|
}
|
2013-03-31 02:23:47 +00:00
|
|
|
|
2013-03-20 18:38:39 +00:00
|
|
|
/**
|
|
|
|
* testIsPast method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testIsPast() {
|
2013-03-31 02:23:47 +00:00
|
|
|
$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'));
|
2013-03-20 18:38:39 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-08 17:19:07 +00:00
|
|
|
/**
|
|
|
|
* testIsThisWeek method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testIsThisWeek() {
|
2009-10-21 21:19:21 +00:00
|
|
|
// 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'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-10-21 21:19:21 +00:00
|
|
|
$this->assertFalse($this->Time->isThisWeek($days[0] . ' days'));
|
|
|
|
$this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-08 17:19:07 +00:00
|
|
|
/**
|
|
|
|
* testIsThisMonth method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testIsThisMonth() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Time->isThisMonth('+0 day');
|
|
|
|
$this->assertTrue($result);
|
2008-07-05 14:31:22 +00:00
|
|
|
$result = $this->Time->isThisMonth($time = mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
2008-07-05 14:31:22 +00:00
|
|
|
$result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') - mt_rand(1, 12)));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
2008-07-05 14:31:22 +00:00
|
|
|
$result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') + mt_rand(1, 12)));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-08 17:19:07 +00:00
|
|
|
/**
|
|
|
|
* testIsThisYear method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testIsThisYear() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $this->Time->isThisYear('+0 day');
|
|
|
|
$this->assertTrue($result);
|
2008-07-05 14:31:22 +00:00
|
|
|
$result = $this->Time->isThisYear(mktime(0, 0, 0, mt_rand(1, 12), mt_rand(1, 28), date('Y')));
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
}
|
2011-11-08 06:16:55 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-08 17:19:07 +00:00
|
|
|
* testWasYesterday method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWasYesterday() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$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);
|
|
|
|
}
|
2011-11-08 06:16:55 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-08 17:19:07 +00:00
|
|
|
* testIsTomorrow method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testIsTomorrow() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$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);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-10-08 17:19:07 +00:00
|
|
|
* testWasWithinLast method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWasWithinLast() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$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'));
|
2008-07-05 14:31:22 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$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'));
|
2008-07-05 14:31:22 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$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'));
|
2008-07-05 14:31:22 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$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'));
|
|
|
|
}
|
2012-05-13 01:25:57 +00:00
|
|
|
|
2012-05-07 20:32:30 +00:00
|
|
|
/**
|
|
|
|
* 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->assertFalse($this->Time->isWithinNext('5 ', '-3 days'));
|
|
|
|
$this->assertFalse($this->Time->isWithinNext('1 ', '-1 hour'));
|
|
|
|
$this->assertFalse($this->Time->isWithinNext('1 ', '-1 minute'));
|
|
|
|
$this->assertFalse($this->Time->isWithinNext('1 ', '-23 hours -59 minutes -59 seconds'));
|
2012-05-13 01:25:57 +00:00
|
|
|
|
2012-05-07 20:32:30 +00:00
|
|
|
$this->assertTrue($this->Time->isWithinNext('7 days', '6 days, 23 hours, 59 minutes, 59 seconds'));
|
|
|
|
$this->assertFalse($this->Time->isWithinNext('7 days', '6 days, 23 hours, 59 minutes, 61 seconds'));
|
|
|
|
}
|
2011-11-08 06:16:55 +00:00
|
|
|
|
|
|
|
/**
|
2008-06-05 15:20:45 +00:00
|
|
|
* testUserOffset method
|
2008-07-05 14:31:22 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testUserOffset() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$timezoneServer = new DateTimeZone(date_default_timezone_get());
|
2008-07-05 14:31:22 +00:00
|
|
|
$timeServer = new DateTime('now', $timezoneServer);
|
2008-05-30 11:40:08 +00:00
|
|
|
$yourTimezone = $timezoneServer->getOffset($timeServer) / HOUR;
|
2008-07-05 14:31:22 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = time();
|
|
|
|
$result = $this->Time->fromString(time(), $yourTimezone);
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertWithinMargin($expected, $result, 1);
|
2012-04-11 22:03:16 +00:00
|
|
|
|
|
|
|
$result = $this->Time->fromString(time(), $timezoneServer->getName());
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertWithinMargin($expected, $result, 1);
|
2012-04-11 22:03:16 +00:00
|
|
|
|
|
|
|
$result = $this->Time->fromString(time(), $timezoneServer);
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertWithinMargin($expected, $result, 1);
|
2012-04-13 04:06:43 +00:00
|
|
|
|
|
|
|
Configure::write('Config.timezone', $timezoneServer->getName());
|
|
|
|
$result = $this->Time->fromString(time());
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertWithinMargin($expected, $result, 1);
|
2012-04-13 04:06:43 +00:00
|
|
|
Configure::delete('Config.timezone');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-08 17:19:07 +00:00
|
|
|
/**
|
|
|
|
* test fromString()
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFromString() {
|
2008-10-08 17:19:07 +00:00
|
|
|
$result = $this->Time->fromString('');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = $this->Time->fromString(0, 0);
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result = $this->Time->fromString('+1 hour');
|
|
|
|
$expected = strtotime('+1 hour');
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertWithinMargin($expected, $result, 1);
|
2008-10-08 17:19:07 +00:00
|
|
|
|
|
|
|
$timezone = date('Z', time());
|
|
|
|
$result = $this->Time->fromString('+1 hour', $timezone);
|
|
|
|
$expected = $this->Time->convert(strtotime('+1 hour'), $timezone);
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertWithinMargin($expected, $result, 1);
|
2012-04-11 22:03:16 +00:00
|
|
|
|
|
|
|
$timezone = date_default_timezone_get();
|
|
|
|
$result = $this->Time->fromString('+1 hour', $timezone);
|
|
|
|
$expected = $this->Time->convert(strtotime('+1 hour'), $timezone);
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertWithinMargin($expected, $result, 1);
|
2012-06-24 10:10:28 +00:00
|
|
|
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
$date = new DateTime('now', new DateTimeZone('Europe/London'));
|
|
|
|
$this->Time->fromString($date);
|
|
|
|
$this->assertEquals('Europe/London', $date->getTimeZone()->getName());
|
|
|
|
|
|
|
|
$this->_restoreSystemTimezone();
|
2008-10-08 17:19:07 +00:00
|
|
|
}
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2012-05-13 13:51:47 +00:00
|
|
|
/**
|
|
|
|
* test fromString() with a DateTime object as the dateString
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFromStringWithDateTime() {
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
$date = new DateTime('+1 hour', new DateTimeZone('America/New_York'));
|
|
|
|
$result = $this->Time->fromString($date, 'UTC');
|
|
|
|
$date->setTimezone(new DateTimeZone('UTC'));
|
2013-04-11 17:39:05 +00:00
|
|
|
$expected = $date->format('U') + $date->getOffset();
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertWithinMargin($expected, $result, 1);
|
2019-01-24 14:43:11 +00:00
|
|
|
$this->_restoreSystemTimezone();
|
|
|
|
}
|
2012-05-13 13:51:47 +00:00
|
|
|
|
2019-01-24 14:43:11 +00:00
|
|
|
public function testFromStringWithDateTimeAsia() {
|
2012-05-13 13:51:47 +00:00
|
|
|
date_default_timezone_set('Australia/Melbourne');
|
|
|
|
$date = new DateTime('+1 hour', new DateTimeZone('America/New_York'));
|
|
|
|
$result = $this->Time->fromString($date, 'Asia/Kuwait');
|
|
|
|
$date->setTimezone(new DateTimeZone('Asia/Kuwait'));
|
|
|
|
$expected = $date->format('U') + $date->getOffset();
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertWithinMargin($expected, $result, 1);
|
2019-01-24 14:43:11 +00:00
|
|
|
$this->_restoreSystemTimezone();
|
|
|
|
}
|
2012-05-13 13:51:47 +00:00
|
|
|
|
2019-01-24 14:43:11 +00:00
|
|
|
public function testFromStringTimezoneConversionToUTC() {
|
|
|
|
date_default_timezone_set('Europe/Copenhagen'); // server timezone
|
|
|
|
$clientTimeZone = new DateTimeZone('Asia/Bangkok');
|
|
|
|
$clientDateTime = new DateTime('2019-01-31 10:00:00', $clientTimeZone);
|
|
|
|
// Convert to UTC.
|
|
|
|
$actual = CakeTime::fromString($clientDateTime, 'UTC');
|
2019-01-25 11:05:44 +00:00
|
|
|
$clientDateTime->setTimezone(new DateTimeZone('UTC'));
|
|
|
|
$expected = $clientDateTime->getTimestamp() + $clientDateTime->getOffset(); // 1548903600
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
$this->_restoreSystemTimezone();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFromStringUTCtoCopenhagen() {
|
|
|
|
date_default_timezone_set('UTC'); // server timezone
|
|
|
|
$clientTimeZone = new DateTimeZone('UTC');
|
|
|
|
$clientDateTime = new DateTime('2012-01-01 10:00:00', $clientTimeZone);
|
|
|
|
$actual = CakeTime::fromString($clientDateTime, 'Europe/Copenhagen');
|
|
|
|
$clientDateTime->setTimezone(new DateTimeZone('Europe/Copenhagen'));
|
|
|
|
$expected = $clientDateTime->getTimestamp() + $clientDateTime->getOffset(); // 1325415600
|
2019-01-24 14:43:11 +00:00
|
|
|
$this->assertEquals($expected, $actual);
|
2012-05-13 13:51:47 +00:00
|
|
|
$this->_restoreSystemTimezone();
|
|
|
|
}
|
|
|
|
|
2013-04-10 01:30:20 +00:00
|
|
|
/**
|
|
|
|
* Test that datetimes in the default timezone are not modified.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFromStringWithDateTimeNoConversion() {
|
|
|
|
Configure::write('Config.timezone', date_default_timezone_get());
|
|
|
|
$date = new DateTime('2013-04-09');
|
|
|
|
$result = $this->Time->fromString($date);
|
2013-04-11 17:39:05 +00:00
|
|
|
$this->assertEquals($result, $date->format('U'));
|
2013-04-10 01:30:20 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 11:05:44 +00:00
|
|
|
public function testConvertToBangkok() {
|
|
|
|
$serverTimeZoneName = 'Europe/Copenhagen';
|
|
|
|
date_default_timezone_set($serverTimeZoneName);
|
|
|
|
|
|
|
|
$serverTimeZone = new DateTimeZone($serverTimeZoneName);
|
|
|
|
$DateTime = new DateTime('2019-01-31 04:00:00', $serverTimeZone);
|
|
|
|
$serverTimestamp = $DateTime->getTimestamp() + $DateTime->getOffset(); // 1548907200
|
|
|
|
|
|
|
|
$clientTimeZoneName = 'Asia/Bangkok';
|
|
|
|
$clientTimeZone = new DateTimeZone($clientTimeZoneName);
|
|
|
|
$DateTime->setTimezone($clientTimeZone);
|
|
|
|
$expected = $DateTime->getTimestamp() + $DateTime->getOffset(); // 1548928800
|
|
|
|
|
|
|
|
$actual = CakeTime::convert($serverTimestamp, $clientTimeZoneName);
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
$this->_restoreSystemTimezone();
|
|
|
|
}
|
|
|
|
|
2010-01-14 18:41:57 +00:00
|
|
|
/**
|
|
|
|
* test converting time specifiers using a time definition localfe file
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testConvertSpecifiers() {
|
2010-01-14 18:41:57 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2010-01-14 18:41:57 +00:00
|
|
|
Configure::write('Config.language', 'time_test');
|
2010-04-13 05:06:44 +00:00
|
|
|
$time = strtotime('Thu Jan 14 11:43:39 2010');
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%a', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'jue';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%A', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'jueves';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%c', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'jue %d ene %Y %H:%M:%S %Z';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%C', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = '20';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%D', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = '%m/%d/%y';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%b', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'ene';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%h', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'ene';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%B', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'enero';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%n', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = "\n";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%n', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = "\n";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%p', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'AM';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%P', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'am';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%r', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = '%I:%M:%S AM';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%R', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = '11:43';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%t', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = "\t";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%T', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = '%H:%M:%S';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%u', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 4;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%x', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = '%d/%m/%y';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->convertSpecifiers('%X', $time);
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = '%H:%M:%S';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:48:34 +00:00
|
|
|
/**
|
2015-07-09 13:54:03 +00:00
|
|
|
* test convert %e on Windows.
|
2011-02-21 15:48:34 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testConvertPercentE() {
|
2015-07-09 13:54:03 +00:00
|
|
|
$this->skipIf(DIRECTORY_SEPARATOR !== '\\', 'Cannot run Windows tests on non-Windows OS.');
|
2011-05-31 00:49:46 +00:00
|
|
|
|
2011-02-21 15:48:34 +00:00
|
|
|
$time = strtotime('Thu Jan 14 11:43:39 2010');
|
|
|
|
$result = $this->Time->convertSpecifiers('%e', $time);
|
|
|
|
$expected = '14';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-02-21 15:48:34 +00:00
|
|
|
|
|
|
|
$result = $this->Time->convertSpecifiers('%e', strtotime('2011-01-01'));
|
|
|
|
$expected = ' 1';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-02-21 15:48:34 +00:00
|
|
|
}
|
|
|
|
|
2010-01-14 18:41:57 +00:00
|
|
|
/**
|
|
|
|
* test formatting dates taking in account preferred i18n locale file
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testI18nFormat() {
|
2010-01-14 18:41:57 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Locale' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Locale' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2010-01-14 18:41:57 +00:00
|
|
|
Configure::write('Config.language', 'time_test');
|
2011-11-19 15:08:04 +00:00
|
|
|
|
2010-04-13 05:06:44 +00:00
|
|
|
$time = strtotime('Thu Jan 14 13:59:28 2010');
|
2010-01-14 18:41:57 +00:00
|
|
|
|
|
|
|
$result = $this->Time->i18nFormat($time);
|
|
|
|
$expected = '14/01/10';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->i18nFormat($time, '%c');
|
2012-04-27 00:39:32 +00:00
|
|
|
$expected = 'jue 14 ene 2010 13:59:28 ' . utf8_encode(strftime('%Z', $time));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->i18nFormat($time, 'Time is %r, and date is %x');
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'Time is 01:59:28 PM, and date is 14/01/10';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
|
2011-11-19 15:08:04 +00:00
|
|
|
$time = strtotime('Wed Jan 13 13:59:28 2010');
|
|
|
|
|
|
|
|
$result = $this->Time->i18nFormat($time);
|
|
|
|
$expected = '13/01/10';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Time->i18nFormat($time, '%c');
|
2012-04-27 00:39:32 +00:00
|
|
|
$expected = 'mié 13 ene 2010 13:59:28 ' . utf8_encode(strftime('%Z', $time));
|
2011-11-19 15:08:04 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = $this->Time->i18nFormat($time, 'Time is %r, and date is %x');
|
|
|
|
$expected = 'Time is 01:59:28 PM, and date is 13/01/10';
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
2010-01-14 20:08:48 +00:00
|
|
|
$result = $this->Time->i18nFormat('invalid date', '%x', 'Date invalid');
|
2010-01-14 18:41:57 +00:00
|
|
|
$expected = 'Date invalid';
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-01-14 18:41:57 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 14:43:11 +00:00
|
|
|
public function testI18nFormatTimezoneConversionToUTC() {
|
|
|
|
date_default_timezone_set('Europe/Copenhagen'); // server timezone
|
|
|
|
$clientTimeZone = new DateTimeZone('Asia/Bangkok');
|
|
|
|
$clientDateTime = new DateTime('2019-01-31 10:00:00', $clientTimeZone);
|
|
|
|
// Convert to UTC.
|
|
|
|
$actual = CakeTime::i18nFormat($clientDateTime, '%Y-%m-%d %H:%M:%S', false, 'UTC');
|
2019-01-25 11:05:44 +00:00
|
|
|
$clientDateTime->setTimezone(new DateTimeZone('UTC'));
|
|
|
|
$expected = $clientDateTime->format('Y-m-d H:i:s');
|
|
|
|
$this->assertEquals($expected, $actual);
|
2019-01-24 14:43:11 +00:00
|
|
|
$this->_restoreSystemTimezone();
|
|
|
|
}
|
|
|
|
|
2019-01-25 11:05:44 +00:00
|
|
|
public function testI18nFormatUTCtoCopenhagen() {
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
$clientTimeZone = new DateTimeZone('UTC');
|
|
|
|
$clientDateTime = new DateTime('2012-01-01 10:00:00', $clientTimeZone);
|
|
|
|
$actual = CakeTime::i18nFormat($clientDateTime, '%Y-%m-%d %H:%M', false, 'Europe/Copenhagen');
|
|
|
|
$clientDateTime->setTimezone(new DateTimeZone('Europe/Copenhagen'));
|
|
|
|
$expected = $clientDateTime->format('Y-m-d H:i');
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
}
|
|
|
|
|
2010-01-14 18:41:57 +00:00
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* test new format() syntax which inverts first and second parameters
|
2010-01-14 18:41:57 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testFormatNewSyntax() {
|
2010-01-14 18:41:57 +00:00
|
|
|
$time = time();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($this->Time->format($time), $this->Time->i18nFormat($time));
|
|
|
|
$this->assertEquals($this->Time->format($time, '%c'), $this->Time->i18nFormat($time, '%c'));
|
2010-01-14 18:41:57 +00:00
|
|
|
}
|
2012-05-12 15:03:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testListTimezones
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testListTimezones() {
|
2016-08-30 01:56:30 +00:00
|
|
|
$this->skipIf(
|
|
|
|
version_compare(PHP_VERSION, '5.4.0', '<='),
|
|
|
|
'This test requires newer libicu which is in php5.4+'
|
|
|
|
);
|
2012-05-12 15:03:56 +00:00
|
|
|
$return = CakeTime::listTimezones();
|
|
|
|
$this->assertTrue(isset($return['Asia']['Asia/Bangkok']));
|
|
|
|
$this->assertEquals('Bangkok', $return['Asia']['Asia/Bangkok']);
|
|
|
|
$this->assertTrue(isset($return['America']['America/Argentina/Buenos_Aires']));
|
|
|
|
$this->assertEquals('Argentina/Buenos_Aires', $return['America']['America/Argentina/Buenos_Aires']);
|
|
|
|
$this->assertTrue(isset($return['UTC']['UTC']));
|
|
|
|
$this->assertFalse(isset($return['Cuba']));
|
|
|
|
$this->assertFalse(isset($return['US']));
|
|
|
|
|
|
|
|
$return = CakeTime::listTimezones('#^Asia/#');
|
|
|
|
$this->assertTrue(isset($return['Asia']['Asia/Bangkok']));
|
|
|
|
$this->assertFalse(isset($return['Pacific']));
|
|
|
|
|
2015-08-20 13:59:46 +00:00
|
|
|
$return = CakeTime::listTimezones(null, null, array('abbr' => true));
|
|
|
|
$this->assertTrue(isset($return['Asia']['Asia/Jakarta']));
|
|
|
|
$this->assertEquals('Jakarta - WIB', $return['Asia']['Asia/Jakarta']);
|
2015-10-27 02:27:54 +00:00
|
|
|
$this->assertEquals('Regina - CST', $return['America']['America/Regina']);
|
2015-08-20 13:59:46 +00:00
|
|
|
|
|
|
|
$return = CakeTime::listTimezones(null, null, array(
|
|
|
|
'abbr' => true,
|
|
|
|
'before' => ' (',
|
|
|
|
'after' => ')',
|
|
|
|
));
|
|
|
|
$this->assertEquals('Jayapura (WIT)', $return['Asia']['Asia/Jayapura']);
|
2015-10-27 02:27:54 +00:00
|
|
|
$this->assertEquals('Regina (CST)', $return['America']['America/Regina']);
|
2015-08-20 13:59:46 +00:00
|
|
|
|
2012-05-12 15:03:56 +00:00
|
|
|
$return = CakeTime::listTimezones('#^(America|Pacific)/#', null, false);
|
|
|
|
$this->assertTrue(isset($return['America/Argentina/Buenos_Aires']));
|
|
|
|
$this->assertTrue(isset($return['Pacific/Tahiti']));
|
|
|
|
|
|
|
|
if (!$this->skipIf(version_compare(PHP_VERSION, '5.3.0', '<'))) {
|
|
|
|
$return = CakeTime::listTimezones(DateTimeZone::ASIA);
|
|
|
|
$this->assertTrue(isset($return['Asia']['Asia/Bangkok']));
|
|
|
|
$this->assertFalse(isset($return['Pacific']));
|
|
|
|
|
|
|
|
$return = CakeTime::listTimezones(DateTimeZone::PER_COUNTRY, 'US', false);
|
|
|
|
$this->assertTrue(isset($return['Pacific/Honolulu']));
|
|
|
|
$this->assertFalse(isset($return['Asia/Bangkok']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-25 13:23:19 +00:00
|
|
|
/**
|
|
|
|
* Tests that using CakeTime::format() with the correct sytax actually converts
|
|
|
|
* from one timezone to the other correctly
|
|
|
|
*
|
|
|
|
* @return void
|
2013-01-11 14:06:54 +00:00
|
|
|
*/
|
2019-01-25 11:05:44 +00:00
|
|
|
public function testCorrectTimezoneConversionAsString() {
|
2012-09-25 13:23:19 +00:00
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
$date = '2012-01-01 10:00:00';
|
2012-10-16 02:51:41 +00:00
|
|
|
$converted = CakeTime::format($date, '%Y-%m-%d %H:%M', '', 'Europe/Copenhagen');
|
2012-09-25 13:23:19 +00:00
|
|
|
$expected = new DateTime($date);
|
|
|
|
$expected->setTimezone(new DateTimeZone('Europe/Copenhagen'));
|
2012-10-16 02:51:41 +00:00
|
|
|
$this->assertEquals($expected->format('Y-m-d H:i'), $converted);
|
2012-09-25 13:23:19 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 11:05:44 +00:00
|
|
|
public function testCorrectTimezoneConversionAsObject() {
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
$clientTimeZone = new DateTimeZone('UTC');
|
|
|
|
$date = '2012-01-01 10:00:00';
|
|
|
|
$clientDateTime = new DateTime($date, $clientTimeZone);
|
|
|
|
$converted = CakeTime::format($clientDateTime, '%Y-%m-%d %H:%M', '', 'Europe/Copenhagen');
|
|
|
|
$clientDateTime->setTimezone(new DateTimeZone('Europe/Copenhagen'));
|
|
|
|
$expected = $clientDateTime->format('Y-m-d H:i');
|
|
|
|
$this->assertEquals($expected, $converted);
|
|
|
|
}
|
|
|
|
|
2019-01-24 14:43:11 +00:00
|
|
|
public function testFormatTimezoneConversionToUTC() {
|
2019-01-18 16:07:05 +00:00
|
|
|
date_default_timezone_set('Europe/Copenhagen'); // server timezone
|
|
|
|
$clientTimeZone = new DateTimeZone('Asia/Bangkok');
|
|
|
|
$clientDateTime = new DateTime('2019-01-31 10:00:00', $clientTimeZone);
|
|
|
|
// Convert to UTC.
|
|
|
|
$actual = CakeTime::format($clientDateTime, '%Y-%m-%d %H:%M:%S', false, 'UTC');
|
2019-01-25 11:05:44 +00:00
|
|
|
$clientDateTime->setTimezone(new DateTimeZone('UTC'));
|
|
|
|
$expected = $clientDateTime->format('Y-m-d H:i:s');
|
|
|
|
$this->assertEquals($expected, $actual);
|
2019-01-24 14:43:11 +00:00
|
|
|
$this->_restoreSystemTimezone();
|
2019-01-20 20:54:41 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|