2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Time Helper class file.
|
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +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
|
2008-05-30 11:40:08 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.View.Helper
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 0.10.0.1076
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-12-08 15:35:02 +00:00
|
|
|
|
2012-02-07 01:01:43 +00:00
|
|
|
App::uses('CakeTime', 'Utility');
|
2011-11-21 15:18:12 +00:00
|
|
|
App::uses('Multibyte', 'I18n');
|
2010-12-04 18:10:24 +00:00
|
|
|
App::uses('AppHelper', 'View/Helper');
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Time Helper class for easy use of time data.
|
|
|
|
*
|
|
|
|
* Manipulation of time data.
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.View.Helper
|
2011-10-15 17:06:19 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html
|
2012-02-07 01:01:43 +00:00
|
|
|
* @see CakeTime
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class TimeHelper extends AppHelper {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-01-06 03:06:52 +00:00
|
|
|
/**
|
2012-02-07 01:01:43 +00:00
|
|
|
* CakeTime instance
|
2012-11-28 22:30:47 +00:00
|
|
|
*
|
|
|
|
* @var stdClass
|
2011-01-06 03:06:52 +00:00
|
|
|
*/
|
2012-02-14 16:14:18 +00:00
|
|
|
protected $_engine = null;
|
2011-01-06 03:06:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2012-02-14 16:26:55 +00:00
|
|
|
* ### Settings:
|
|
|
|
*
|
|
|
|
* - `engine` Class name to use to replace CakeTime functionality
|
|
|
|
* The class needs to be placed in the `Utility` directory.
|
|
|
|
*
|
2011-01-06 03:06:52 +00:00
|
|
|
* @param View $View the view object the helper is attached to.
|
2013-04-03 10:54:42 +00:00
|
|
|
* @param array $settings Settings array
|
2012-03-03 22:10:12 +00:00
|
|
|
* @throws CakeException When the engine class could not be found.
|
2011-01-06 03:06:52 +00:00
|
|
|
*/
|
|
|
|
public function __construct(View $View, $settings = array()) {
|
2012-03-11 01:57:18 +00:00
|
|
|
$settings = Hash::merge(array('engine' => 'CakeTime'), $settings);
|
2011-01-06 03:06:52 +00:00
|
|
|
parent::__construct($View, $settings);
|
2012-02-14 15:56:48 +00:00
|
|
|
list($plugin, $engineClass) = pluginSplit($settings['engine'], true);
|
|
|
|
App::uses($engineClass, $plugin . 'Utility');
|
2012-02-13 02:14:33 +00:00
|
|
|
if (class_exists($engineClass)) {
|
2012-02-14 16:14:18 +00:00
|
|
|
$this->_engine = new $engineClass($settings);
|
2012-02-13 02:14:33 +00:00
|
|
|
} else {
|
|
|
|
throw new CakeException(__d('cake_dev', '%s could not be found', $engineClass));
|
|
|
|
}
|
2011-01-06 03:06:52 +00:00
|
|
|
}
|
|
|
|
|
2010-01-14 18:41:57 +00:00
|
|
|
/**
|
2012-02-07 01:01:43 +00:00
|
|
|
* Magic accessor for deprecated attributes.
|
2010-01-14 18:41:57 +00:00
|
|
|
*
|
2012-02-07 01:01:43 +00:00
|
|
|
* @param string $name Name of the attribute to set.
|
|
|
|
* @param string $value Value of the attribute to set.
|
2012-11-28 22:30:47 +00:00
|
|
|
* @return void
|
2010-01-14 18:41:57 +00:00
|
|
|
*/
|
2012-02-07 01:01:43 +00:00
|
|
|
public function __set($name, $value) {
|
|
|
|
switch ($name) {
|
|
|
|
case 'niceFormat':
|
2012-02-14 16:14:18 +00:00
|
|
|
$this->_engine->{$name} = $value;
|
2013-07-02 22:52:48 +00:00
|
|
|
break;
|
2012-02-07 01:01:43 +00:00
|
|
|
default:
|
2012-02-13 02:14:33 +00:00
|
|
|
$this->{$name} = $value;
|
2010-01-14 18:41:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-07 01:01:43 +00:00
|
|
|
* Magic isset check for deprecated attributes.
|
2010-01-14 18:41:57 +00:00
|
|
|
*
|
2012-02-07 01:01:43 +00:00
|
|
|
* @param string $name Name of the attribute to check.
|
2014-11-05 12:03:27 +00:00
|
|
|
* @return bool|null
|
2010-01-14 18:41:57 +00:00
|
|
|
*/
|
2012-02-07 01:01:43 +00:00
|
|
|
public function __isset($name) {
|
|
|
|
if (isset($this->{$name})) {
|
|
|
|
return true;
|
2010-01-14 18:41:57 +00:00
|
|
|
}
|
2012-02-07 01:01:43 +00:00
|
|
|
$magicGet = array('niceFormat');
|
|
|
|
if (in_array($name, $magicGet)) {
|
|
|
|
return $this->__get($name) !== null;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Magic accessor for attributes that were deprecated.
|
|
|
|
*
|
|
|
|
* @param string $name Name of the attribute to get.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function __get($name) {
|
2012-02-14 16:14:18 +00:00
|
|
|
if (isset($this->_engine->{$name})) {
|
|
|
|
return $this->_engine->{$name};
|
2012-02-07 01:01:43 +00:00
|
|
|
}
|
|
|
|
$magicGet = array('niceFormat');
|
|
|
|
if (in_array($name, $magicGet)) {
|
2012-02-14 16:14:18 +00:00
|
|
|
return $this->_engine->{$name};
|
2012-02-07 01:01:43 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-02-14 16:26:55 +00:00
|
|
|
/**
|
|
|
|
* Call methods from CakeTime utility class
|
2014-05-29 19:01:20 +00:00
|
|
|
*
|
|
|
|
* @param string $method Method to call.
|
|
|
|
* @param array $params Parameters to pass to method.
|
2013-10-15 02:43:17 +00:00
|
|
|
* @return mixed Whatever is returned by called method, or false on failure
|
2012-02-14 16:26:55 +00:00
|
|
|
*/
|
2012-02-07 01:01:43 +00:00
|
|
|
public function __call($method, $params) {
|
2012-02-14 16:14:18 +00:00
|
|
|
return call_user_func_array(array($this->_engine, $method), $params);
|
2010-01-14 18:41:57 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Converts a string representing the format for the function strftime and returns a
|
|
|
|
* windows safe and i18n aware format.
|
|
|
|
*
|
2012-02-07 01:01:43 +00:00
|
|
|
* @param string $format Format with specifiers for strftime function.
|
|
|
|
* Accepts the special specifier %S which mimics the modifier S for date()
|
|
|
|
* @param string $time UNIX timestamp
|
|
|
|
* @return string windows safe and date() function compatible format for strftime
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::convertSpecifiers()
|
2012-02-07 01:01:43 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
|
|
|
*/
|
|
|
|
public function convertSpecifiers($format, $time = null) {
|
2012-02-14 16:14:18 +00:00
|
|
|
return $this->_engine->convertSpecifiers($format, $time);
|
2012-02-07 01:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Converts given time (in server's time zone) to user's local time, given his/her timezone.
|
|
|
|
*
|
2008-10-23 00:10:44 +00:00
|
|
|
* @param string $serverTime UNIX timestamp
|
2012-05-13 00:43:31 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return int UNIX timestamp
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::convert()
|
2011-11-11 18:51:14 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function convert($serverTime, $timezone) {
|
|
|
|
return $this->_engine->convert($serverTime, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns server's offset
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return int Offset
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::serverOffset()
|
2011-11-11 18:51:14 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function serverOffset() {
|
2012-02-14 16:14:18 +00:00
|
|
|
return $this->_engine->serverOffset();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2008-10-08 17:19:07 +00:00
|
|
|
* @return string Parsed timestamp
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::fromString()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function fromString($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->fromString($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns a nicely formatted date string for given Datetime string.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-03-10 08:35:03 +00:00
|
|
|
* @param string $format The format to use. If null, `CakeTime::$niceFormat` is used
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Formatted date string
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::nice()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function nice($dateString = null, $timezone = null, $format = null) {
|
|
|
|
return $this->_engine->nice($dateString, $timezone, $format);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns a formatted descriptive date string for given datetime string.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime objectp
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Described, relative date string
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::niceShort()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function niceShort($dateString = null, $timezone = null) {
|
|
|
|
return $this->_engine->niceShort($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns a partial SQL string to search for all records between two dates.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $begin UNIX timestamp, strtotime() valid string or DateTime object
|
|
|
|
* @param int|string|DateTime $end UNIX timestamp, strtotime() valid string or DateTime object
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $fieldName Name of database field to compare with
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Partial SQL string.
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::daysAsSql()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function daysAsSql($begin, $end, $fieldName, $timezone = null) {
|
|
|
|
return $this->_engine->daysAsSql($begin, $end, $fieldName, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns a partial SQL string to search for all records between two times
|
|
|
|
* occurring on the same day.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $fieldName Name of database field to compare with
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Partial SQL string.
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::dayAsSql()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function dayAsSql($dateString, $fieldName, $timezone = null) {
|
|
|
|
return $this->_engine->dayAsSql($dateString, $fieldName, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns true if given datetime string is today.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool True if datetime string is today
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::isToday()
|
2011-11-11 18:51:14 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function isToday($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->isToday($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns true if given datetime string is within this week.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool True if datetime string is within current week
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::isThisWeek()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function isThisWeek($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->isThisWeek($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns true if given datetime string is within this month
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool True if datetime string is within current month
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::isThisMonth()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function isThisMonth($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->isThisMonth($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns true if given datetime string is within current year.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool True if datetime string is within current year
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::isThisYear()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function isThisYear($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->isThisYear($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns true if given datetime string was yesterday.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool True if datetime string was yesterday
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::wasYesterday()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function wasYesterday($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->wasYesterday($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns true if given datetime string is tomorrow.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool True if datetime string was yesterday
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::isTomorrow()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function isTomorrow($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->isTomorrow($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns the quarter
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
|
|
|
* @param bool $range if true returns a range in Y-m-d format
|
2011-11-07 06:26:58 +00:00
|
|
|
* @return mixed 1, 2, 3, or 4 quarter of year or array if $range true
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::toQuarter()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function toQuarter($dateString, $range = false) {
|
2012-02-14 16:14:18 +00:00
|
|
|
return $this->_engine->toQuarter($dateString, $range);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return int Unix timestamp
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::toUnix()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function toUnix($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->toUnix($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns a date formatted for Atom RSS feeds.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Formatted date string
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::toAtom()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function toAtom($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->toAtom($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Formats date for RSS feeds
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Formatted date string
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::toRSS()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function toRSS($dateString, $timezone = null) {
|
|
|
|
return $this->_engine->toRSS($dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-08-04 00:36:31 +00:00
|
|
|
* Formats a date into a phrase expressing the relative time.
|
2014-02-07 14:45:00 +00:00
|
|
|
*
|
2012-05-13 02:25:38 +00:00
|
|
|
* ## Addition options
|
|
|
|
*
|
|
|
|
* - `element` - The element to wrap the formatted time in.
|
|
|
|
* Has a few additional options:
|
|
|
|
* - `tag` - The tag to use, defaults to 'span'.
|
2013-10-23 02:59:50 +00:00
|
|
|
* - `class` - The class name to use, defaults to `time-ago-in-words`.
|
2012-05-13 02:25:38 +00:00
|
|
|
* - `title` - Defaults to the $dateTime input.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateTime UNIX timestamp, strtotime() valid string or DateTime object
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param array $options Default format if timestamp is used in $dateString
|
|
|
|
* @return string Relative time string.
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::timeAgoInWords()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function timeAgoInWords($dateTime, $options = array()) {
|
2012-05-09 18:00:22 +00:00
|
|
|
$element = null;
|
|
|
|
|
2013-08-08 01:56:58 +00:00
|
|
|
if (!empty($options['element'])) {
|
2012-05-13 01:16:57 +00:00
|
|
|
$element = array(
|
2012-05-09 18:00:22 +00:00
|
|
|
'tag' => 'span',
|
|
|
|
'class' => 'time-ago-in-words',
|
|
|
|
'title' => $dateTime
|
|
|
|
);
|
2012-05-13 01:59:33 +00:00
|
|
|
|
2012-05-09 18:00:22 +00:00
|
|
|
if (is_array($options['element'])) {
|
2014-04-07 23:25:14 +00:00
|
|
|
$element = $options['element'] + $element;
|
2012-05-09 18:00:22 +00:00
|
|
|
} else {
|
2012-05-13 01:16:57 +00:00
|
|
|
$element['tag'] = $options['element'];
|
2012-05-09 18:00:22 +00:00
|
|
|
}
|
2012-05-13 01:16:57 +00:00
|
|
|
unset($options['element']);
|
2012-05-09 18:00:22 +00:00
|
|
|
}
|
|
|
|
$relativeDate = $this->_engine->timeAgoInWords($dateTime, $options);
|
|
|
|
|
|
|
|
if ($element) {
|
2012-05-13 01:16:57 +00:00
|
|
|
$relativeDate = sprintf(
|
|
|
|
'<%s%s>%s</%s>',
|
|
|
|
$element['tag'],
|
|
|
|
$this->_parseAttributes($element, array('tag')),
|
|
|
|
$relativeDate,
|
|
|
|
$element['tag']
|
|
|
|
);
|
2012-05-09 18:00:22 +00:00
|
|
|
}
|
|
|
|
return $relativeDate;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns true if specified datetime was within the interval specified, else false.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param string|int $timeInterval the numeric value with space then time type.
|
2010-01-25 22:59:05 +00:00
|
|
|
* Example of valid types: 6 hours, 2 days, 1 minute.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::wasWithinLast()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function wasWithinLast($timeInterval, $dateString, $timezone = null) {
|
|
|
|
return $this->_engine->wasWithinLast($timeInterval, $dateString, $timezone);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2012-05-13 01:59:33 +00:00
|
|
|
|
2012-05-09 18:00:22 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns true if specified datetime is within the interval specified, else false.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param string|int $timeInterval the numeric value with space then time type.
|
2012-05-09 18:00:22 +00:00
|
|
|
* Example of valid types: 6 hours, 2 days, 1 minute.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2014-07-03 13:36:42 +00:00
|
|
|
* @return bool
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::isWithinLast()
|
2012-05-09 18:00:22 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time
|
|
|
|
*/
|
|
|
|
public function isWithinNext($timeInterval, $dateString, $timezone = null) {
|
|
|
|
return $this->_engine->isWithinNext($timeInterval, $dateString, $timezone);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns gmt as a UNIX timestamp.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $string UNIX timestamp, strtotime() valid string or DateTime object
|
|
|
|
* @return int UNIX timestamp
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::gmt()
|
2011-10-16 13:36:51 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function gmt($string = null) {
|
2012-02-14 16:14:18 +00:00
|
|
|
return $this->_engine->gmt($string);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
|
|
|
|
* This function also accepts a time string and a format string as first and second parameters.
|
|
|
|
* In that case this function behaves as a wrapper for TimeHelper::i18nFormat()
|
|
|
|
*
|
|
|
|
* ## Examples
|
|
|
|
*
|
|
|
|
* Create localized & formatted time:
|
|
|
|
*
|
|
|
|
* {{{
|
|
|
|
* $this->Time->format('2012-02-15', '%m-%d-%Y'); // returns 02-15-2012
|
|
|
|
* $this->Time->format('2012-02-15 23:01:01', '%c'); // returns preferred date and time based on configured locale
|
|
|
|
* $this->Time->format('0000-00-00', '%d-%m-%Y', 'N/A'); // return N/A becuase an invalid date was passed
|
|
|
|
* $this->Time->format('2012-02-15 23:01:01', '%c', 'N/A', 'America/New_York'); // converts passed date to timezone
|
|
|
|
* }}}
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $format date format string (or a UNIX timestamp, strtotime() valid string or DateTime object)
|
|
|
|
* @param int|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object (or a date format string)
|
|
|
|
* @param bool $invalid flag to ignore results of fromString == false
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Formatted date string
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::format()
|
2011-11-11 18:51:14 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function format($format, $date = null, $invalid = false, $timezone = null) {
|
|
|
|
return $this->_engine->format($format, $date, $invalid, $timezone);
|
2010-01-14 18:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-02-07 14:45:00 +00:00
|
|
|
* Returns a formatted date string, given either a UNIX timestamp or a valid strtotime() date string.
|
|
|
|
* It takes into account the default date format for the current language if a LC_TIME file is used.
|
|
|
|
*
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param int|string|DateTime $date UNIX timestamp, strtotime() valid string or DateTime object
|
2010-01-14 18:41:57 +00:00
|
|
|
* @param string $format strftime format string.
|
2014-07-03 13:36:42 +00:00
|
|
|
* @param bool $invalid flag to ignore results of fromString == false
|
2012-05-13 13:51:47 +00:00
|
|
|
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
|
2011-07-31 20:55:52 +00:00
|
|
|
* @return string Formatted and translated date string
|
2014-05-29 19:01:20 +00:00
|
|
|
* @see CakeTime::i18nFormat()
|
2011-11-11 18:51:14 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
|
2010-01-14 18:41:57 +00:00
|
|
|
*/
|
2012-04-11 22:03:16 +00:00
|
|
|
public function i18nFormat($date, $format = null, $invalid = false, $timezone = null) {
|
|
|
|
return $this->_engine->i18nFormat($date, $format, $invalid, $timezone);
|
2011-11-19 15:08:04 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|