CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.9 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.9
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper
  • None

Classes

  • CacheHelper
  • FlashHelper
  • FormHelper
  • HtmlHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • MootoolsEngineHelper
  • NumberHelper
  • PaginatorHelper
  • PrototypeEngineHelper
  • RssHelper
  • SessionHelper
  • TextHelper
  • TimeHelper

Class TimeHelper

Time Helper class for easy use of time data.

Manipulation of time data.

AppHelper
Extended by TimeHelper
Package: Cake\View\Helper
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
    CakeTime
    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
mixed
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 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() public ¶

__get( string $name )

Magic accessor for attributes that were deprecated.

Parameters
string $name
Name of the attribute to get.
Returns
mixed

__isset() public ¶

__isset( string $name )

Magic isset check for deprecated attributes.

Parameters
string $name
Name of the attribute to check.
Returns
boolean|null

__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
integer
UNIX timestamp
See
CakeTime::convert()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting

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
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() 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() 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() 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
string
Formatted date string
See
CakeTime::format()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting

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
string
Parsed timestamp
See
CakeTime::fromString()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting

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
integer
UNIX timestamp
See
CakeTime::gmt()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting

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
string
Formatted and translated date string
See
CakeTime::i18nFormat()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting

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
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() 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() 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() 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() 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() 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() 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() 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

serverOffset() public ¶

serverOffset( )

Returns server's offset

Returns
integer
Offset
See
CakeTime::serverOffset()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting

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 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() 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() 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() 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
string
Formatted date string
See
CakeTime::toRSS()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting

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
integer
Unix timestamp
See
CakeTime::toUnix()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting

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
boolean
See
CakeTime::wasWithinLast()
Link
http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#testing-time

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
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

$_engine ¶

protected CakeTime

CakeTime instance

null
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs