$defaultLocale
$defaultLocale : string
The default locale to be used for displaying formatted date strings.
Extends the Date class provided by Chronos.
Adds handy methods and locale-aware formatting helpers
$wordFormat : string|array|integer
The format to use when formatting a time using `Cake\I18n\Date::timeAgoInWords()` and the difference is more than `Cake\I18n\Date::$wordEnd`
None found |
$niceFormat : string|array|integer
The format to use when formatting a time using `Cake\I18n\Date::nice()`
The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details)
It is possible to provide an array of 2 constants. In this case, the first position will be used for formatting the date part of the object and the second position will be used to format the time part.
None found |
$wordAccuracy : array
The format to use when formatting a time using `Date::timeAgoInWords()` and the difference is less than `Date::$wordEnd`
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
$weekOfYear : integer
ISO-8601 week number of year, weeks starting on Monday
None found |
None found |
None found |
None found |
None found |
None found |
None found |
$local : boolean
checks if the timezone is local, true if local, false otherwise
None found |
None found |
None found |
None found |
$_formatters : array<mixed,\IntlDateFormatter>
In-memory cache of date formatters
None found |
$_jsonEncodeFormat : string|array|integer
The format to use when when converting this object to json
The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details)
It is possible to provide an array of 2 constants. In this case, the first position will be used for formatting the date part of the object and the second position will be used to format the time part.
None found |
$_isDateInstance : boolean
Caches whether or not this class is a subclass of a Date or MutableDate
None found |
$toStringFormat : string
Format to use for __toString method when type juggling occurs.
None found |
None found |
$diffFormatter : \Cake\Chronos\DifferenceFormatter
Instance of the diff formatting object.
None found |
None found |
None found |
None found |
None found |
$_toStringFormat : string|array|integer
The format to use when formatting a time using `Cake\I18n\Date::i18nFormat()` and `__toString`
The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details)
It is possible to provide an array of 2 constants. In this case, the first position will be used for formatting the date part of the object and the second position will be used to format the time part.
None found |
getDefaultLocale() : string|null
Gets the default locale.
The default locale string to be used or null.
None found |
setDefaultLocale(string|null $locale = null) : void
Sets the default locale.
string|null | $locale | The default locale string to be used or null. |
None found |
nice(string|\DateTimeZone|null $timezone = null, string|null $locale = null) : string
Returns a nicely formatted date string for this object.
The format to be used is stored in the static property Time::niceFormat
.
string|\DateTimeZone|null | $timezone | Timezone string or DateTimeZone object in which the date will be displayed. The timezone stored for this object will not be changed. |
string|null | $locale | The locale name in which the date should be displayed (e.g. pt-BR) |
Formatted date string
None found |
i18nFormat(string|integer|null $format = null, string|\DateTimeZone|null $timezone = null, string|null $locale = null) : string|integer
Returns a formatted string for this time object using the preferred format and language for the specified locale.
It is possible to specify the desired format for the string to be displayed.
You can either pass IntlDateFormatter
constants as the first argument of this
function, or pass a full ICU date formatting string as specified in the following
resource: http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details.
Additional to IntlDateFormatter
constants and date formatting string you can use
Time::UNIX_TIMESTAMP_FORMAT to get a unix timestamp
$time = new Time('2014-04-20 22:10');
$time->i18nFormat(); // outputs '4/20/14, 10:10 PM' for the en-US locale
$time->i18nFormat(\IntlDateFormatter::FULL); // Use the full date and time format
$time->i18nFormat([\IntlDateFormatter::FULL, \IntlDateFormatter::SHORT]); // Use full date but short time format
$time->i18nFormat('yyyy-MM-dd HH:mm:ss'); // outputs '2014-04-20 22:10'
$time->i18nFormat(Time::UNIX_TIMESTAMP_FORMAT); // outputs '1398031800'
If you wish to control the default format to be used for this method, you can alter
the value of the static Time::$defaultLocale
variable and set it to one of the
possible formats accepted by this function.
You can read about the available IntlDateFormatter constants at https://secure.php.net/manual/en/class.intldateformatter.php
If you need to display the date in a different timezone than the one being used for this Time object without altering its internal state, you can pass a timezone string or object as the second parameter.
Finally, should you need to use a different locale for displaying this time object, pass a locale string as the third parameter to this function.
$time = new Time('2014-04-20 22:10');
$time->i18nFormat(null, null, 'de-DE');
$time->i18nFormat(\IntlDateFormatter::FULL, 'Europe/Berlin', 'de-DE');
You can control the default locale to be used by setting the static variable
Time::$defaultLocale
to a valid locale string. If empty, the default will be
taken from the intl.default_locale
ini config.
string|integer|null | $format | Format string. |
string|\DateTimeZone|null | $timezone | Timezone string or DateTimeZone object in which the date will be displayed. The timezone stored for this object will not be changed. |
string|null | $locale | The locale name in which the date should be displayed (e.g. pt-BR) |
Formatted and translated date string
None found |
__toString() : string
Format the instance as a string using the set format
None found |
resetToStringFormat() : void
Reset the format used to the default when type juggling a ChronosInterface instance to a string
None found |
setToStringFormat(string $format) : void
Set the default format used when type juggling a ChronosInterface instance to a string
string | $format | The format to use in future __toString() calls. |
None found |
setJsonEncodeFormat(string|array|integer $format) : void
Sets the default format used when converting this object to json
string|array|integer | $format | Format. |
None found |
parseDateTime(string $time, string|array|null $format = null) : static|null
Returns a new Time object after parsing the provided time string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.
When no $format is provided, the toString
format will be used.
If it was impossible to parse the provided time, null will be returned.
Example:
$time = Time::parseDateTime('10/13/2013 12:54am');
$time = Time::parseDateTime('13 Oct, 2013 13:54', 'dd MMM, y H:mm');
$time = Time::parseDateTime('10/10/2015', [IntlDateFormatter::SHORT, -1]);
string | $time | The time string to parse. |
string|array|null | $format | Any format accepted by IntlDateFormatter. |
None found |
parseDate(string $date, string|integer|null $format = null) : static|null
Returns a new Time object after parsing the provided $date string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.
When no $format is provided, the wordFormat
format will be used.
If it was impossible to parse the provided time, null will be returned.
Example:
$time = Time::parseDate('10/13/2013');
$time = Time::parseDate('13 Oct, 2013', 'dd MMM, y');
$time = Time::parseDate('13 Oct, 2013', IntlDateFormatter::SHORT);
string | $date | The date string to parse. |
string|integer|null | $format | Any format accepted by IntlDateFormatter. |
None found |
parseTime(string $time, string|integer|null $format = null) : static|null
Returns a new Time object after parsing the provided $time string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.
When no $format is provided, the IntlDateFormatter::SHORT format will be used.
If it was impossible to parse the provided time, null will be returned.
Example:
$time = Time::parseTime('11:23pm');
string | $time | The time string to parse. |
string|integer|null | $format | Any format accepted by IntlDateFormatter. |
None found |
jsonSerialize() : string
Returns a string that should be serialized when converting this object to json
None found |
diffFormatter(\Cake\Chronos\DifferenceFormatter|null $formatter = null) : \Cake\Chronos\DifferenceFormatter
Get the difference formatter instance or overwrite the current one.
\Cake\Chronos\DifferenceFormatter|null | $formatter | The formatter instance when setting. |
The formatter instance.
None found |
None found |
__construct(string|null $time = 'now')
Create a new mutable Date instance.
Please see the testing aids section (specifically static::setTestNow()) for more on the possibility of this constructor returning a test instance.
Date instances lack time components, however due to limitations in PHP's internal Datetime object the time will always be set to 00:00:00, and the timezone will always be UTC. Normalizing the timezone allows for subtraction/addition to have deterministic results.
string|null | $time | Fixed or relative time |
None found |
toImmutable() : \Cake\Chronos\Date
Create a new immutable instance from current mutable instance.
None found |
None found |
setWeekendDays(array $days) : void
Set weekend days
array | $days | Which days are 'weekends'. |
None found |
eq(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is equal to another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
None found |
ne(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is not equal to another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
None found |
gt(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is greater (after) than another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
None found |
gte(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is greater (after) than or equal to another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
None found |
lt(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is less (before) than another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
None found |
lte(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is less (before) or equal to another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
None found |
between(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2, boolean $equal = true) : boolean
Determines if the instance is between two others
\Cake\Chronos\ChronosInterface | $dt1 | The instance to compare with. |
\Cake\Chronos\ChronosInterface | $dt2 | The instance to compare with. |
boolean | $equal | Indicates if a > and < comparison should be used or <= or >= |
None found |
closest(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2) : \Cake\Chronos\ChronosInterface
Get the closest date from the instance.
\Cake\Chronos\ChronosInterface | $dt1 | The instance to compare with. |
\Cake\Chronos\ChronosInterface | $dt2 | The instance to compare with. |
None found |
farthest(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2) : \Cake\Chronos\ChronosInterface
Get the farthest date from the instance.
\Cake\Chronos\ChronosInterface | $dt1 | The instance to compare with. |
\Cake\Chronos\ChronosInterface | $dt2 | The instance to compare with. |
None found |
min(\Cake\Chronos\ChronosInterface|null $dt = null) : static
Get the minimum instance between a given instance (default now) and the current instance.
\Cake\Chronos\ChronosInterface|null | $dt | The instance to compare with. |
None found |
max(\Cake\Chronos\ChronosInterface|null $dt = null) : static
Get the maximum instance between a given instance (default now) and the current instance.
\Cake\Chronos\ChronosInterface|null | $dt | The instance to compare with. |
None found |
None found |
None found |
None found |
None found |
None found |
isNextWeek() : boolean
Determines if the instance is within the next week
None found |
isLastWeek() : boolean
Determines if the instance is within the last week
None found |
isNextMonth() : boolean
Determines if the instance is within the next month
None found |
isLastMonth() : boolean
Determines if the instance is within the last month
None found |
isNextYear() : boolean
Determines if the instance is within the next year
None found |
isLastYear() : boolean
Determines if the instance is within the last year
None found |
isFuture() : boolean
Determines if the instance is in the future, ie. greater (after) than now
None found |
isPast() : boolean
Determines if the instance is in the past, ie. less (before) than now
None found |
None found |
isSameDay(\Cake\Chronos\ChronosInterface $dt) : boolean
Checks if the passed in date is the same day as the instance current day.
\Cake\Chronos\ChronosInterface | $dt | The instance to check against. |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
isThisWeek() : boolean
Returns true if this object represents a date within the current week
None found |
isThisMonth() : boolean
Returns true if this object represents a date within the current month
None found |
isThisYear() : boolean
Returns true if this object represents a date within the current year
None found |
isBirthday(\Cake\Chronos\ChronosInterface|null $dt = null) : static
Check if its the birthday. Compares the date/month values of the two dates.
\Cake\Chronos\ChronosInterface|null | $dt | The instance to compare with or null to use current day. |
None found |
wasWithinLast(string|integer $timeInterval) : boolean
Returns true this instance happened within the specified interval
string|integer | $timeInterval | the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute. |
None found |
isWithinNext(string|integer $timeInterval) : boolean
Returns true this instance will happen within the specified interval
string|integer | $timeInterval | the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute. |
None found |
None found |
diffInYears(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in years
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInMonths(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in months
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInWeeks(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in weeks
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInDays(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in days
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInDaysFiltered(callable $callback, \Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in days using a filter callable
callable | $callback | The callback to use for filtering. |
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInHoursFiltered(callable $callback, \Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in hours using a filter callable
callable | $callback | The callback to use for filtering. |
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffFiltered(\Cake\Chronos\ChronosInterval $ci, callable $callback, \Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference by the given interval using a filter callable
\Cake\Chronos\ChronosInterval | $ci | An interval to traverse by |
callable | $callback | The callback to use for filtering. |
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInWeekdays(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in weekdays
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInWeekendDays(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in weekend days using a filter
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInHours(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in hours
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInMinutes(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in minutes
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
diffInSeconds(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in seconds
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
None found |
secondsSinceMidnight() : integer
The number of seconds since midnight.
None found |
secondsUntilEndOfDay() : integer
The number of seconds until 23:59:59.
None found |
fromNow(\DateTime|\DateTimeImmutable $datetime) : \DateInterval|boolean
Convenience method for getting the remaining time from a given time.
\DateTime|\DateTimeImmutable | $datetime | The date to get the remaining time from. |
The DateInterval object representing the difference between the two dates or FALSE on failure.
None found |
diffForHumans(\Cake\Chronos\ChronosInterface|null $other = null, boolean $absolute = false) : string
Get the difference in a human readable format.
When comparing a value in the past to default now: 1 hour ago 5 months ago
When comparing a value in the future to default now: 1 hour from now 5 months from now
When comparing a value in the past to another value: 1 hour before 5 months before
When comparing a value in the future to another value: 1 hour after 5 months after
\Cake\Chronos\ChronosInterface|null | $other | The datetime to compare with. |
boolean | $absolute | removes time difference modifiers ago, after, etc |
None found |
instance(\DateTimeInterface $dt) : static
Create a ChronosInterface instance from a DateTimeInterface one
\DateTimeInterface | $dt | The datetime instance to convert. |
None found |
parse(string $time = 'now', \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from a string. This is an alias for the constructor that allows better fluent syntax as it allows you to do ChronosInterface::parse('Monday next week')->fn() rather than (new Chronos('Monday next week'))->fn()
string | $time | The strtotime compatible string to parse |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name. |
None found |
now(\DateTimeZone|string|null $tz = null) : static
Get a ChronosInterface instance for the current date and time
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name. |
None found |
today(\DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance for today
\DateTimeZone|string|null | $tz | The timezone to use. |
None found |
tomorrow(\DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance for tomorrow
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
None found |
yesterday(\DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance for yesterday
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
None found |
maxValue() : \Cake\Chronos\ChronosInterface
Create a ChronosInterface instance for the greatest supported date.
None found |
minValue() : \Cake\Chronos\ChronosInterface
Create a ChronosInterface instance for the lowest supported date.
None found |
create(integer|null $year = null, integer|null $month = null, integer|null $day = null, integer|null $hour = null, integer|null $minute = null, integer|null $second = null, \DateTimeZone|string|null $tz = null) : static
Create a new ChronosInterface instance from a specific date and time.
If any of $year, $month or $day are set to null their now() values will be used.
If $hour is null it will be set to its now() value and the default values for $minute and $second will be their now() values. If $hour is not null then the default values for $minute and $second will be 0.
integer|null | $year | The year to create an instance with. |
integer|null | $month | The month to create an instance with. |
integer|null | $day | The day to create an instance with. |
integer|null | $hour | The hour to create an instance with. |
integer|null | $minute | The minute to create an instance with. |
integer|null | $second | The second to create an instance with. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
None found |
createFromDate(integer $year = null, integer $month = null, integer $day = null, \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from just a date. The time portion is set to now.
integer | $year | The year to create an instance with. |
integer | $month | The month to create an instance with. |
integer | $day | The day to create an instance with. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
None found |
createFromTime(integer|null $hour = null, integer|null $minute = null, integer|null $second = null, \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from just a time. The date portion is set to today.
integer|null | $hour | The hour to create an instance with. |
integer|null | $minute | The minute to create an instance with. |
integer|null | $second | The second to create an instance with. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
None found |
createFromFormat(string $format, string $time, \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from a specific format
string | $format | The date() compatible format string. |
string | $time | The formatted date string to interpret. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
None found |
createFromTimestamp(integer $timestamp, \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from a timestamp
integer | $timestamp | The timestamp to create an instance from. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
None found |
createFromTimestampUTC(integer $timestamp) : static
Create a ChronosInterface instance from an UTC timestamp
integer | $timestamp | The UTC timestamp to create an instance from. |
None found |
getLastErrors() : array
Returns any errors or warnings that were found during the parsing of the last object created by this class.
None found |
None found |
toFormattedDateString() : string
Format the instance as a readable date
None found |
None found |
None found |
toDayDateTimeString() : string
Format the instance with day, date and time
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
None found |
toQuarter(boolean $range = false) : integer|array
Returns the quarter
boolean | $range | Range. |
1, 2, 3, or 4 quarter of year or array if $range true
None found |
None found |
setTime(integer $hours, integer $minutes, integer $seconds = null, integer $microseconds = null) : static
Modify the time on the Date.
This method ignores all inputs and forces all inputs to 0.
integer | $hours | The hours to set (ignored) |
integer | $minutes | The minutes to set (ignored) |
integer | $seconds | The seconds to set (ignored) |
integer | $microseconds | The microseconds to set (ignored) |
A modified Date instance.
None found |
add(\DateInterval $interval) : static
Add an Interval to a Date
Any changes to the time will be ignored and reset to 00:00:00
\DateInterval | $interval | The interval to modify this date by. |
A modified Date instance
None found |
sub(\DateInterval $interval) : static
Subtract an Interval from a Date.
Any changes to the time will be ignored and reset to 00:00:00
\DateInterval | $interval | The interval to modify this date by. |
A modified Date instance
None found |
timezone(\DateTimeZone|string $value) : $this
No-op method.
Timezones have no effect on calendar dates.
\DateTimeZone|string | $value | The DateTimeZone object or timezone name to use. |
None found |
tz(\DateTimeZone|string $value) : $this
No-op method.
Timezones have no effect on calendar dates.
\DateTimeZone|string | $value | The DateTimeZone object or timezone name to use. |
None found |
setTimezone(\DateTimeZone|string $value) : $this
No-op method.
Timezones have no effect on calendar dates.
\DateTimeZone|string | $value | The DateTimeZone object or timezone name to use. |
None found |
setTimestamp(integer $value) : static
Set the timestamp value and get a new object back.
This method will discard the time aspects of the timestamp and only apply the date portions
integer | $value | The timestamp value to set. |
None found |
modify(string $relative) : static
Overloaded to ignore time changes.
Changing any aspect of the time will be ignored, and the resulting object will have its time frozen to 00:00:00.
string | $relative | The relative change to make. |
A new date with the applied date changes.
None found |
__get(string $name) : string|integer|\DateTimeZone
Get a part of the ChronosInterface object
string | $name | The property name to read. |
The property value.
None found |
__isset(string $name) : boolean
Check if an attribute exists on the object
string | $name | The property name to check. |
Whether or not the property exists.
None found |
None found |
setWeekStartsAt(integer $day) : void
Set the first day of week
integer | $day | The day the week starts with. |
None found |
None found |
setWeekEndsAt(integer $day) : void
Set the last day of week
integer | $day | The day the week ends with. |
None found |
setDate(integer $year, integer $month, integer $day) : static
Set the date to a different date.
Workaround for a PHP bug related to the first day of a month
integer | $year | The year to set. |
integer | $month | The month to set. |
integer | $day | The day to set. |
None found |
setDateTime(integer $year, integer $month, integer $day, integer $hour, integer $minute, integer $second) : static
Set the date and time all together
integer | $year | The year to set. |
integer | $month | The month to set. |
integer | $day | The day to set. |
integer | $hour | The hour to set. |
integer | $minute | The minute to set. |
integer | $second | The second to set. |
None found |
setTimeFromTimeString(string $time) : static
Set the time by time string
string | $time | Time as string. |
None found |
timestamp(integer $value) : static
Set the instance's timestamp
integer | $value | The timestamp value to set. |
None found |
year(integer $value) : static
Set the instance's year
integer | $value | The year value. |
None found |
month(integer $value) : static
Set the instance's month
integer | $value | The month value. |
None found |
day(integer $value) : static
Set the instance's day
integer | $value | The day value. |
None found |
hour(integer $value) : static
Set the instance's hour
integer | $value | The hour value. |
None found |
minute(integer $value) : static
Set the instance's minute
integer | $value | The minute value. |
None found |
second(integer $value) : static
Set the instance's second
integer | $value | The seconds value. |
None found |
addYears(integer $value) : static
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
integer | $value | The number of years to add. |
None found |
addYear(integer $value = 1) : static
Add a year to the instance
integer | $value | The number of years to add. |
None found |
subYear(integer $value = 1) : static
Remove a year from the instance
integer | $value | The number of years to remove. |
None found |
subYears(integer $value) : static
Remove years from the instance.
integer | $value | The number of years to remove. |
None found |
addMonths(integer $value) : static
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month.
(new Chronos('2015-01-03'))->addMonths(1); // Results in 2015-02-03
(new Chronos('2015-01-31'))->addMonths(1); // Results in 2015-02-28
integer | $value | The number of months to add. |
None found |
addMonth(integer $value = 1) : static
Add a month to the instance
When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month.
(new Chronos('2015-01-03'))->addMonth(); // Results in 2015-02-03
(new Chronos('2015-01-31'))->addMonth(); // Results in 2015-02-28
integer | $value | The number of months to add. |
None found |
subMonth(integer $value = 1) : static
Remove a month from the instance
When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month.
(new Chronos('2015-03-01'))->subMonth(); // Results in 2015-02-01
(new Chronos('2015-03-31'))->subMonth(); // Results in 2015-02-28
integer | $value | The number of months to remove. |
None found |
subMonths(integer $value) : static
Remove months from the instance
When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month.
(new Chronos('2015-03-01'))->subMonths(1); // Results in 2015-02-01
(new Chronos('2015-03-31'))->subMonths(1); // Results in 2015-02-28
integer | $value | The number of months to remove. |
None found |
addMonthsWithOverflow(integer $value) : static
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
integer | $value | The number of months to add. |
None found |
addMonthWithOverflow(integer $value = 1) : static
Add a month with overflow to the instance
integer | $value | The number of months to add. |
None found |
subMonthWithOverflow(integer $value = 1) : static
Remove a month with overflow from the instance
integer | $value | The number of months to remove. |
None found |
subMonthsWithOverflow(integer $value) : static
Remove months with overflow from the instance
integer | $value | The number of months to remove. |
None found |
addDays(integer $value) : static
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
integer | $value | The number of days to add. |
None found |
addDay(integer $value = 1) : static
Add a day to the instance
integer | $value | The number of days to add. |
None found |
subDay(integer $value = 1) : static
Remove a day from the instance
integer | $value | The number of days to remove. |
None found |
subDays(integer $value) : static
Remove days from the instance
integer | $value | The number of days to remove. |
None found |
addWeekdays(integer $value) : static
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
integer | $value | The number of weekdays to add. |
None found |
addWeekday(integer $value = 1) : static
Add a weekday to the instance
integer | $value | The number of weekdays to add. |
None found |
subWeekdays(integer $value) : static
Remove weekdays from the instance
integer | $value | The number of weekdays to remove. |
None found |
subWeekday(integer $value = 1) : static
Remove a weekday from the instance
integer | $value | The number of weekdays to remove. |
None found |
addWeeks(integer $value) : static
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
integer | $value | The number of weeks to add. |
None found |
addWeek(integer $value = 1) : static
Add a week to the instance
integer | $value | The number of weeks to add. |
None found |
subWeek(integer $value = 1) : static
Remove a week from the instance
integer | $value | The number of weeks to remove. |
None found |
subWeeks(integer $value) : static
Remove weeks to the instance
integer | $value | The number of weeks to remove. |
None found |
addHours(integer $value) : static
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
integer | $value | The number of hours to add. |
None found |
addHour(integer $value = 1) : static
Add an hour to the instance
integer | $value | The number of hours to add. |
None found |
subHour(integer $value = 1) : static
Remove an hour from the instance
integer | $value | The number of hours to remove. |
None found |
subHours(integer $value) : static
Remove hours from the instance
integer | $value | The number of hours to remove. |
None found |
addMinutes(integer $value) : static
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
integer | $value | The number of minutes to add. |
None found |
addMinute(integer $value = 1) : static
Add a minute to the instance
integer | $value | The number of minutes to add. |
None found |
subMinute(integer $value = 1) : static
Remove a minute from the instance
integer | $value | The number of minutes to remove. |
None found |
subMinutes(integer $value) : static
Remove minutes from the instance
integer | $value | The number of minutes to remove. |
None found |
addSeconds(integer $value) : static
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
integer | $value | The number of seconds to add. |
None found |
addSecond(integer $value = 1) : static
Add a second to the instance
integer | $value | The number of seconds to add. |
None found |
subSecond(integer $value = 1) : static
Remove a second from the instance
integer | $value | The number of seconds to remove. |
None found |
subSeconds(integer $value) : static
Remove seconds from the instance
integer | $value | The number of seconds to remove. |
None found |
None found |
None found |
startOfMonth() : static
Resets the date to the first day of the month and the time to 00:00:00
None found |
endOfMonth() : static
Resets the date to end of the month and time to 23:59:59
None found |
startOfYear() : static
Resets the date to the first day of the year and the time to 00:00:00
None found |
endOfYear() : static
Resets the date to end of the year and time to 23:59:59
None found |
startOfDecade() : static
Resets the date to the first day of the decade and the time to 00:00:00
None found |
endOfDecade() : static
Resets the date to end of the decade and time to 23:59:59
None found |
startOfCentury() : static
Resets the date to the first day of the century and the time to 00:00:00
None found |
endOfCentury() : static
Resets the date to end of the century and time to 23:59:59
None found |
startOfWeek() : static
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
None found |
endOfWeek() : static
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
None found |
next(integer|null $dayOfWeek = null) : mixed
Modify to the next occurrence of a given day of the week.
If no dayOfWeek is provided, modify to the next occurrence of the current day of the week. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
None found |
previous(integer|null $dayOfWeek = null) : mixed
Modify to the previous occurrence of a given day of the week.
If no dayOfWeek is provided, modify to the previous occurrence of the current day of the week. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
None found |
firstOfMonth(integer|null $dayOfWeek = null) : mixed
Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
None found |
lastOfMonth(integer|null $dayOfWeek = null) : mixed
Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
None found |
nthOfMonth(integer $nth, integer $dayOfWeek) : mixed
Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer | $nth | The offset to use. |
integer | $dayOfWeek | The day of the week to move to. |
None found |
firstOfQuarter(integer|null $dayOfWeek = null) : mixed
Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
None found |
lastOfQuarter(integer|null $dayOfWeek = null) : mixed
Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
None found |
nthOfQuarter(integer $nth, integer $dayOfWeek) : mixed
Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.
Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer | $nth | The offset to use. |
integer | $dayOfWeek | The day of the week to move to. |
None found |
firstOfYear(integer|null $dayOfWeek = null) : mixed
Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
None found |
lastOfYear(integer|null $dayOfWeek = null) : mixed
Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
None found |
nthOfYear(integer $nth, integer $dayOfWeek) : mixed
Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.
Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer | $nth | The offset to use. |
integer | $dayOfWeek | The day of the week to move to. |
None found |
average(\Cake\Chronos\ChronosInterface|null $dt = null) : static
Modify the current instance to the average of a given instance (default now) and the current instance.
\Cake\Chronos\ChronosInterface|null | $dt | The instance to compare with. |
None found |
setTestNow(\Cake\Chronos\ChronosInterface|string|null $testNow = null) : void
Set the test now used by Date and Time classes provided by Chronos
\Cake\Chronos\ChronosInterface|string|null | $testNow | The instance to use for all future instances. |
None found |
getTestNow() : static|null
Get the test instance stored in Chronos
the current instance used for testing or null.
None found |
hasTestNow() : boolean
Get whether or not Chronos has a test instance set.
True if there is a test instance, otherwise false
None found |
timeAgoInWords(array $options = array()) : string
Returns either a relative or a formatted absolute date depending on the difference between the current date and this object.
from
=> another Date object representing the "now" dateformat
=> 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)
end
=> The end of relative date tellingrelativeString
=> The printf compatible string when outputting relative dateabsoluteString
=> The printf compatible string when outputting absolute datetimezone
=> 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. Formatting is done internally using
i18nFormat
, see the method for the valid formatting strings.
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.
array | $options | Array of options. |
Relative time string.
None found |
_formatObject(\DateTime $date, string|integer|array $format, string $locale) : string
Returns a translated and localized date string.
Implements what IntlDateFormatter::formatObject() is in PHP 5.5+
\DateTime | $date | Date. |
string|integer|array | $format | Format. |
string | $locale | The locale name in which the date should be displayed. |
None found |
safeCreateDateTimeZone(\DateTimeZone|string|null $object) : \DateTimeZone
Creates a DateTimeZone from a string or a DateTimeZone
\DateTimeZone|string|null | $object | The value to convert. |
None found |
stripTime(string|integer $time) : string
Removes the time components from an input string.
Used to ensure constructed objects always lack time.
string|integer | $time | The input time. Integer values will be assumed to be in UTC. The 'now' and '' values will use the current local time. |
The date component of $time.
None found |
stripRelativeTime(string $time) : string
Remove time components from strtotime relative strings.
string | $time | The input expression |
The output expression with no time modifiers.
None found |
setDateParent(integer $year, integer $month, integer $day) : static
Just calling to parent setDate It used in overwritten setDate
integer | $year | The year to set. |
integer | $month | The month to set. |
integer | $day | The day to set. |
None found |