Class TimeHelper
Time Helper class for easy use of time data.
Manipulation of time data.
- AppHelper
- TimeHelper
Link: http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html
See:
CakeTime
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/TimeHelper.php
Properties summary
-
$_engine
protected
Method Summary
- __call() publicCall methods from CakeTime utility class
- __construct() publicConstructor
- __get() publicMagic accessor for attributes that were deprecated.
- __isset() publicMagic isset check for deprecated attributes.
- __set() publicMagic accessor for deprecated attributes.
- convert() publicConverts given time (in server's time zone) to user's local time, given his/her timezone.
- convertSpecifiers() public
Converts a string representing the format for the function strftime and returns a Windows safe and i18n aware format.
- dayAsSql() public
Returns a partial SQL string to search for all records between two times occurring on the same day.
- daysAsSql() publicReturns a partial SQL string to search for all records between two dates.
- format() public
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()
- fromString() publicReturns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
- gmt() publicReturns gmt as a UNIX timestamp.
- i18nFormat() public
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.
- isThisMonth() publicReturns true if given datetime string is within this month
- isThisWeek() publicReturns true if given datetime string is within this week.
- isThisYear() publicReturns true if given datetime string is within current year.
- isToday() publicReturns true if given datetime string is today.
- isTomorrow() publicReturns true if given datetime string is tomorrow.
- isWithinNext() publicReturns true if specified datetime is within the interval specified, else false.
- nice() publicReturns a nicely formatted date string for given Datetime string.
- niceShort() publicReturns a formatted descriptive date string for given datetime string.
- serverOffset() publicReturns server's offset
- timeAgoInWords() publicFormats a date into a phrase expressing the relative time.
- toAtom() publicReturns a date formatted for Atom RSS feeds.
- toQuarter() publicReturns the quarter
- toRSS() publicFormats date for RSS feeds
- toUnix() publicReturns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
- wasWithinLast() publicReturns true if specified datetime was within the interval specified, else false.
- wasYesterday() publicReturns true if given datetime string was yesterday.
Method Detail
__call()source public
__call( string $method , array $params )
Call methods from CakeTime utility class
Parameters
- string
$method
- Method to call.
- array
$params
- Parameters to pass to method.
Returns
mixedWhatever is returned by called method, or false on failure
__construct()source public
__construct( View $View , array $settings array() )
Constructor
Settings:
-
engine
Class name to use to replace CakeTime functionality The class needs to be placed in theUtility
directory.
Parameters
-
View
$View
- the view object the helper is attached to.
- array
$settings
optional array() - Settings array
Throws
CakeException
When the engine class could not be found.
__get()source public
__get( string $name )
Magic accessor for attributes that were deprecated.
Parameters
- string
$name
- Name of the attribute to get.
Returns
mixed__isset()source public
__isset( string $name )
Magic isset check for deprecated attributes.
Parameters
- string
$name
- Name of the attribute to check.
Returns
boolean|null__set()source public
__set( string $name , string $value )
Magic accessor for deprecated attributes.
Parameters
- string
$name
- Name of the attribute to set.
- string
$value
- Value of the attribute to set.
convert()source public
convert( string $serverTime , string|DateTimeZone $timezone )
Converts given time (in server's time zone) to user's local time, given his/her timezone.
Parameters
- string
$serverTime
- UNIX timestamp
- string|DateTimeZone
$timezone
- User's timezone string or DateTimeZone object
Returns
integerUNIX timestamp
See
CakeTime::convert()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingconvertSpecifiers()source public
convertSpecifiers( string $format , string $time null )
Converts a string representing the format for the function strftime and returns a Windows safe and i18n aware format.
Parameters
- string
$format
Format with specifiers for strftime function. Accepts the special specifier %S which mimics the modifier S for date()
- string
$time
optional null - UNIX timestamp
Returns
stringWindows safe and date() function compatible format for strftime
See
CakeTime::convertSpecifiers()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingdayAsSql()source public
dayAsSql( integer|string|DateTime $dateString , string $fieldName , string|DateTimeZone $timezone null )
Returns a partial SQL string to search for all records between two times occurring on the same day.
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string
$fieldName
- Name of database field to compare with
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
stringPartial SQL string.
See
CakeTime::dayAsSql()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingdaysAsSql()source public
daysAsSql( integer|string|DateTime $begin , integer|string|DateTime $end , string $fieldName , string|DateTimeZone $timezone null )
Returns a partial SQL string to search for all records between two dates.
Parameters
- integer|string|DateTime
$begin
- UNIX timestamp, strtotime() valid string or DateTime object
- integer|string|DateTime
$end
- UNIX timestamp, strtotime() valid string or DateTime object
- string
$fieldName
- Name of database field to compare with
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
stringPartial SQL string.
See
CakeTime::daysAsSql()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingformat()source public
format( integer|string|DateTime $format , integer|string|DateTime $date null , boolean $invalid false , string|DateTimeZone $timezone null )
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 because 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
Parameters
- integer|string|DateTime
$format
- date format string (or a UNIX timestamp, strtotime() valid string or DateTime object)
- integer|string|DateTime
$date
optional null - UNIX timestamp, strtotime() valid string or DateTime object (or a date format string)
- boolean
$invalid
optional false - flag to ignore results of fromString == false
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
stringFormatted date string
See
CakeTime::format()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingfromString()source public
fromString( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
stringParsed timestamp
See
CakeTime::fromString()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattinggmt()source public
gmt( integer|string|DateTime $string null )
Returns gmt as a UNIX timestamp.
Parameters
- integer|string|DateTime
$string
optional null - UNIX timestamp, strtotime() valid string or DateTime object
Returns
integerUNIX timestamp
See
CakeTime::gmt()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingi18nFormat()source public
i18nFormat( integer|string|DateTime $date , string $format null , boolean $invalid false , string|DateTimeZone $timezone null )
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.
Parameters
- integer|string|DateTime
$date
- UNIX timestamp, strtotime() valid string or DateTime object
- string
$format
optional null - strftime format string.
- boolean
$invalid
optional false - flag to ignore results of fromString == false
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
stringFormatted and translated date string
See
CakeTime::i18nFormat()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingisThisMonth()source public
isThisMonth( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is within this month
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
booleanTrue if datetime string is within current month
See
CakeTime::isThisMonth()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-timeisThisWeek()source public
isThisWeek( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is within this week.
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
booleanTrue if datetime string is within current week
See
CakeTime::isThisWeek()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-timeisThisYear()source public
isThisYear( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is within current year.
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
booleanTrue if datetime string is within current year
See
CakeTime::isThisYear()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-timeisToday()source public
isToday( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is today.
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
booleanTrue if datetime string is today
See
CakeTime::isToday()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-timeisTomorrow()source public
isTomorrow( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is tomorrow.
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
booleanTrue if datetime string was yesterday
See
CakeTime::isTomorrow()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-timeisWithinNext()source public
isWithinNext( string|integer $timeInterval , integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if specified datetime is within the interval specified, else false.
Parameters
- string|integer
$timeInterval
the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
booleanSee
CakeTime::isWithinLast()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-timenice()source public
nice( integer|string|DateTime $dateString null , string|DateTimeZone $timezone null , string $format null )
Returns a nicely formatted date string for given Datetime string.
Parameters
- integer|string|DateTime
$dateString
optional null - UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
- string
$format
optional null - The format to use. If null,
CakeTime::$niceFormat
is used
Returns
stringFormatted date string
See
CakeTime::nice()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingniceShort()source public
niceShort( integer|string|DateTime $dateString null , string|DateTimeZone $timezone null )
Returns a formatted descriptive date string for given datetime string.
Parameters
- integer|string|DateTime
$dateString
optional null - UNIX timestamp, strtotime() valid string or DateTime object.
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
stringDescribed, relative date string
See
CakeTime::niceShort()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingserverOffset()source public
serverOffset( )
Returns server's offset
Returns
integerOffset
See
CakeTime::serverOffset()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingtimeAgoInWords()source public
timeAgoInWords( integer|string|DateTime $dateTime , array $options array() )
Formats a date into a phrase expressing the relative time.
Addition options
-
element
- The element to wrap the formatted time in. Has a few additional options:-
tag
- The tag to use, defaults to 'span'. -
class
- The class name to use, defaults totime-ago-in-words
. -
title
- Defaults to the $dateTime input.
-
Parameters
- integer|string|DateTime
$dateTime
- UNIX timestamp, strtotime() valid string or DateTime object
- array
$options
optional array() - Default format if timestamp is used in $dateString
Returns
stringRelative time string.
See
CakeTime::timeAgoInWords()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingtoAtom()source public
toAtom( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns a date formatted for Atom RSS feeds.
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
stringFormatted date string
See
CakeTime::toAtom()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingtoQuarter()source public
toQuarter( integer|string|DateTime $dateString , boolean $range false )
Returns the quarter
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- boolean
$range
optional false - if true returns a range in Y-m-d format
Returns
integer|array1, 2, 3, or 4 quarter of year or array if $range true
See
CakeTime::toQuarter()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingtoRSS()source public
toRSS( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Formats date for RSS feeds
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
stringFormatted date string
See
CakeTime::toRSS()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingtoUnix()source public
toUnix( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
integerUnix timestamp
See
CakeTime::toUnix()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formattingwasWithinLast()source public
wasWithinLast( string|integer $timeInterval , integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if specified datetime was within the interval specified, else false.
Parameters
- string|integer
$timeInterval
the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
booleanSee
CakeTime::wasWithinLast()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-timewasYesterday()source public
wasYesterday( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string was yesterday.
Parameters
- integer|string|DateTime
$dateString
- UNIX timestamp, strtotime() valid string or DateTime object
- string|DateTimeZone
$timezone
optional null - User's timezone string or DateTimeZone object
Returns
booleanTrue if datetime string was yesterday
See
CakeTime::wasYesterday()Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-timeProperties detail
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.9/class-TimeHelper.html