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
protectedstdClass
CakeTime instance
Method Summary
-
__call() public
Call methods from CakeTime utility class -
__construct() public
Constructor -
__get() public
Magic accessor for attributes that were deprecated. -
__isset() public
Magic isset check for deprecated attributes. -
__set() public
Magic accessor for deprecated attributes. -
convert() public
Converts 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() public
Returns 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() public
Returns a UNIX timestamp, given either a UNIX timestamp or a valid strtotime() date string. -
gmt() public
Returns 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() public
Returns true if given datetime string is within this month -
isThisWeek() public
Returns true if given datetime string is within this week. -
isThisYear() public
Returns true if given datetime string is within current year. -
isToday() public
Returns true if given datetime string is today. -
isTomorrow() public
Returns true if given datetime string is tomorrow. -
isWithinNext() public
Returns true if specified datetime is within the interval specified, else false. -
nice() public
Returns a nicely formatted date string for given Datetime string. -
niceShort() public
Returns a formatted descriptive date string for given datetime string. -
serverOffset() public
Returns server's offset -
timeAgoInWords() public
Formats a date into a phrase expressing the relative time. -
toAtom() public
Returns a date formatted for Atom RSS feeds. -
toQuarter() public
Returns the quarter -
toRSS() public
Formats date for RSS feeds -
toUnix() public
Returns a UNIX timestamp from a textual datetime description. Wrapper for PHP function strtotime(). -
wasWithinLast() public
Returns true if specified datetime was within the interval specified, else false. -
wasYesterday() public
Returns true if given datetime string was yesterday.
Method Detail
__call() 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
Whatever is returned by called method, or false on failure
__construct() 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
__get() public ¶
__get( string $name )
Magic accessor for attributes that were deprecated.
Parameters
- string $name
- Name of the attribute to get.
Returns
__isset() public ¶
__isset( string $name )
Magic isset check for deprecated attributes.
Parameters
- string $name
- Name of the attribute to check.
Returns
__set() 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() 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
UNIX timestamp
See
Link
convertSpecifiers() 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
windows safe and date() function compatible format for strftime
See
Link
dayAsSql() 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
Partial SQL string.
See
Link
daysAsSql() 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
Partial SQL string.
See
Link
format() 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 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 }}}
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
Formatted date string
See
Link
fromString() 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
Parsed timestamp
See
Link
gmt() 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
UNIX timestamp
See
Link
i18nFormat() 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
Formatted and translated date string
See
Link
isThisMonth() 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
True if datetime string is within current month
See
Link
isThisWeek() 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
True if datetime string is within current week
See
Link
isThisYear() 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
True if datetime string is within current year
See
Link
isToday() 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
True if datetime string is today
See
Link
isTomorrow() 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
True if datetime string was yesterday
See
Link
isWithinNext() 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
See
Link
nice() 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
Formatted date string
See
Link
niceShort() 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 objectp
- string|DateTimeZone $timezone optional null
- User's timezone string or DateTimeZone object
Returns
Described, relative date string
See
Link
serverOffset() public ¶
serverOffset( )
Returns server's offset
Returns
Offset
See
Link
timeAgoInWords() 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
Relative time string.
See
Link
toAtom() 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
Formatted date string
See
Link
toQuarter() 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
1, 2, 3, or 4 quarter of year or array if $range true
See
Link
toRSS() 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
Formatted date string
See
Link
toUnix() 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
Unix timestamp
See
Link
wasWithinLast() 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
See
Link
wasYesterday() 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
True if datetime string was yesterday