Class FrozenDate
Extends the Date class provided by Chronos.
Adds handy methods and locale-aware formatting helpers
This object provides an immutable variant of Cake\I18n\Date
Constants summary
-
intDAYS_PER_WEEK7 -
stringDEFAULT_TO_STRING_FORMAT'Y-m-d H:i:s' -
intFRIDAY5 -
intHOURS_PER_DAY24 -
intMINUTES_PER_HOUR60 -
intMONDAY1 -
intMONTHS_PER_QUARTER3 -
intMONTHS_PER_YEAR12 -
intSATURDAY6 -
intSECONDS_PER_MINUTE60 -
intSUNDAY7 -
intTHURSDAY4 -
intTUESDAY2 -
intWEDNESDAY3 -
intWEEKS_PER_YEAR52 -
intYEARS_PER_CENTURY100 -
intYEARS_PER_DECADE10
Properties summary
- $_formatters protected static
\IntlDateFormatter[]In-memory cache of date formatters
- $_jsonEncodeFormat protected static
string|int|int[]|\ClosureThe format to use when converting this object to JSON.
- $_lastErrors protected static
arrayHolds the last error generated by createFromFormat
- $_toStringFormat protected static
string|int|int[]The format to use when formatting a time using
Cake\I18n\Date::i18nFormat()and__toString. This format is also used byparseDateTime(). - $days protected static
arrayNames of days of the week.
- $defaultLocale protected static
string|nullThe default locale to be used for displaying formatted date strings.
- $diffFormatter protected static
\Cake\Chronos\DifferenceFormatterInterfaceInstance of the diff formatting object.
- $lenientParsing protected static
boolWhether lenient parsing is enabled for IntlDateFormatter.
- $niceFormat public static
string|int|int[]The format to use when formatting a time using
Cake\I18n\Date::nice() - $relativePattern protected static
stringRegex for relative period.
- $toStringFormat protected static
stringFormat to use for __toString method when type juggling occurs.
- $weekEndsAt protected static
intLast day of week
- $weekStartsAt protected static
intFirst day of week
- $weekendDays protected static
arrayDays of weekend
- $wordAccuracy public static
string[]The format to use when formatting a time using
Date::timeAgoInWords()and the difference is less thanDate::$wordEnd - $wordEnd public static
stringThe end of relative time telling
- $wordFormat public static
string|int|int[]The format to use when formatting a time using
Cake\I18n\Date::timeAgoInWords()and the difference is more thanCake\I18n\Date::$wordEnd
Method Summary
- addDays() public
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
- addHours() public
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
- addMinutes() public
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonths() public
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonthsWithOverflow() public
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
- addSeconds() public
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
- addWeekdays() public
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
- addWeeks() public
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
- addYears() public
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
- addYearsWithOverflow() public
Add years with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
- average() public
Modify the current instance to the average of a given instance (default now) and the current instance.
- createFromArray() public static
Creates a ChronosInterface instance from an array of date and time values.
- createFromDate() public static
Create a ChronosInterface instance from just a date. The time portion is set to now.
- createFromTime() public static
Create a ChronosInterface instance from just a time. The date portion is set to today.
- firstOfMonth() public
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. static::MONDAY.
- firstOfQuarter() public
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. static::MONDAY.
- firstOfYear() public
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. static::MONDAY.
- getLastErrors() public static
Returns any errors or warnings that were found during the parsing of the last object created by this class.
- hasRelativeKeywords() public static
Determine if there is a relative keyword in the time string, this is to create dates relative to now for test instances. e.g.: next tuesday
- i18nFormat() public
Returns a formatted string for this time object using the preferred format and language for the specified locale.
- jsonSerialize() public
Returns a string that should be serialized when converting this object to JSON
- lastOfMonth() public
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. static::MONDAY.
- lastOfQuarter() public
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. static::MONDAY.
- lastOfYear() public
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. static::MONDAY.
- max() public
Get the maximum instance between a given instance (default now) and the current instance.
- min() public
Get the minimum instance between a given instance (default now) and the current instance.
- modify() public
- nthOfMonth() public
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.
- nthOfQuarter() public
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.
- nthOfYear() public
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.
- parse() public 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()
- parseDate() public static
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.
- parseDateTime() public static
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.
- parseTime() public static
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.
- resetToStringFormat() public static
Resets the format used to the default when converting an instance of this type to a string
- setJsonEncodeFormat() public static
Sets the default format used when converting this object to JSON
- setToStringFormat() public static
Sets the default format used when type converting instances of this type to string
- startOfWeek() public
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
- timeAgoInWords() public
Returns either a relative or a formatted absolute date depending on the difference between the current date and this object.
- toWeek() public
Method Detail
__construct() public
__construct(mixed $time, mixed $tz)
Create a new Date instance.
You can specify the timezone for the $time parameter. This timezone will not be used in any future modifications to the Date instance.
The $timezone parameter is ignored if $time is a DateTimeInterface 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.
Parameters
-
string|int|\DateTimeInterface|null$time optional Fixed or relative time
-
\DateTimeZone|string|null$tz optional The timezone in which the date is taken. Ignored if
$timeis a DateTimeInterface instance.
__debugInfo() public
__debugInfo()
Returns the data that should be displayed when debugging this object
Returns
array__get() public
__get(string $name)
Get a part of the ChronosInterface object
Parameters
-
string$name The property name to read.
Returns
string|int|bool|\DateTimeZoneThe property value.
Throws
InvalidArgumentException__isset() public
__isset(string $name)
Check if an attribute exists on the object
Parameters
-
string$name The property name to check.
Returns
boolWhether or not the property exists.
__toString() public
__toString()
Format the instance as a string using the set format
Returns
string_formatObject() protected
_formatObject(mixed $date, mixed $format, ?string $locale)
Returns a translated and localized date string.
Implements what IntlDateFormatter::formatObject() is in PHP 5.5+
Parameters
-
\DateTime|\DateTimeImmutable$date Date.
-
string|int|int[]$format Format.
-
string|null$locale The locale name in which the date should be displayed.
Returns
stringadd() public
add(mixed $interval)
Add an Interval to a Date
Any changes to the time will be ignored and reset to 00:00:00
Parameters
-
\DateInterval$interval The interval to modify this date by.
Returns
staticA modified Date instance
addDay() public
addDay(int $value)
Add a day to the instance
Parameters
-
int$value optional The number of days to add.
Returns
staticaddDays() public
addDays(int $value)
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of days to add.
Returns
staticaddHour() public
addHour(int $value)
Add an hour to the instance
Parameters
-
int$value optional The number of hours to add.
Returns
staticaddHours() public
addHours(int $value)
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of hours to add.
Returns
staticaddMinute() public
addMinute(int $value)
Add a minute to the instance
Parameters
-
int$value optional The number of minutes to add.
Returns
staticaddMinutes() public
addMinutes(int $value)
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of minutes to add.
Returns
staticaddMonth() public
addMonth(int $value)
Add a month to the instance.
Has the same behavior as addMonths().
Parameters
-
int$value optional The number of months to add.
Returns
staticaddMonthWithOverflow() public
addMonthWithOverflow(int $value)
Add a month with overflow to the instance.
Has the same behavior as addMonthsWithOverflow().
Parameters
-
int$value optional The number of months to add.
Returns
staticaddMonths() public
addMonths(int $value)
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
If the new date does not exist, the last day of the month is used instead instead of overflowing into the next month.
Example:
(new Chronos('2015-01-03'))->addMonths(1); // Results in 2015-02-03
(new Chronos('2015-01-31'))->addMonths(1); // Results in 2015-02-28 Parameters
-
int$value The number of months to add.
Returns
staticaddMonthsWithOverflow() public
addMonthsWithOverflow(int $value)
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
If the new date does not exist, the days overflow into the next month.
Example:
(new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01 Parameters
-
int$value The number of months to add.
Returns
staticaddSecond() public
addSecond(int $value)
Add a second to the instance
Parameters
-
int$value optional The number of seconds to add.
Returns
staticaddSeconds() public
addSeconds(int $value)
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of seconds to add.
Returns
staticaddWeek() public
addWeek(int $value)
Add a week to the instance
Parameters
-
int$value optional The number of weeks to add.
Returns
staticaddWeekday() public
addWeekday(int $value)
Add a weekday to the instance
Parameters
-
int$value optional The number of weekdays to add.
Returns
staticaddWeekdays() public
addWeekdays(int $value)
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of weekdays to add.
Returns
staticaddWeeks() public
addWeeks(int $value)
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of weeks to add.
Returns
staticaddYear() public
addYear(int $value)
Add a year to the instance
Has the same behavior as addYears().
Parameters
-
int$value optional The number of years to add.
Returns
staticaddYearWithOverflow() public
addYearWithOverflow(int $value)
Add a year with overflow to the instance
Has the same behavior as addYearsWithOverflow().
Parameters
-
int$value optional The number of years to add.
Returns
staticaddYears() public
addYears(int $value)
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
If the new date does not exist, the last day of the month is used instead instead of overflowing into the next month.
Example:
(new Chronos('2015-01-03'))->addYears(1); // Results in 2016-01-03
(new Chronos('2012-02-29'))->addYears(1); // Results in 2013-02-28 Parameters
-
int$value The number of years to add.
Returns
staticaddYearsWithOverflow() public
addYearsWithOverflow(int $value)
Add years with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
If the new date does not exist, the days overflow into the next month.
Example:
(new Chronos('2012-02-29'))->addYearsWithOverflow(1); // Results in 2013-03-01 Parameters
-
int$value The number of years to add.
Returns
staticaverage() public
average(?\Cake\Chronos\ChronosInterface $dt)
Modify the current instance to the average of a given instance (default now) and the current instance.
Parameters
-
\Cake\Chronos\ChronosInterface$dt optional The instance to compare with.
Returns
staticbetween() public
between(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2, bool $equal)
Determines if the instance is between two others
Parameters
-
\Cake\Chronos\ChronosInterface$dt1 The instance to compare with.
-
\Cake\Chronos\ChronosInterface$dt2 The instance to compare with.
-
bool$equal optional Indicates if a > and < comparison should be used or <= or >=
Returns
boolclosest() public
closest(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2)
Get the closest date from the instance.
Parameters
-
\Cake\Chronos\ChronosInterface$dt1 The instance to compare with.
-
\Cake\Chronos\ChronosInterface$dt2 The instance to compare with.
Returns
staticcopy() public
copy()
Get a copy of the instance
Returns
staticcreate() public static
create(?int $year, ?int $month, ?int $day, ?int $hour, ?int $minute, ?int $second, ?int $microsecond, mixed $tz)
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, $second and $microsecond will be their now() values. If $hour is not null then the default values for $minute, $second and $microsecond will be 0.
Parameters
-
int|null$year optional The year to create an instance with.
-
int|null$month optional The month to create an instance with.
-
int|null$day optional The day to create an instance with.
-
int|null$hour optional The hour to create an instance with.
-
int|null$minute optional The minute to create an instance with.
-
int|null$second optional The second to create an instance with.
-
int|null$microsecond optional The microsecond to create an instance with.
-
\DateTimeZone|string|null$tz optional The DateTimeZone object or timezone name the new instance should use.
Returns
staticcreateFromArray() public static
createFromArray(array $values)
Creates a ChronosInterface instance from an array of date and time values.
The 'year', 'month' and 'day' values must all be set for a date. The time values all default to 0.
The 'timezone' value can be any format supported by \DateTimeZone.
Allowed values:
- year
- month
- day
- hour
- minute
- second
- microsecond
- meridian ('am' or 'pm')
- timezone
Parameters
-
(int|string)[]$values Array of date and time values.
Returns
staticcreateFromDate() public static
createFromDate(?int $year, ?int $month, ?int $day, mixed $tz)
Create a ChronosInterface instance from just a date. The time portion is set to now.
Parameters
-
int|null$year optional The year to create an instance with.
-
int|null$month optional The month to create an instance with.
-
int|null$day optional The day to create an instance with.
-
\DateTimeZone|string|null$tz optional The DateTimeZone object or timezone name the new instance should use.
Returns
staticcreateFromFormat() public static
createFromFormat(mixed $format, mixed $time, mixed $tz)
Create a ChronosInterface instance from a specific format
Parameters
-
string$format The date() compatible format string.
-
string$time The formatted date string to interpret.
-
\DateTimeZone|string|null$tz optional The DateTimeZone object or timezone name the new instance should use.
Returns
staticThrows
InvalidArgumentExceptioncreateFromTime() public static
createFromTime(?int $hour, ?int $minute, ?int $second, ?int $microsecond, mixed $tz)
Create a ChronosInterface instance from just a time. The date portion is set to today.
Parameters
-
int|null$hour optional The hour to create an instance with.
-
int|null$minute optional The minute to create an instance with.
-
int|null$second optional The second to create an instance with.
-
int|null$microsecond optional The microsecond to create an instance with.
-
\DateTimeZone|string|null$tz optional The DateTimeZone object or timezone name the new instance should use.
Returns
staticcreateFromTimestamp() public static
createFromTimestamp(int $timestamp, mixed $tz)
Create a ChronosInterface instance from a timestamp
Parameters
-
int$timestamp The timestamp to create an instance from.
-
\DateTimeZone|string|null$tz optional The DateTimeZone object or timezone name the new instance should use.
Returns
staticcreateFromTimestampUTC() public static
createFromTimestampUTC(int $timestamp)
Create a ChronosInterface instance from an UTC timestamp
Parameters
-
int$timestamp The UTC timestamp to create an instance from.
Returns
staticday() public
day(int $value)
Set the instance's day
Parameters
-
int$value The day value.
Returns
staticdiffFiltered() public
diffFiltered(\Cake\Chronos\ChronosInterval $ci, callable $callback, ?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference by the given interval using a filter callable
Parameters
-
\Cake\Chronos\ChronosInterval$ci An interval to traverse by
-
callable$callback The callback to use for filtering.
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffForHumans() public
diffForHumans(?\Cake\Chronos\ChronosInterface $other, bool $absolute)
Get the difference in a human readable format in the current locale.
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
Parameters
-
\Cake\Chronos\ChronosInterface|null$other optional The datetime to compare with.
-
bool$absolute optional Removes time difference modifiers ago, after, etc
Returns
stringdiffFormatter() public static
diffFormatter(?\Cake\Chronos\DifferenceFormatterInterface $formatter)
Get the difference formatter instance or overwrite the current one.
Parameters
-
\Cake\Chronos\DifferenceFormatterInterface|null$formatter optional The formatter instance when setting.
Returns
\Cake\Chronos\DifferenceFormatterInterfaceThe formatter instance.
diffInDays() public
diffInDays(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in days
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInDaysFiltered() public
diffInDaysFiltered(callable $callback, ?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in days using a filter callable
Parameters
-
callable$callback The callback to use for filtering.
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInHours() public
diffInHours(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in hours
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInHoursFiltered() public
diffInHoursFiltered(callable $callback, ?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in hours using a filter callable
Parameters
-
callable$callback The callback to use for filtering.
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInMinutes() public
diffInMinutes(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in minutes
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInMonths() public
diffInMonths(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in months
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInSeconds() public
diffInSeconds(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in seconds
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInWeekdays() public
diffInWeekdays(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in weekdays
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInWeekendDays() public
diffInWeekendDays(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in weekend days using a filter
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInWeeks() public
diffInWeeks(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in weeks
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInYears() public
diffInYears(?\Cake\Chronos\ChronosInterface $dt, bool $abs)
Get the difference in years
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdisableLenientParsing() public static
disableLenientParsing()
Enables lenient parsing for locale formats.
enableLenientParsing() public static
enableLenientParsing()
Enables lenient parsing for locale formats.
endOfCentury() public
endOfCentury()
Resets the date to end of the century and time to 23:59:59
Returns
staticendOfDay() public
endOfDay()
Resets the time to 23:59:59
Returns
staticendOfDecade() public
endOfDecade()
Resets the date to end of the decade and time to 23:59:59
Returns
staticendOfMonth() public
endOfMonth()
Resets the date to end of the month and time to 23:59:59
Returns
staticendOfWeek() public
endOfWeek()
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
Returns
staticendOfYear() public
endOfYear()
Resets the date to end of the year and time to 23:59:59
Returns
staticeq() public
eq(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is equal to another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
equals() public
equals(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is equal to another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolfarthest() public
farthest(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2)
Get the farthest date from the instance.
Parameters
-
\Cake\Chronos\ChronosInterface$dt1 The instance to compare with.
-
\Cake\Chronos\ChronosInterface$dt2 The instance to compare with.
Returns
staticfirstOfMonth() public
firstOfMonth(?int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int|null$dayOfWeek optional The day of the week to move to.
Returns
mixedfirstOfQuarter() public
firstOfQuarter(?int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int|null$dayOfWeek optional The day of the week to move to.
Returns
mixedfirstOfYear() public
firstOfYear(?int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int|null$dayOfWeek optional The day of the week to move to.
Returns
mixedfromNow() public static
fromNow(mixed $datetime)
Convenience method for getting the remaining time from a given time.
Parameters
-
\DateTime|\DateTimeImmutable$datetime The date to get the remaining time from.
Returns
\DateInterval|boolThe DateInterval object representing the difference between the two dates or FALSE on failure.
getDefaultLocale() public static
getDefaultLocale()
Gets the default locale.
Returns
string|nullThe default locale string to be used or null.
getDiffFormatter() public static
getDiffFormatter()
Get the difference formatter instance.
Returns
\Cake\Chronos\DifferenceFormatterInterfacegetLastErrors() public static
getLastErrors()
Returns any errors or warnings that were found during the parsing of the last object created by this class.
Returns
arraygetTestNow() public static
getTestNow()
Get the test instance stored in Chronos
Returns
\Cake\Chronos\ChronosInterface|nullthe current instance used for testing or null.
See Also
getWeekEndsAt() public static
getWeekEndsAt()
Get the last day of week
Returns
intgetWeekStartsAt() public static
getWeekStartsAt()
Get the first day of week
Returns
intgetWeekendDays() public static
getWeekendDays()
Get weekend days
Returns
arraygreaterThan() public
greaterThan(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is greater (after) than another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolgreaterThanOrEquals() public
greaterThanOrEquals(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is greater (after) than or equal to another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolgt() public
gt(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is greater (after) than another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
gte() public
gte(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is greater (after) than or equal to another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
hasRelativeKeywords() public static
hasRelativeKeywords(?string $time)
Determine if there is a relative keyword in the time string, this is to create dates relative to now for test instances. e.g.: next tuesday
Parameters
-
string|null$time The time string to check.
Returns
booltrue if there is a keyword, otherwise false
hasTestNow() public static
hasTestNow()
Get whether or not Chronos has a test instance set.
Returns
boolTrue if there is a test instance, otherwise false
See Also
hour() public
hour(int $value)
Set the instance's hour
Parameters
-
int$value The hour value.
Returns
statici18nFormat() public
i18nFormat(mixed $format, mixed $timezone, mixed $locale)
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
Examples
$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' You can control the default format used through Time::setToStringFormat().
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.
Examples
$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 used through Time::setDefaultLocale(). If empty, the default will be taken from the intl.default_locale ini config.
Parameters
-
string|int|int[]|null$format optional Format string.
-
string|\DateTimeZone|null$timezone optional 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 optional The locale name in which the date should be displayed (e.g. pt-BR)
Returns
string|intFormatted and translated date string
instance() public static
instance(\DateTimeInterface $dt)
Create a ChronosInterface instance from a DateTimeInterface one
Parameters
-
\DateTimeInterface$dt The datetime instance to convert.
Returns
staticisBirthday() public
isBirthday(\Cake\Chronos\ChronosInterface $dt)
Check if its the birthday. Compares the date/month values of the two dates.
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolisFriday() public
isFriday()
Checks if this day is a Friday.
Returns
boolisFuture() public
isFuture()
Determines if the instance is in the future, ie. greater (after) than now
Returns
boolisLastMonth() public
isLastMonth()
Determines if the instance is within the last month
Returns
boolisLastWeek() public
isLastWeek()
Determines if the instance is within the last week
Returns
boolisLastYear() public
isLastYear()
Determines if the instance is within the last year
Returns
boolisLeapYear() public
isLeapYear()
Determines if the instance is a leap year
Returns
boolisMonday() public
isMonday()
Checks if this day is a Monday.
Returns
boolisMutable() public
isMutable()
Check if instance of ChronosInterface is mutable.
Returns
boolisNextMonth() public
isNextMonth()
Determines if the instance is within the next month
Returns
boolisNextWeek() public
isNextWeek()
Determines if the instance is within the next week
Returns
boolisNextYear() public
isNextYear()
Determines if the instance is within the next year
Returns
boolisPast() public
isPast()
Determines if the instance is in the past, ie. less (before) than now
Returns
boolisSameDay() public
isSameDay(\Cake\Chronos\ChronosInterface $dt)
Checks if the passed in date is the same day as the instance current day.
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to check against.
Returns
boolisSaturday() public
isSaturday()
Checks if this day is a Saturday.
Returns
boolisSunday() public
isSunday()
Checks if this day is a Sunday.
Returns
boolisThisMonth() public
isThisMonth()
Returns true if this object represents a date within the current month
Returns
boolisThisWeek() public
isThisWeek()
Returns true if this object represents a date within the current week
Returns
boolisThisYear() public
isThisYear()
Returns true if this object represents a date within the current year
Returns
boolisThursday() public
isThursday()
Checks if this day is a Thursday.
Returns
boolisToday() public
isToday()
Determines if the instance is today
Returns
boolisTomorrow() public
isTomorrow()
Determines if the instance is tomorrow
Returns
boolisTuesday() public
isTuesday()
Checks if this day is a Tuesday.
Returns
boolisWednesday() public
isWednesday()
Checks if this day is a Wednesday.
Returns
boolisWeekday() public
isWeekday()
Determines if the instance is a weekday
Returns
boolisWeekend() public
isWeekend()
Determines if the instance is a weekend day
Returns
boolisWithinNext() public
isWithinNext(mixed $timeInterval)
Returns true this instance will happen within the specified interval
Parameters
-
string|int$timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
Returns
boolisYesterday() public
isYesterday()
Determines if the instance is yesterday
Returns
booljsonSerialize() public
jsonSerialize()
Returns a string that should be serialized when converting this object to JSON
Returns
string|intlastOfMonth() public
lastOfMonth(?int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int|null$dayOfWeek optional The day of the week to move to.
Returns
mixedlastOfQuarter() public
lastOfQuarter(?int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int|null$dayOfWeek optional The day of the week to move to.
Returns
mixedlastOfYear() public
lastOfYear(?int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int|null$dayOfWeek optional The day of the week to move to.
Returns
mixedlenientParsingEnabled() public static
lenientParsingEnabled()
Gets whether locale format parsing is set to lenient.
Returns
boollessThan() public
lessThan(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is less (before) than another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boollessThanOrEquals() public
lessThanOrEquals(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is less (before) or equal to another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boollt() public
lt(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is less (before) than another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
lte() public
lte(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is less (before) or equal to another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
max() public
max(?\Cake\Chronos\ChronosInterface $dt)
Get the maximum instance between a given instance (default now) and the current instance.
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to compare with.
Returns
staticmaxValue() public static
maxValue()
Create a ChronosInterface instance for the greatest supported date.
Returns
\Cake\Chronos\ChronosInterfacemin() public
min(?\Cake\Chronos\ChronosInterface $dt)
Get the minimum instance between a given instance (default now) and the current instance.
Parameters
-
\Cake\Chronos\ChronosInterface|null$dt optional The instance to compare with.
Returns
staticminValue() public static
minValue()
Create a ChronosInterface instance for the lowest supported date.
Returns
\Cake\Chronos\ChronosInterfaceminute() public
minute(int $value)
Set the instance's minute
Parameters
-
int$value The minute value.
Returns
staticmodify() public
modify(string $relative)
Parameters
-
string$relative
month() public
month(int $value)
Set the instance's month
Parameters
-
int$value The month value.
Returns
staticne() public
ne(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is not equal to another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
next() public
next(?int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int|null$dayOfWeek optional The day of the week to move to.
Returns
mixednice() public
nice(mixed $timezone, mixed $locale)
Returns a nicely formatted date string for this object.
The format to be used is stored in the static property Time::niceFormat.
Parameters
-
string|\DateTimeZone|null$timezone optional 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 optional The locale name in which the date should be displayed (e.g. pt-BR)
Returns
stringFormatted date string
notEquals() public
notEquals(\Cake\Chronos\ChronosInterface $dt)
Determines if the instance is not equal to another
Parameters
-
\Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolnow() public static
now(mixed $tz)
Get a ChronosInterface instance for the current date and time
Parameters
-
\DateTimeZone|string|null$tz The DateTimeZone object or timezone name.
Returns
staticnthOfMonth() public
nthOfMonth(int $nth, int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int$nth The offset to use.
-
int$dayOfWeek The day of the week to move to.
Returns
mixednthOfQuarter() public
nthOfQuarter(int $nth, int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int$nth The offset to use.
-
int$dayOfWeek The day of the week to move to.
Returns
mixednthOfYear() public
nthOfYear(int $nth, int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int$nth The offset to use.
-
int$dayOfWeek The day of the week to move to.
Returns
mixedparse() public static
parse(mixed $time, mixed $tz)
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()
Parameters
-
\DateTimeInterface|string|int$time optional The strtotime compatible string to parse
-
\DateTimeZone|string|null$tz optional The DateTimeZone object or timezone name.
Returns
staticparseDate() public static
parseDate(string $date, mixed $format)
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); Parameters
-
string$date The date string to parse.
-
string|int|array|null$format optional Any format accepted by IntlDateFormatter.
Returns
static|nullparseDateTime() public static
parseDateTime(string $time, mixed $format, mixed $tz)
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.
Unlike DateTime, the time zone of the returned instance is always converted to $tz (default time zone if null) even if the $time string specified a time zone. This is a limitation of IntlDateFormatter.
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, IntlDateFormatter::NONE]); Parameters
-
string$time The time string to parse.
-
string|int|int[]|null$format optional Any format accepted by IntlDateFormatter.
-
\DateTimeZone|string|null$tz optional The timezone for the instance
Returns
static|nullparseTime() public static
parseTime(string $time, mixed $format)
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'); Parameters
-
string$time The time string to parse.
-
string|int|null$format optional Any format accepted by IntlDateFormatter.
Returns
static|nullprevious() public
previous(?int $dayOfWeek)
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. static::MONDAY.
Parameters
-
int|null$dayOfWeek optional The day of the week to move to.
Returns
mixedresetToStringFormat() public static
resetToStringFormat()
Resets the format used to the default when converting an instance of this type to a string
safeCreateDateTimeZone() protected static
safeCreateDateTimeZone(mixed $object)
Creates a DateTimeZone from a string or a DateTimeZone
Parameters
-
\DateTimeZone|string|null$object The value to convert.
Returns
\DateTimeZoneThrows
InvalidArgumentExceptionsecond() public
second(int $value)
Set the instance's second
Parameters
-
int$value The seconds value.
Returns
staticsecondsSinceMidnight() public
secondsSinceMidnight()
The number of seconds since midnight.
Returns
intsecondsUntilEndOfDay() public
secondsUntilEndOfDay()
The number of seconds until 23:59:59.
Returns
intsetDate() public
setDate(mixed $year, mixed $month, mixed $day)
Set the date to a different date.
Workaround for a PHP bug related to the first day of a month
Parameters
-
int$year The year to set.
-
int$month The month to set.
-
int$day The day to set.
Returns
staticsetDateTime() public
setDateTime(int $year, int $month, int $day, int $hour, int $minute, int $second)
Set the date and time all together
Parameters
-
int$year The year to set.
-
int$month The month to set.
-
int$day The day to set.
-
int$hour The hour to set.
-
int$minute The minute to set.
-
int$second optional The second to set.
Returns
staticsetDefaultLocale() public static
setDefaultLocale(?string $locale)
Sets the default locale.
Set to null to use IntlDateFormatter default.
Parameters
-
string|null$locale optional The default locale string to be used.
setDiffFormatter() public static
setDiffFormatter(\Cake\Chronos\DifferenceFormatterInterface $formatter)
Set the difference formatter instance.
Parameters
-
\Cake\Chronos\DifferenceFormatterInterface$formatter The formatter instance when setting.
setJsonEncodeFormat() public static
setJsonEncodeFormat(mixed $format)
Sets the default format used 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.
Alternatively, the format can provide a callback. In this case, the callback can receive this datetime object and return a formatted string.
Parameters
-
string|array|int|\Closure$format Format.
See Also
setTestNow() public static
setTestNow(mixed $testNow)
Set the test now used by Date and Time classes provided by Chronos
Parameters
-
\Cake\Chronos\ChronosInterface|string|null$testNow optional The instance to use for all future instances.
See Also
setTime() public
setTime(mixed $hours, mixed $minutes, mixed $seconds, mixed $microseconds)
Modify the time on the Date.
This method ignores all inputs and forces all inputs to 0.
Parameters
-
int$hours The hours to set (ignored)
-
int$minutes The minutes to set (ignored)
-
int$seconds optional The seconds to set (ignored)
-
int$microseconds optional The microseconds to set (ignored)
Returns
staticA modified Date instance.
setTimeFromTimeString() public
setTimeFromTimeString(string $time)
Set the time by time string
Parameters
-
string$time Time as string.
Returns
staticsetTimestamp() public
setTimestamp(mixed $value)
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
Parameters
-
int$value The timestamp value to set.
Returns
staticsetTimezone() public
setTimezone(mixed $value)
Set the instance's timezone from a string or object
Parameters
-
\DateTimeZone|string$value The DateTimeZone object or timezone name to use.
Returns
staticsetToStringFormat() public static
setToStringFormat(mixed $format)
Sets the default format used when type converting instances of this type to string
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.
Parameters
-
string|int|int[]$format Format.
setWeekEndsAt() public static
setWeekEndsAt(int $day)
Set the last day of week
Parameters
-
int$day The day the week ends with.
setWeekStartsAt() public static
setWeekStartsAt(int $day)
Set the first day of week
Parameters
-
int$day The day the week starts with.
setWeekendDays() public static
setWeekendDays(array $days)
Set weekend days
Parameters
-
array$days Which days are 'weekends'.
startOfCentury() public
startOfCentury()
Resets the date to the first day of the century and the time to 00:00:00
Returns
staticstartOfDay() public
startOfDay()
Resets the time to 00:00:00
Returns
staticstartOfDecade() public
startOfDecade()
Resets the date to the first day of the decade and the time to 00:00:00
Returns
staticstartOfMonth() public
startOfMonth()
Resets the date to the first day of the month and the time to 00:00:00
Returns
staticstartOfWeek() public
startOfWeek()
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
Returns
staticstartOfYear() public
startOfYear()
Resets the date to the first day of the year and the time to 00:00:00
Returns
staticstripRelativeTime() protected
stripRelativeTime(string $time)
Remove time components from strtotime relative strings.
Parameters
-
string$time The input expression
Returns
stringThe output expression with no time modifiers.
stripTime() protected
stripTime(mixed $time, mixed $tz)
Removes the time components from an input string.
Used to ensure constructed objects always lack time.
Parameters
-
\DateTime|\DateTimeImmutable|string|int|null$time The input time. Integer values will be assumed to be in UTC. The 'now' and '' values will use the current local time.
-
\DateTimeZone|null$tz The timezone in which the date is taken
Returns
stringThe date component of $time.
sub() public
sub(mixed $interval)
Subtract an Interval from a Date.
Any changes to the time will be ignored and reset to 00:00:00
Parameters
-
\DateInterval$interval The interval to modify this date by.
Returns
staticA modified Date instance
subDay() public
subDay(int $value)
Remove a day from the instance
Parameters
-
int$value optional The number of days to remove.
Returns
staticsubDays() public
subDays(int $value)
Remove days from the instance
Parameters
-
int$value The number of days to remove.
Returns
staticsubHour() public
subHour(int $value)
Remove an hour from the instance
Parameters
-
int$value optional The number of hours to remove.
Returns
staticsubHours() public
subHours(int $value)
Remove hours from the instance
Parameters
-
int$value The number of hours to remove.
Returns
staticsubMinute() public
subMinute(int $value)
Remove a minute from the instance
Parameters
-
int$value optional The number of minutes to remove.
Returns
staticsubMinutes() public
subMinutes(int $value)
Remove minutes from the instance
Parameters
-
int$value The number of minutes to remove.
Returns
staticsubMonth() public
subMonth(int $value)
Remove a month from the instance
Has the same behavior as addMonths().
Parameters
-
int$value optional The number of months to remove.
Returns
staticsubMonthWithOverflow() public
subMonthWithOverflow(int $value)
Remove a month with overflow from the instance.
Has the same behavior as addMonthsWithOverflow().
Parameters
-
int$value optional The number of months to remove.
Returns
staticsubMonths() public
subMonths(int $value)
Remove months from the instance.
Has the same behavior as addMonths().
Parameters
-
int$value The number of months to remove.
Returns
staticsubMonthsWithOverflow() public
subMonthsWithOverflow(int $value)
Remove months with overflow from the instance.
Has the same behavior as addMonthsWithOverflow().
Parameters
-
int$value The number of months to remove.
Returns
staticsubSecond() public
subSecond(int $value)
Remove a second from the instance
Parameters
-
int$value optional The number of seconds to remove.
Returns
staticsubSeconds() public
subSeconds(int $value)
Remove seconds from the instance
Parameters
-
int$value The number of seconds to remove.
Returns
staticsubWeek() public
subWeek(int $value)
Remove a week from the instance
Parameters
-
int$value optional The number of weeks to remove.
Returns
staticsubWeekday() public
subWeekday(int $value)
Remove a weekday from the instance
Parameters
-
int$value optional The number of weekdays to remove.
Returns
staticsubWeekdays() public
subWeekdays(int $value)
Remove weekdays from the instance
Parameters
-
int$value The number of weekdays to remove.
Returns
staticsubWeeks() public
subWeeks(int $value)
Remove weeks to the instance
Parameters
-
int$value The number of weeks to remove.
Returns
staticsubYear() public
subYear(int $value)
Remove a year from the instance.
Has the same behavior as addYears().
Parameters
-
int$value optional The number of years to remove.
Returns
staticsubYearWithOverflow() public
subYearWithOverflow(int $value)
Remove a year with overflow from the instance
Has the same behavior as addYearsWithOverflow().
Parameters
-
int$value optional The number of years to remove.
Returns
staticsubYears() public
subYears(int $value)
Remove years from the instance.
Has the same behavior as addYears().
Parameters
-
int$value The number of years to remove.
Returns
staticsubYearsWithOverflow() public
subYearsWithOverflow(int $value)
Remove years with overflow from the instance
Has the same behavior as addYearsWithOverflow().
Parameters
-
int$value The number of years to remove.
Returns
statictimeAgoInWords() public
timeAgoInWords(array $options)
Returns either a relative or a formatted absolute date depending on the difference between the current date and this object.
Options:
-
from=> another Date object representing the "now" date -
format=> a fall back format if the relative time is longer than the duration specified by end -
accuracy=> Specifies how accurate the date should be described (array)- year => The format if years > 0 (default "day")
- month => The format if months > 0 (default "day")
- week => The format if weeks > 0 (default "day")
- day => The format if weeks > 0 (default "day")
-
end=> The end of relative date telling -
relativeString=> The printf compatible string when outputting relative date -
absoluteString=> The printf compatible string when outputting absolute date -
timezone=> The user timezone the timestamp should be formatted in.
Relative dates look something like this:
- 3 weeks, 4 days ago
- 1 day ago
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.
Parameters
-
array$options optional Array of options.
Returns
stringRelative time string.
timestamp() public
timestamp(int $value)
Set the instance's timestamp
Parameters
-
int$value The timestamp value to set.
Returns
statictimezone() public
timezone(mixed $value)
Alias for setTimezone()
Parameters
-
\DateTimeZone|string$value The DateTimeZone object or timezone name to use.
Returns
statictoAtomString() public
toAtomString()
Format the instance as ATOM
Returns
stringtoCookieString() public
toCookieString()
Format the instance as COOKIE
Returns
stringtoDateString() public
toDateString()
Format the instance as date
Returns
stringtoDateTimeString() public
toDateTimeString()
Format the instance as date and time
Returns
stringtoDayDateTimeString() public
toDayDateTimeString()
Format the instance with day, date and time
Returns
stringtoFormattedDateString() public
toFormattedDateString()
Format the instance as a readable date
Returns
stringtoIso8601String() public
toIso8601String()
Format the instance as ISO8601
Returns
stringtoMutable() public
toMutable()
Create a new mutable instance from current immutable instance.
Returns
\Cake\Chronos\MutableDatetoQuarter() public
toQuarter(bool $range)
Returns the quarter
Parameters
-
bool$range optional Range.
Returns
int|array1, 2, 3, or 4 quarter of year or array if $range true
toRfc1036String() public
toRfc1036String()
Format the instance as RFC1036
Returns
stringtoRfc1123String() public
toRfc1123String()
Format the instance as RFC1123
Returns
stringtoRfc2822String() public
toRfc2822String()
Format the instance as RFC2822
Returns
stringtoRfc3339String() public
toRfc3339String()
Format the instance as RFC3339
Returns
stringtoRfc822String() public
toRfc822String()
Format the instance as RFC822
Returns
stringtoRfc850String() public
toRfc850String()
Format the instance as RFC850
Returns
stringtoRssString() public
toRssString()
Format the instance as RSS
Returns
stringtoTimeString() public
toTimeString()
Format the instance as time
Returns
stringtoUnixString() public
toUnixString()
Returns a UNIX timestamp.
Returns
stringUNIX timestamp
toW3cString() public
toW3cString()
Format the instance as W3C
Returns
stringtoWeek() public
toWeek()
today() public static
today(mixed $tz)
Create a ChronosInterface instance for today
Parameters
-
\DateTimeZone|string|null$tz optional The timezone to use.
Returns
statictomorrow() public static
tomorrow(mixed $tz)
Create a ChronosInterface instance for tomorrow
Parameters
-
\DateTimeZone|string|null$tz optional The DateTimeZone object or timezone name the new instance should use.
Returns
statictz() public
tz(mixed $value)
Alias for setTimezone()
Parameters
-
\DateTimeZone|string$value The DateTimeZone object or timezone name to use.
Returns
staticwasWithinLast() public
wasWithinLast(mixed $timeInterval)
Returns true this instance happened within the specified interval
Parameters
-
string|int$timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
Returns
boolyear() public
year(int $value)
Set the instance's year
Parameters
-
int$value The year value.
Returns
staticyesterday() public static
yesterday(mixed $tz)
Create a ChronosInterface instance for yesterday
Parameters
-
\DateTimeZone|string|null$tz optional The DateTimeZone object or timezone name the new instance should use.
Returns
staticProperty Detail
$_formatters protected static
In-memory cache of date formatters
Type
\IntlDateFormatter[]$_jsonEncodeFormat protected static
The format to use 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.
Type
string|int|int[]|\Closure$_lastErrors protected static
Holds the last error generated by createFromFormat
Type
array$_toStringFormat protected static
The format to use when formatting a time using Cake\I18n\Date::i18nFormat() and __toString. This format is also used by parseDateTime().
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.
Type
string|int|int[]$days protected static
Names of days of the week.
Type
array$defaultLocale protected static
The default locale to be used for displaying formatted date strings.
Use static::setDefaultLocale() and static::getDefaultLocale() instead.
Type
string|null$diffFormatter protected static
Instance of the diff formatting object.
Type
\Cake\Chronos\DifferenceFormatterInterface$lenientParsing protected static
Whether lenient parsing is enabled for IntlDateFormatter.
Defaults to true which is the default for IntlDateFormatter.
Type
bool$niceFormat public static
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.
Type
string|int|int[]$relativePattern protected static
Regex for relative period.
Type
string$toStringFormat protected static
Format to use for __toString method when type juggling occurs.
Type
string$weekEndsAt protected static
Last day of week
Type
int$weekStartsAt protected static
First day of week
Type
int$weekendDays protected static
Days of weekend
Type
array$wordAccuracy public static
The format to use when formatting a time using Date::timeAgoInWords() and the difference is less than Date::$wordEnd
Type
string[]$wordEnd public static
The end of relative time telling
Type
string$wordFormat public static
The format to use when formatting a time using Cake\I18n\Date::timeAgoInWords() and the difference is more than Cake\I18n\Date::$wordEnd
Type
string|int|int[]
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.I18n.FrozenDate.html