Class TimeHelper
Time Helper class for easy use of time data.
Manipulation of time data.
- AppHelper
- TimeHelper
Properties summary
Method Summary
- Call methods from CakeTime utility class
- Constructor
- Magic accessor for attributes that were deprecated.
- Magic isset check for deprecated attributes.
- Magic accessor for deprecated attributes.
- Converts given time (in server's time zone) to user's local time, given his/her timezone.
-
Converts a string representing the format for the function strftime and returns a Windows safe and i18n aware format.
-
Returns a partial SQL string to search for all records between two times occurring on the same day.
- Returns a partial SQL string to search for all records between two dates.
-
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()
- Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string.
- Returns gmt as a UNIX timestamp.
-
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.
- Returns true if given datetime string is within this month
- Returns true if given datetime string is within this week.
- Returns true if given datetime string is within current year.
- Returns true if given datetime string is today.
- Returns true if given datetime string is tomorrow.
- Returns true if specified datetime is within the interval specified, else false.
- Returns a nicely formatted date string for given Datetime string.
- Returns a formatted descriptive date string for given datetime string.
- Returns server's offset
- Formats a date into a phrase expressing the relative time.
- Returns a date formatted for Atom RSS feeds.
- Returns the quarter
- Formats date for RSS feeds
- Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime().
- Returns true if specified datetime was within the interval specified, else false.
- Returns 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
mixed
Whatever 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 the Utility
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
integer
UNIX timestamp
See
CakeTime::convert()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting convertSpecifiers()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
string
Windows safe and date() function compatible format for strftime
See
CakeTime::convertSpecifiers()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting dayAsSql()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
string
Partial SQL string.
See
CakeTime::dayAsSql()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting daysAsSql()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
string
Partial SQL string.
See
CakeTime::daysAsSql()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting 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
string
Formatted date string
See
CakeTime::format()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting fromString()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
string
Parsed timestamp
See
CakeTime::fromString()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting 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
string
Formatted and translated date string
See
CakeTime::i18nFormat()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting isThisMonth()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
boolean
True if datetime string is within current month
See
CakeTime::isThisMonth()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time isThisWeek()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
boolean
True if datetime string is within current week
See
CakeTime::isThisWeek()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time isThisYear()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
boolean
True if datetime string is within current year
See
CakeTime::isThisYear()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time isToday()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
boolean
True if datetime string is today
See
CakeTime::isToday()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time isTomorrow()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
boolean
True if datetime string was yesterday
See
CakeTime::isTomorrow()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time isWithinNext()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
boolean
See
CakeTime::isWithinLast()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time nice()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
string
Formatted date string
See
CakeTime::nice()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting niceShort()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
string
Described, relative date string
See
CakeTime::niceShort()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting timeAgoInWords()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 to time-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
string
Relative time string.
See
CakeTime::timeAgoInWords()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting toAtom()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
string
Formatted date string
See
CakeTime::toAtom()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting toQuarter()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|array
1, 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#formatting 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
string
Formatted date string
See
CakeTime::toRSS()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting toUnix()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
integer
Unix timestamp
See
CakeTime::toUnix()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting wasWithinLast()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
boolean
See
CakeTime::wasWithinLast()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time wasYesterday()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
boolean
True if datetime string was yesterday
See
CakeTime::wasYesterday()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time Properties detail