Time Helper class for easy use of time data.
Manipulation of time data.
__get( string $name )
Magic set method for backwards compatibility. Used by TimeHelper to get static variables in CakeTime
$name
mixed
__set( string $name , mixes $value )
Magic set method for backwards compatibility. Used by TimeHelper to modify static variables in CakeTime
$name
$value
_strftime( string $format , integer $date )
Multibyte wrapper for strftime.
Handles utf8_encoding the result of strftime when necessary.
$format
$date
string
_translateSpecifier( array $specifier )
Auxiliary function to translate a matched specifier element from a regular expression into a Windows safe and i18n aware specifier
$specifier
string
convert( string $serverTime , string|DateTimeZone $timezone )
Converts given time (in server's time zone) to user's local time, given his/her timezone.
$serverTime
$timezone
integer
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.
$format
$time
optional null string
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.
$dateString
$fieldName
$timezone
optional null string
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.
$begin
$end
$fieldName
$timezone
optional null string
format( integer|string|DateTime $date , integer|string|DateTime $format null , boolean|string $default 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()
Create localized & formatted time:
CakeTime::format('2012-02-15', '%m-%d-%Y'); // returns 02-15-2012 CakeTime::format('2012-02-15 23:01:01', '%c'); // returns preferred date and time based on configured locale CakeTime::format('0000-00-00', '%d-%m-%Y', 'N/A'); // return N/A becuase an invalid date was passed CakeTime::format('2012-02-15 23:01:01', '%c', 'N/A', 'America/New_York'); // converts passed date to timezone
$date
$format
optional null $default
optional false $timezone
optional null string
CakeTime::i18nFormat()
fromString( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
$dateString
$timezone
optional null string
gmt( integer|string|DateTime $dateString null )
Returns gmt as a UNIX timestamp.
$dateString
optional null integer
i18nFormat( integer|string|DateTime $date , string $format null , boolean|string $default 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.
$date
$format
optional null $default
optional false $timezone
optional null string
isFuture( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is in the future.
$dateString
$timezone
optional null boolean
isPast( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is in the past.
$dateString
$timezone
optional null boolean
isThisMonth( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is within this month
$dateString
$timezone
optional null boolean
isThisWeek( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is within this week.
$dateString
$timezone
optional null boolean
isThisYear( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is within current year.
$dateString
$timezone
optional null boolean
isToday( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is today.
$dateString
$timezone
optional null boolean
isTomorrow( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string is tomorrow.
$dateString
$timezone
optional null boolean
isWithinNext( string|integer $timeInterval , integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if specified datetime is within the interval specified, else false.
$timeInterval
$dateString
$timezone
optional null boolean
listTimezones( integer|string $filter null , string $country null , boolean $group true )
Get list of timezone identifiers
$filter
optional null $country
optional null $group
optional true array
nice( integer|string|DateTime $dateString null , string|DateTimeZone $timezone null , string $format null )
Returns a nicely formatted date string for given Datetime string.
See http://php.net/manual/en/function.strftime.php for information on formatting using locale strings.
$dateString
optional null $timezone
optional null $format
optional null CakeTime::$niceFormat
is usedstring
niceShort( integer|string|DateTime $dateString null , string|DateTimeZone $timezone null )
Returns a formatted descriptive date string for given datetime string.
If the given date is today, the returned string could be "Today, 16:54". If the given date is tomorrow, the returned string could be "Tomorrow, 16:54". If the given date was yesterday, the returned string could be "Yesterday, 16:54". If the given date is within next or last week, the returned string could be "On Thursday, 16:54". If $dateString's year is the current year, the returned string does not include mention of the year.
$dateString
optional null $timezone
optional null string
serverOffset( )
Returns server's offset from GMT in seconds.
integer
timeAgoInWords( integer|string|DateTime $dateTime , array $options array() )
Returns either a relative or a formatted absolute date depending on the difference between the current time and given datetime. $datetime should be in a strtotime - parsable format, like MySQL's datetime datatype.
format
=> a fall back format if the relative time is longer than the duration specified by endaccuracy
=> Specifies how accurate the date should be described (array) - year => The format if years > 0 (default "day") - month => The format if months > 0 (default "day") - week => The format if weeks > 0 (default "day") - day => The format if weeks > 0 (default "hour") - hour => The format if hours > 0 (default "minute") - minute => The format if minutes > 0 (default "minute") - second => The format if seconds > 0 (default "second")end
=> The end of relative time tellingrelativeString
=> The printf compatible string when outputting past relative timerelativeStringFuture
=> The printf compatible string when outputting future relative timeabsoluteString
=> The printf compatible string when outputting absolute timeuserOffset
=> Users offset from GMT (in hours) Deprecated use timezone instead.timezone
=> The user timezone the timestamp should be formatted in.Relative dates look something like this:
Default date formatting is d/m/yy e.g: on 18/2/09
The returned string includes 'ago' or 'on' and assumes you'll properly add a word like 'Posted ' before the function output.
NOTE: If the difference is one week or more, the lowest level of accuracy is day
$dateTime
$options
optional array() string
timezone( string|DateTimeZone $timezone null )
Returns a timezone object from a string or the user's timezone object
$timezone
optional null DateTimeZone
toAtom( string $dateString , string|DateTimeZone $timezone null )
Returns a date formatted for Atom RSS feeds.
$dateString
$timezone
optional null string
toQuarter( integer|string|DateTime $dateString , boolean $range false )
Returns the quarter
$dateString
$range
optional false integer|array
toRSS( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Formats date for RSS feeds
$dateString
$timezone
optional null string
toServer( integer|string|DateTime $dateString , string|DateTimeZone $timezone null , string $format 'Y-m-d H:i:s' )
Returns a formatted date in server's timezone.
If a DateTime object is given or the dateString has a timezone segment, the timezone parameter will be ignored.
If no timezone parameter is given and no DateTime object, the passed $dateString will be considered to be in the UTC timezone.
$dateString
$timezone
optional null $format
optional 'Y-m-d H:i:s' mixed
toUnix( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
$dateString
$timezone
optional null integer
wasWithinLast( string|integer $timeInterval , integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if specified datetime was within the interval specified, else false.
$timeInterval
$dateString
$timezone
optional null boolean
wasYesterday( integer|string|DateTime $dateString , string|DateTimeZone $timezone null )
Returns true if given datetime string was yesterday.
$dateString
$timezone
optional null boolean
© 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.
http://api.cakephp.org/2.7/class-CakeTime.html