Extends the Date class provided by Chronos.
Adds handy methods and locale-aware formatting helpers
int 7
string 'Y-m-d H:i:s'
Default format to use for __toString method when type juggling occurs.
int 5
int 24
int 60
int 1
int 3
int 12
int 6
int 60
int 7
int 4
int 2
int 3
int 52
int 100
int 10
arrayIntlDateFormatter>In-memory cache of date formatters
Closure|array<int>|string|intThe format to use when converting this object to JSON.
arrayHolds the last error generated by createFromFormat
array<int>|string|intThe format to use when formatting a time using Cake\I18n\Date::i18nFormat() and __toString. This format is also used by parseDateTime().
intdoes a diffInYears() with default parameters
intint1 (for Monday) through 7 (for Sunday)
stringint0 through 365
arrayNames of days of the week.
intnumber of days in the given month
string|nullThe default locale to be used for displaying formatted date strings.
Cake\Chronos\DifferenceFormatterInterfaceInstance of the diff formatting object.
booldaylight savings time indicator, true if DST, false otherwise
intboolWhether lenient parsing is enabled for IntlDateFormatter.
boolchecks if the timezone is local, true if local, false otherwise
intintintintarray<int>|string|intThe format to use when formatting a time using Cake\I18n\Date::nice()
intthe timezone offset in seconds from UTC
intthe timezone offset in hours from UTC
intthe quarter of this instance, 1 - 4
stringRegex for relative period.
intintseconds since the Unix Epoch
DateTimeZonethe current timezone
stringstringFormat to use for __toString method when type juggling occurs.
DateTimeZonealias of timezone
stringboolchecks if the timezone is UTC, true if UTC, false otherwise
intLast day of week
int1 through 5
intISO-8601 week number of year, weeks starting on Monday
intFirst day of week
arrayDays of weekend
array<string>The format to use when formatting a time using Date::timeAgoInWords() and the difference is less than Date::$wordEnd
stringThe end of relative time telling
array<int>|string|intThe format to use when formatting a time using Cake\I18n\Date::timeAgoInWords() and the difference is more than Cake\I18n\Date::$wordEnd
intintCreate a new FrozenDate instance.
Returns the data that should be displayed when debugging this object
Get a part of the ChronosInterface object
Check if an attribute exists on the object
Format the instance as a string using the set format
Returns a translated and localized date string. Implements what IntlDateFormatter::formatObject() is in PHP 5.5+
Add an Interval to a Date
Add a day to the instance
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
Add an hour to the instance
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
Add a minute to the instance
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
Add a month to the instance.
Add a month with overflow to the instance.
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
Add a second to the instance
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
Add a week to the instance
Add a weekday to the instance
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
Add a year to the instance
Add a year with overflow to the instance
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
Add years with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
Modify the current instance to the average of a given instance (default now) and the current instance.
Determines if the instance is between two others
Get the closest date from the instance.
Get a copy of the instance
Create a new ChronosInterface instance from a specific date and time.
Creates a ChronosInterface instance from an array of date and time values.
Create a ChronosInterface instance from just a date. The time portion is set to now.
Create a ChronosInterface instance from a specific format
Create a ChronosInterface instance from just a time. The date portion is set to today.
Create a ChronosInterface instance from a timestamp
Create a ChronosInterface instance from an UTC timestamp
Set the instance's day
Get the difference by the given interval using a filter callable
Get the difference in a human readable format.
Get the difference formatter instance or overwrite the current one.
Get the difference in days
Get the difference in days using a filter callable
Get the difference in hours
Get the difference in hours using a filter callable
Get the difference in minutes
Get the difference in months
Get the difference in months ignoring the timezone. This means the months are calculated in the specified timezone without converting to UTC first. This prevents the day from changing which can change the month.
Get the difference in seconds
Get the difference in weekdays
Get the difference in weekend days using a filter
Get the difference in weeks
Get the difference in years
Enables lenient parsing for locale formats.
Enables lenient parsing for locale formats.
Resets the date to end of the century and time to 23:59:59
Resets the time to 23:59:59
Resets the date to end of the decade and time to 23:59:59
Resets the date to end of the month and time to 23:59:59
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
Resets the date to end of the year and time to 23:59:59
Determines if the instance is equal to another
Determines if the instance is equal to another
Get the farthest date from the instance.
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.
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.
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.
Convenience method for getting the remaining time from a given time.
Gets the default locale.
Get the difference formatter instance.
Returns any errors or warnings that were found during the parsing of the last object created by this class.
Get the test instance stored in Chronos
Get the last day of week
Get the first day of week
Get weekend days
Determines if the instance is greater (after) than another
Determines if the instance is greater (after) than or equal to another
Determines if the instance is greater (after) than another
Determines if the instance is greater (after) than or equal to another
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
Get whether or not Chronos has a test instance set.
Set the instance's hour
Returns a formatted string for this time object using the preferred format and language for the specified locale.
Create a ChronosInterface instance from a DateTimeInterface one
Check if its the birthday. Compares the date/month values of the two dates.
Checks if this day is a Friday.
Determines if the instance is in the future, ie. greater (after) than now
Determines if the instance is within the last month
Determines if the instance is within the last week
Determines if the instance is within the last year
Determines if the instance is a leap year
Checks if this day is a Monday.
Check if instance of ChronosInterface is mutable.
Determines if the instance is within the next month
Determines if the instance is within the next week
Determines if the instance is within the next year
Determines if the instance is in the past, ie. less (before) than now
Checks if the passed in date is the same day as the instance current day.
Checks if this day is a Saturday.
Checks if this day is a Sunday.
Returns true if this object represents a date within the current month
Returns true if this object represents a date within the current week
Returns true if this object represents a date within the current year
Checks if this day is a Thursday.
Determines if the instance is today
Determines if the instance is tomorrow
Checks if this day is a Tuesday.
Checks if this day is a Wednesday.
Determines if the instance is a weekday
Determines if the instance is a weekend day
Returns true this instance will happen within the specified interval
Determines if the instance is yesterday
Returns a string that should be serialized when converting this object to JSON
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.
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.
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.
Gets whether locale format parsing is set to lenient.
Determines if the instance is less (before) than another
Determines if the instance is less (before) or equal to another
Determines if the instance is less (before) than another
Determines if the instance is less (before) or equal to another
Get the maximum instance between a given instance (default now) and the current instance.
Create a ChronosInterface instance for the greatest supported date.
Set the instance's microsecond
Get the minimum instance between a given instance (default now) and the current instance.
Create a ChronosInterface instance for the lowest supported date.
Set the instance's minute
Overloaded to ignore time changes.
Set the instance's month
Determines if the instance is not equal to another
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.
Returns a nicely formatted date string for this object.
Determines if the instance is not equal to another
Get a ChronosInterface instance for the current date and time
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.
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.
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.
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()
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.
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.
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.
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.
Resets the format used to the default when converting an instance of this type to a string
Creates a DateTimeZone from a string or a DateTimeZone
Set the instance's second
The number of seconds since midnight.
The number of seconds until 23:59:59.
Set the date to a different date.
Set the date and time all together
Sets the default locale.
Set the difference formatter instance.
Sets the default format used when converting this object to JSON
Set the test now used by Date and Time classes provided by Chronos
Modify the time on the Date.
Set the time by time string
Set the timestamp value and get a new object back.
Set the instance's timezone from a string or object
Sets the default format used when type converting instances of this type to string
Set the last day of week
Set the first day of week
Set weekend days
Resets the date to the first day of the century and the time to 00:00:00
Resets the time to 00:00:00
Resets the date to the first day of the decade and the time to 00:00:00
Resets the date to the first day of the month and the time to 00:00:00
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
Resets the date to the first day of the year and the time to 00:00:00
Remove time components from strtotime relative strings.
Removes the time components from an input string.
Subtract an Interval from a Date.
Remove a day from the instance
Remove days from the instance
Remove an hour from the instance
Remove hours from the instance
Remove a minute from the instance
Remove minutes from the instance
Remove a month from the instance
Remove a month with overflow from the instance.
Remove months from the instance.
Remove months with overflow from the instance.
Remove a second from the instance
Remove seconds from the instance
Remove a week from the instance
Remove a weekday from the instance
Remove weekdays from the instance
Remove weeks to the instance
Remove a year from the instance.
Remove a year with overflow from the instance
Remove years from the instance.
Remove years with overflow from the instance
Returns either a relative or a formatted absolute date depending on the difference between the current date and this object.
Set the instance's timestamp
Alias for setTimezone()
Format the instance as ATOM
Format the instance as COOKIE
Format the instance as date
Format the instance as date and time
Format the instance with day, date and time
Format the instance as a readable date
Create a new immutable instance from current mutable instance.
Format the instance as ISO8601
Returns the quarter
Format the instance as RFC1036
Format the instance as RFC1123
Format the instance as RFC2822
Format the instance as RFC3339
Format the instance as RFC822
Format the instance as RFC850
Format the instance as RSS
Format the instance as time
Returns a UNIX timestamp.
Format the instance as W3C
Create a ChronosInterface instance for today
Create a ChronosInterface instance for tomorrow
Alias for setTimezone()
Returns true this instance happened within the specified interval
Set the instance's year
Create a ChronosInterface instance for yesterday
__construct(DateTimeInterface|string|int|null $time = 'now', DateTimeZone|string|null $tz = null)
Create a new FrozenDate 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 the server local time. Normalizing the timezone allows for subtraction/addition to have deterministic results.
DateTimeInterface|string|int|null $time optional Fixed or relative time
DateTimeZone|string|null $tz optional The timezone in which the date is taken. Ignored if $time is a DateTimeInterface instance.
__debugInfo(): array<string, mixed>
Returns the data that should be displayed when debugging this object
array<string, mixed>__get(string $name): string|int|boolDateTimeZone
Get a part of the ChronosInterface object
string $name The property name to read.
string|int|boolDateTimeZoneInvalidArgumentException__isset(string $name): bool
Check if an attribute exists on the object
string $name The property name to check.
bool__toString(): string
Format the instance as a string using the set format
string_formatObject(DateTimeDateTimeImmutable $date, array<int>|string|int $format, string|null $locale): string
Returns a translated and localized date string. Implements what IntlDateFormatter::formatObject() is in PHP 5.5+
DateTimeDateTimeImmutable $date Date.
array<int>|string|int $format Format.
string|null $locale The locale name in which the date should be displayed.
stringadd(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.
staticaddDay(int $value = 1): static
Add a day to the instance
int $value optional The number of days to add.
staticaddDays(int $value): static
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
int $value The number of days to add.
staticaddHour(int $value = 1): static
Add an hour to the instance
int $value optional The number of hours to add.
staticaddHours(int $value): static
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
int $value The number of hours to add.
staticaddMinute(int $value = 1): static
Add a minute to the instance
int $value optional The number of minutes to add.
staticaddMinutes(int $value): static
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
int $value The number of minutes to add.
staticaddMonth(int $value = 1): static
Add a month to the instance.
Has the same behavior as addMonths().
int $value optional The number of months to add.
staticaddMonthWithOverflow(int $value = 1): static
Add a month with overflow to the instance.
Has the same behavior as addMonthsWithOverflow().
int $value optional The number of months to add.
staticaddMonths(int $value): static
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.
(new Chronos('2015-01-03'))->addMonths(1); // Results in 2015-02-03
(new Chronos('2015-01-31'))->addMonths(1); // Results in 2015-02-28 int $value The number of months to add.
staticaddMonthsWithOverflow(int $value): static
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.
(new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01 int $value The number of months to add.
staticaddSecond(int $value = 1): static
Add a second to the instance
int $value optional The number of seconds to add.
staticaddSeconds(int $value): static
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
int $value The number of seconds to add.
staticaddWeek(int $value = 1): static
Add a week to the instance
int $value optional The number of weeks to add.
staticaddWeekday(int $value = 1): static
Add a weekday to the instance
int $value optional The number of weekdays to add.
staticaddWeekdays(int $value): static
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
int $value The number of weekdays to add.
staticaddWeeks(int $value): static
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
int $value The number of weeks to add.
staticaddYear(int $value = 1): static
Add a year to the instance
Has the same behavior as addYears().
int $value optional The number of years to add.
staticaddYearWithOverflow(int $value = 1): static
Add a year with overflow to the instance
Has the same behavior as addYearsWithOverflow().
int $value optional The number of years to add.
staticaddYears(int $value): static
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.
(new Chronos('2015-01-03'))->addYears(1); // Results in 2016-01-03
(new Chronos('2012-02-29'))->addYears(1); // Results in 2013-02-28 int $value The number of years to add.
staticaddYearsWithOverflow(int $value): static
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.
(new Chronos('2012-02-29'))->addYearsWithOverflow(1); // Results in 2013-03-01 int $value The number of years to add.
staticaverage(Cake\Chronos\ChronosInterface $dt = null): static
Modify the current instance to the average of a given instance (default now) and the current instance.
Cake\Chronos\ChronosInterface $dt optional The instance to compare with.
staticbetween(Cake\Chronos\ChronosInterface $dt1, Cake\Chronos\ChronosInterface $dt2, bool $equal = true): bool
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.
bool $equal optional Indicates if a > and < comparison should be used or <= or >=
boolclosest(Cake\Chronos\ChronosInterface $dt1, Cake\Chronos\ChronosInterface $dt2): static
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.
staticcopy(): static
Get a copy of the instance
staticcreate(int|null $year = null, int|null $month = null, int|null $day = null, int|null $hour = null, int|null $minute = null, int|null $second = null, int|null $microsecond = 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, $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.
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.
staticcreateFromArray((int|string)[] $values): static
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:
(int|string)[] $values Array of date and time values.
staticcreateFromDate(int|null $year = null, int|null $month = null, int|null $day = null, DateTimeZone|string|null $tz = null): static
Create a ChronosInterface instance from just a date. The time portion is set to now.
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.
staticcreateFromFormat(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 optional The DateTimeZone object or timezone name the new instance should use.
staticInvalidArgumentExceptioncreateFromTime(int|null $hour = null, int|null $minute = null, int|null $second = null, int|null $microsecond = null, DateTimeZone|string|null $tz = null): static
Create a ChronosInterface instance from just a time. The date portion is set to today.
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.
staticcreateFromTimestamp(int $timestamp, DateTimeZone|string|null $tz = null): static
Create a ChronosInterface instance from a timestamp
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.
staticcreateFromTimestampUTC(int $timestamp): static
Create a ChronosInterface instance from an UTC timestamp
int $timestamp The UTC timestamp to create an instance from.
staticday(int $value): static
Set the instance's day
int $value The day value.
staticdiffFiltered(Cake\Chronos\ChronosInterval $ci, callable $callback, Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
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 optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffForHumans(Cake\Chronos\ChronosInterface|null $other = null, bool $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 optional The datetime to compare with.
bool $absolute optional removes time difference modifiers ago, after, etc
stringdiffFormatter(Cake\Chronos\DifferenceFormatterInterface|null $formatter = null): Cake\Chronos\DifferenceFormatterInterface
Get the difference formatter instance or overwrite the current one.
Cake\Chronos\DifferenceFormatterInterface|null $formatter optional The formatter instance when setting.
Cake\Chronos\DifferenceFormatterInterfacediffInDays(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in days
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffInDaysFiltered(callable $callback, Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in days using a filter callable
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
intdiffInHours(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in hours
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffInHoursFiltered(callable $callback, Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in hours using a filter callable
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
intdiffInMinutes(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in minutes
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffInMonths(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in months
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffInMonthsIgnoreTimezone(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in months ignoring the timezone. This means the months are calculated in the specified timezone without converting to UTC first. This prevents the day from changing which can change the month.
For example, if comparing 2019-06-01 Asia/Tokyo and 2019-10-01 Asia/Tokyo, the result would be 4 months instead of 3 when using normal DateTime::diff().
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffInSeconds(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in seconds
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffInWeekdays(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in weekdays
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffInWeekendDays(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in weekend days using a filter
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffInWeeks(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in weeks
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdiffInYears(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in years
Cake\Chronos\ChronosInterface|null $dt optional The instance to difference from.
bool $abs optional Get the absolute of the difference
intdisableLenientParsing(): void
Enables lenient parsing for locale formats.
voidenableLenientParsing(): void
Enables lenient parsing for locale formats.
voidendOfCentury(): static
Resets the date to end of the century and time to 23:59:59
staticendOfDay(): static
Resets the time to 23:59:59
staticendOfDecade(): static
Resets the date to end of the decade and time to 23:59:59
staticendOfMonth(): static
Resets the date to end of the month and time to 23:59:59
staticendOfWeek(): static
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
staticendOfYear(): static
Resets the date to end of the year and time to 23:59:59
staticeq(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is equal to another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolequals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is equal to another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolfarthest(Cake\Chronos\ChronosInterface $dt1, Cake\Chronos\ChronosInterface $dt2): static
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.
staticfirstOfMonth(int|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. static::MONDAY.
int|null $dayOfWeek optional The day of the week to move to.
mixedfirstOfQuarter(int|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. static::MONDAY.
int|null $dayOfWeek optional The day of the week to move to.
mixedfirstOfYear(int|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. static::MONDAY.
int|null $dayOfWeek optional The day of the week to move to.
mixedfromNow(DateTimeDateTimeImmutable $datetime): DateInterval|bool
Convenience method for getting the remaining time from a given time.
DateTimeDateTimeImmutable $datetime The date to get the remaining time from.
DateInterval|boolgetDefaultLocale(): string|null
Gets the default locale.
string|nullgetDiffFormatter(): Cake\Chronos\DifferenceFormatterInterface
Get the difference formatter instance.
Cake\Chronos\DifferenceFormatterInterfacegetLastErrors(): array
Returns any errors or warnings that were found during the parsing of the last object created by this class.
arraygetTestNow(): Cake\Chronos\ChronosInterface|null
Get the test instance stored in Chronos
Cake\Chronos\ChronosInterface|nullgetWeekEndsAt(): int
Get the last day of week
intgetWeekStartsAt(): int
Get the first day of week
intgetWeekendDays(): array
Get weekend days
arraygreaterThan(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolgreaterThanOrEquals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than or equal to another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolgt(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolgte(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than or equal to another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolhasRelativeKeywords(string|null $time): bool
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
string|null $time The time string to check.
boolhasTestNow(): bool
Get whether or not Chronos has a test instance set.
boolhour(int $value): static
Set the instance's hour
int $value The hour value.
statici18nFormat(string|int|null $format = null, DateTimeZone|string|null $timezone = null, string|null $locale = null): string|int
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: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax.
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' 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.
$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.
string|int|null $format optional Format string.
DateTimeZone|string|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)
string|intinstance(DateTimeInterface $dt): static
Create a ChronosInterface instance from a DateTimeInterface one
DateTimeInterface $dt The datetime instance to convert.
staticisBirthday(Cake\Chronos\ChronosInterface $dt): bool
Check if its the birthday. Compares the date/month values of the two dates.
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolisFriday(): bool
Checks if this day is a Friday.
boolisFuture(): bool
Determines if the instance is in the future, ie. greater (after) than now
boolisLastMonth(): bool
Determines if the instance is within the last month
boolisLastWeek(): bool
Determines if the instance is within the last week
boolisLastYear(): bool
Determines if the instance is within the last year
boolisLeapYear(): bool
Determines if the instance is a leap year
boolisMonday(): bool
Checks if this day is a Monday.
boolisMutable(): bool
Check if instance of ChronosInterface is mutable.
boolisNextMonth(): bool
Determines if the instance is within the next month
boolisNextWeek(): bool
Determines if the instance is within the next week
boolisNextYear(): bool
Determines if the instance is within the next year
boolisPast(): bool
Determines if the instance is in the past, ie. less (before) than now
boolisSameDay(Cake\Chronos\ChronosInterface $dt): bool
Checks if the passed in date is the same day as the instance current day.
Cake\Chronos\ChronosInterface $dt The instance to check against.
boolisSaturday(): bool
Checks if this day is a Saturday.
boolisSunday(): bool
Checks if this day is a Sunday.
boolisThisMonth(): bool
Returns true if this object represents a date within the current month
boolisThisWeek(): bool
Returns true if this object represents a date within the current week
boolisThisYear(): bool
Returns true if this object represents a date within the current year
boolisThursday(): bool
Checks if this day is a Thursday.
boolisToday(): bool
Determines if the instance is today
boolisTomorrow(): bool
Determines if the instance is tomorrow
boolisTuesday(): bool
Checks if this day is a Tuesday.
boolisWednesday(): bool
Checks if this day is a Wednesday.
boolisWeekday(): bool
Determines if the instance is a weekday
boolisWeekend(): bool
Determines if the instance is a weekend day
boolisWithinNext(string|int $timeInterval): bool
Returns true this instance will happen within the specified interval
string|int $timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
boolisYesterday(): bool
Determines if the instance is yesterday
booljsonSerialize(): string|int
Returns a string that should be serialized when converting this object to JSON
string|intlastOfMonth(int|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. static::MONDAY.
int|null $dayOfWeek optional The day of the week to move to.
mixedlastOfQuarter(int|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. static::MONDAY.
int|null $dayOfWeek optional The day of the week to move to.
mixedlastOfYear(int|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. static::MONDAY.
int|null $dayOfWeek optional The day of the week to move to.
mixedlenientParsingEnabled(): bool
Gets whether locale format parsing is set to lenient.
boollessThan(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) than another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boollessThanOrEquals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) or equal to another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boollt(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) than another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boollte(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) or equal to another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolmax(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 optional The instance to compare with.
staticmaxValue(): Cake\Chronos\ChronosInterface
Create a ChronosInterface instance for the greatest supported date.
Cake\Chronos\ChronosInterfacemicrosecond(int $value): static
Set the instance's microsecond
int $value The microsecond value.
staticmin(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 optional The instance to compare with.
staticminValue(): Cake\Chronos\ChronosInterface
Create a ChronosInterface instance for the lowest supported date.
Cake\Chronos\ChronosInterfaceminute(int $value): static
Set the instance's minute
int $value The minute value.
staticmodify(string $relative): Cake\Chronos\ChronosInterface
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 Cake\Chronos\ChronosInterfacemonth(int $value): static
Set the instance's month
int $value The month value.
staticne(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is not equal to another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolnext(int|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. static::MONDAY.
int|null $dayOfWeek optional The day of the week to move to.
mixednice(DateTimeZone|string|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.
DateTimeZone|string|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)
stringnotEquals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is not equal to another
Cake\Chronos\ChronosInterface $dt The instance to compare with.
boolnow(DateTimeZone|string|null $tz): static
Get a ChronosInterface instance for the current date and time
DateTimeZone|string|null $tz The DateTimeZone object or timezone name.
staticnthOfMonth(int $nth, int $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. static::MONDAY.
int $nth The offset to use.
int $dayOfWeek The day of the week to move to.
mixednthOfQuarter(int $nth, int $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. static::MONDAY.
int $nth The offset to use.
int $dayOfWeek The day of the week to move to.
mixednthOfYear(int $nth, int $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. static::MONDAY.
int $nth The offset to use.
int $dayOfWeek The day of the week to move to.
mixedparse(DateTimeInterface|string|int $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()
DateTimeInterface|string|int $time optional The strtotime compatible string to parse
DateTimeZone|string|null $tz optional The DateTimeZone object or timezone name.
staticparseDate(string $date, array|string|int|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.
array|string|int|null $format optional Any format accepted by IntlDateFormatter.
static|nullparseDateTime(string $time, array<int>|string|null $format = null, DateTimeZone|string|null $tz = 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.
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]); string $time The time string to parse.
array<int>|string|null $format optional Any format accepted by IntlDateFormatter.
DateTimeZone|string|null $tz optional The timezone for the instance
static|nullparseTime(string $time, string|int|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|int|null $format optional Any format accepted by IntlDateFormatter.
static|nullprevious(int|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. static::MONDAY.
int|null $dayOfWeek optional The day of the week to move to.
mixedresetToStringFormat(): void
Resets the format used to the default when converting an instance of this type to a string
voidsafeCreateDateTimeZone(DateTimeZone|string|null $object): DateTimeZone
Creates a DateTimeZone from a string or a DateTimeZone
DateTimeZone|string|null $object The value to convert.
DateTimeZoneInvalidArgumentExceptionsecond(int $value): static
Set the instance's second
int $value The seconds value.
staticsecondsSinceMidnight(): int
The number of seconds since midnight.
intsecondsUntilEndOfDay(): int
The number of seconds until 23:59:59.
intsetDate(int $year, int $month, int $day): static
Set the date to a different date.
Workaround for a PHP bug related to the first day of a month
int $year The year to set.
int $month The month to set.
int $day The day to set.
staticsetDateTime(int $year, int $month, int $day, int $hour, int $minute, int $second = 0): static
Set the date and time all together
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.
staticsetDefaultLocale(string|null $locale = null): void
Sets the default locale.
Set to null to use IntlDateFormatter default.
string|null $locale optional The default locale string to be used.
voidsetDiffFormatter(Cake\Chronos\DifferenceFormatterInterface $formatter): void
Set the difference formatter instance.
Cake\Chronos\DifferenceFormatterInterface $formatter The formatter instance when setting.
voidsetJsonEncodeFormat(Closure|array|string|int $format): void
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 (https://unicode-org.github.io/icu-docs/apidoc/released/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.
Closure|array|string|int $format voidsetTestNow(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 optional The instance to use for all future instances.
voidsetTime(int $hours, int $minutes, int $seconds = null, int $microseconds = null): static
Modify the time on the Date.
This method ignores all inputs and forces all inputs to 0.
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)
staticsetTimeFromTimeString(string $time): static
Set the time by time string
string $time Time as string.
staticsetTimestamp(int $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
int $value The timestamp value to set.
staticsetTimezone(DateTimeZone|string $value): static
Set the instance's timezone from a string or object
Timezones have no effect on calendar dates.
DateTimeZone|string $value The DateTimeZone object or timezone name to use.
staticsetToStringFormat(string $format): void
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 (https://unicode-org.github.io/icu-docs/apidoc/released/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.
string $format Format.
voidsetWeekEndsAt(int $day): void
Set the last day of week
int $day The day the week ends with.
voidsetWeekStartsAt(int $day): void
Set the first day of week
int $day The day the week starts with.
voidsetWeekendDays(array $days): void
Set weekend days
array $days Which days are 'weekends'.
voidstartOfCentury(): static
Resets the date to the first day of the century and the time to 00:00:00
staticstartOfDay(): static
Resets the time to 00:00:00
staticstartOfDecade(): static
Resets the date to the first day of the decade and the time to 00:00:00
staticstartOfMonth(): static
Resets the date to the first day of the month and the time to 00:00:00
staticstartOfWeek(): static
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
staticstartOfYear(): static
Resets the date to the first day of the year and the time to 00:00:00
staticstripRelativeTime(string $time): string
Remove time components from strtotime relative strings.
string $time The input expression
stringstripTime(DateTimeDateTimeImmutable|string|int|null $time, DateTimeZone|null $tz): string
Removes the time components from an input string.
Used to ensure constructed objects always lack time.
DateTimeDateTimeImmutable|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
stringsub(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.
staticsubDay(int $value = 1): static
Remove a day from the instance
int $value optional The number of days to remove.
staticsubDays(int $value): static
Remove days from the instance
int $value The number of days to remove.
staticsubHour(int $value = 1): static
Remove an hour from the instance
int $value optional The number of hours to remove.
staticsubHours(int $value): static
Remove hours from the instance
int $value The number of hours to remove.
staticsubMinute(int $value = 1): static
Remove a minute from the instance
int $value optional The number of minutes to remove.
staticsubMinutes(int $value): static
Remove minutes from the instance
int $value The number of minutes to remove.
staticsubMonth(int $value = 1): static
Remove a month from the instance
Has the same behavior as addMonths().
int $value optional The number of months to remove.
staticsubMonthWithOverflow(int $value = 1): static
Remove a month with overflow from the instance.
Has the same behavior as addMonthsWithOverflow().
int $value optional The number of months to remove.
staticsubMonths(int $value): static
Remove months from the instance.
Has the same behavior as addMonths().
int $value The number of months to remove.
staticsubMonthsWithOverflow(int $value): static
Remove months with overflow from the instance.
Has the same behavior as addMonthsWithOverflow().
int $value The number of months to remove.
staticsubSecond(int $value = 1): static
Remove a second from the instance
int $value optional The number of seconds to remove.
staticsubSeconds(int $value): static
Remove seconds from the instance
int $value The number of seconds to remove.
staticsubWeek(int $value = 1): static
Remove a week from the instance
int $value optional The number of weeks to remove.
staticsubWeekday(int $value = 1): static
Remove a weekday from the instance
int $value optional The number of weekdays to remove.
staticsubWeekdays(int $value): static
Remove weekdays from the instance
int $value The number of weekdays to remove.
staticsubWeeks(int $value): static
Remove weeks to the instance
int $value The number of weeks to remove.
staticsubYear(int $value = 1): static
Remove a year from the instance.
Has the same behavior as addYears().
int $value optional The number of years to remove.
staticsubYearWithOverflow(int $value = 1): static
Remove a year with overflow from the instance
Has the same behavior as addYearsWithOverflow().
int $value optional The number of years to remove.
staticsubYears(int $value): static
Remove years from the instance.
Has the same behavior as addYears().
int $value The number of years to remove.
staticsubYearsWithOverflow(int $value): static
Remove years with overflow from the instance
Has the same behavior as addYearsWithOverflow().
int $value The number of years to remove.
statictimeAgoInWords(array<string, mixed> $options = []): 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<string, mixed> $options optional Array of options.
stringtimestamp(int $value): static
Set the instance's timestamp
int $value The timestamp value to set.
statictimezone(DateTimeZone|string $value): static
Alias for setTimezone()
Timezones have no effect on calendar dates.
DateTimeZone|string $value The DateTimeZone object or timezone name to use.
statictoAtomString(): string
Format the instance as ATOM
stringtoCookieString(): string
Format the instance as COOKIE
stringtoDateString(): string
Format the instance as date
stringtoDateTimeString(): string
Format the instance as date and time
stringtoDayDateTimeString(): string
Format the instance with day, date and time
stringtoFormattedDateString(): string
Format the instance as a readable date
stringtoImmutable(): Cake\Chronos\Date
Create a new immutable instance from current mutable instance.
Cake\Chronos\DatetoIso8601String(): string
Format the instance as ISO8601
stringtoQuarter(bool $range = false): int|array
Returns the quarter
bool $range optional Range.
int|arraytoRfc1036String(): string
Format the instance as RFC1036
stringtoRfc1123String(): string
Format the instance as RFC1123
stringtoRfc2822String(): string
Format the instance as RFC2822
stringtoRfc3339String(): string
Format the instance as RFC3339
stringtoRfc822String(): string
Format the instance as RFC822
stringtoRfc850String(): string
Format the instance as RFC850
stringtoRssString(): string
Format the instance as RSS
stringtoTimeString(): string
Format the instance as time
stringtoUnixString(): string
Returns a UNIX timestamp.
stringtoW3cString(): string
Format the instance as W3C
stringtoWeek(): int
inttoday(DateTimeZone|string|null $tz = null): static
Create a ChronosInterface instance for today
DateTimeZone|string|null $tz optional The timezone to use.
statictomorrow(DateTimeZone|string|null $tz = null): static
Create a ChronosInterface instance for tomorrow
DateTimeZone|string|null $tz optional The DateTimeZone object or timezone name the new instance should use.
statictz(DateTimeZone|string $value): static
Alias for setTimezone()
Timezones have no effect on calendar dates.
DateTimeZone|string $value The DateTimeZone object or timezone name to use.
staticwasWithinLast(string|int $timeInterval): bool
Returns true this instance happened within the specified interval
string|int $timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
boolyear(int $value): static
Set the instance's year
int $value The year value.
staticyesterday(DateTimeZone|string|null $tz = null): static
Create a ChronosInterface instance for yesterday
DateTimeZone|string|null $tz optional The DateTimeZone object or timezone name the new instance should use.
staticIn-memory cache of date formatters
arrayIntlDateFormatter>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 (https://unicode-org.github.io/icu-docs/apidoc/released/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.
Closure|array<int>|string|intHolds the last error generated by createFromFormat
arrayThe 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 (https://unicode-org.github.io/icu-docs/apidoc/released/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.
array<int>|string|intdoes a diffInYears() with default parameters
intint1 (for Monday) through 7 (for Sunday)
intstring0 through 365
intNames of days of the week.
arraynumber of days in the given month
intThe default locale to be used for displaying formatted date strings.
Use static::setDefaultLocale() and static::getDefaultLocale() instead.
string|nullInstance of the diff formatting object.
Cake\Chronos\DifferenceFormatterInterfacedaylight savings time indicator, true if DST, false otherwise
boolintWhether lenient parsing is enabled for IntlDateFormatter.
Defaults to true which is the default for IntlDateFormatter.
boolchecks if the timezone is local, true if local, false otherwise
boolintintintintThe 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 (https://unicode-org.github.io/icu-docs/apidoc/released/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.
array<int>|string|intthe timezone offset in seconds from UTC
intthe timezone offset in hours from UTC
intthe quarter of this instance, 1 - 4
intRegex for relative period.
stringintseconds since the Unix Epoch
intthe current timezone
DateTimeZonestringFormat to use for __toString method when type juggling occurs.
stringalias of timezone
DateTimeZonestringchecks if the timezone is UTC, true if UTC, false otherwise
boolLast day of week
int1 through 5
intISO-8601 week number of year, weeks starting on Monday
intFirst day of week
intDays of weekend
arrayThe format to use when formatting a time using Date::timeAgoInWords() and the difference is less than Date::$wordEnd
array<string>The end of relative time telling
stringThe format to use when formatting a time using Cake\I18n\Date::timeAgoInWords() and the difference is more than Cake\I18n\Date::$wordEnd
array<int>|string|intintint
© 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.4/class-Cake.I18n.Date.html