Extends the built-in DateTime class to provide handy methods and locale-aware formatting helpers
This object provides an immutable variant of {@link \Cake\I18n\Time}
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
string
'unixTimestampFormat'
serialise the value as a Unix Timestamp
int
3
int
52
int
100
int
10
arrayIntlDateFormatter>
In-memory cache of date formatters
Closure|array<int>|string|int
The format to use when converting this object to JSON.
array
Holds the last error generated by createFromFormat
array<int>|string|int
The format to use when formatting a time using Cake\I18n\FrozenTime::i18nFormat()
and __toString
. This format is also used by parseDateTime()
.
int
does a diffInYears() with default parameters
int
int
1 (for Monday) through 7 (for Sunday)
string
int
0 through 365
array
Names of days of the week.
int
number of days in the given month
string|null
The default locale to be used for displaying formatted date strings.
Cake\Chronos\DifferenceFormatterInterface
Instance of the diff formatting object.
bool
daylight savings time indicator, true if DST, false otherwise
int
bool
Whether lenient parsing is enabled for IntlDateFormatter.
bool
checks if the timezone is local, true if local, false otherwise
int
int
int
int
array<int>|string|int
The format to use when formatting a time using Cake\I18n\FrozenTime::nice()
int
the timezone offset in seconds from UTC
int
the timezone offset in hours from UTC
int
the quarter of this instance, 1 - 4
string
Regex for relative period.
int
Cake\Chronos\ChronosInterface|null
A test ChronosInterface instance to be returned when now instances are created
int
seconds since the Unix Epoch
DateTimeZone
the current timezone
string
string
Format to use for __toString method when type juggling occurs.
DateTimeZone
alias of timezone
string
bool
checks if the timezone is UTC, true if UTC, false otherwise
int
Last day of week
int
1 through 5
int
ISO-8601 week number of year, weeks starting on Monday
int
First day of week
array
Days of weekend
array<string>
The format to use when formatting a time using Time::timeAgoInWords()
and the difference is less than Time::$wordEnd
string
The end of relative time telling
array<int>|string|int
The format to use when formatting a time using Cake\I18n\FrozenTime::timeAgoInWords()
and the difference is more than Cake\I18n\FrozenTime::$wordEnd
int
int
Create a new immutable time 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 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 ChronosInterface instance (real or mock) to be returned when a "now" instance is created.
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
Determine if there is a valid test instance set. A valid test instance is anything that is not null.
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
Get list of timezone identifiers
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
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 a ChronosInterface instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions:
Set the time by time string
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 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 time 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
Format the instance as ISO8601
Create a new mutable instance from current immutable instance.
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 = null, DateTimeZone|string|null $tz = null)
Create a new immutable time instance.
Please see the testing aids section (specifically static::setTestNow()) for more on the possibility of this constructor returning a test instance.
DateTimeInterface|string|int|null
$time optional Fixed or relative time
DateTimeZone|string|null
$tz optional The timezone for the 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|boolDateTimeZone
InvalidArgumentException
__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.
string
addDay(int $value = 1): static
Add a day to the instance
int
$value optional The number of days to add.
static
addDays(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.
static
addHour(int $value = 1): static
Add an hour to the instance
int
$value optional The number of hours to add.
static
addHours(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.
static
addMinute(int $value = 1): static
Add a minute to the instance
int
$value optional The number of minutes to add.
static
addMinutes(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.
static
addMonth(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.
static
addMonthWithOverflow(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.
static
addMonths(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.
static
addMonthsWithOverflow(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.
static
addSecond(int $value = 1): static
Add a second to the instance
int
$value optional The number of seconds to add.
static
addSeconds(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.
static
addWeek(int $value = 1): static
Add a week to the instance
int
$value optional The number of weeks to add.
static
addWeekday(int $value = 1): static
Add a weekday to the instance
int
$value optional The number of weekdays to add.
static
addWeekdays(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.
static
addWeeks(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.
static
addYear(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.
static
addYearWithOverflow(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.
static
addYears(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.
static
addYearsWithOverflow(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.
static
average(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.
static
between(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 >=
bool
closest(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.
static
copy(): static
Get a copy of the instance
static
create(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.
static
createFromArray((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.
static
createFromDate(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.
static
createFromFormat(string $format, string $time, DateTimeZone|string|null $tz = null): static
Create a ChronosInterface instance from a specific format
string
$format The date() compatible format string.
string
$time The formatted date string to interpret.
DateTimeZone|string|null
$tz optional The DateTimeZone object or timezone name the new instance should use.
static
InvalidArgumentException
createFromTime(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.
static
createFromTimestamp(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.
static
createFromTimestampUTC(int $timestamp): static
Create a ChronosInterface instance from an UTC timestamp
int
$timestamp The UTC timestamp to create an instance from.
static
day(int $value): static
Set the instance's day
int
$value The day value.
static
diffFiltered(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
int
diffForHumans(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
string
diffFormatter(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\DifferenceFormatterInterface
diffInDays(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
int
diffInDaysFiltered(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
int
diffInHours(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
int
diffInHoursFiltered(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
int
diffInMinutes(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
int
diffInMonths(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
int
diffInMonthsIgnoreTimezone(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
int
diffInSeconds(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
int
diffInWeekdays(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
int
diffInWeekendDays(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
int
diffInWeeks(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
int
diffInYears(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
int
disableLenientParsing(): void
Enables lenient parsing for locale formats.
void
enableLenientParsing(): void
Enables lenient parsing for locale formats.
void
endOfCentury(): static
Resets the date to end of the century and time to 23:59:59
static
endOfDay(): static
Resets the time to 23:59:59
static
endOfDecade(): static
Resets the date to end of the decade and time to 23:59:59
static
endOfMonth(): static
Resets the date to end of the month and time to 23:59:59
static
endOfWeek(): static
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
static
endOfYear(): static
Resets the date to end of the year and time to 23:59:59
static
eq(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is equal to another
Cake\Chronos\ChronosInterface
$dt The instance to compare with.
bool
equals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is equal to another
Cake\Chronos\ChronosInterface
$dt The instance to compare with.
bool
farthest(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.
static
firstOfMonth(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.
mixed
firstOfQuarter(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.
mixed
firstOfYear(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.
mixed
fromNow(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|bool
getDefaultLocale(): string|null
Gets the default locale.
string|null
getDiffFormatter(): Cake\Chronos\DifferenceFormatterInterface
Get the difference formatter instance.
Cake\Chronos\DifferenceFormatterInterface
getLastErrors(): array
Returns any errors or warnings that were found during the parsing of the last object created by this class.
array
getTestNow(): Cake\Chronos\ChronosInterface|null
Get the ChronosInterface instance (real or mock) to be returned when a "now" instance is created.
Cake\Chronos\ChronosInterface|null
getWeekEndsAt(): int
Get the last day of week
int
getWeekStartsAt(): int
Get the first day of week
int
getWeekendDays(): array
Get weekend days
array
greaterThan(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than another
Cake\Chronos\ChronosInterface
$dt The instance to compare with.
bool
greaterThanOrEquals(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.
bool
gt(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than another
Cake\Chronos\ChronosInterface
$dt The instance to compare with.
bool
gte(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.
bool
hasRelativeKeywords(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.
bool
hasTestNow(): bool
Determine if there is a valid test instance set. A valid test instance is anything that is not null.
bool
hour(int $value): static
Set the instance's hour
int
$value The hour value.
static
i18nFormat(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|int
instance(DateTimeInterface $dt): static
Create a ChronosInterface instance from a DateTimeInterface one
DateTimeInterface
$dt The datetime instance to convert.
static
isBirthday(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.
bool
isFriday(): bool
Checks if this day is a Friday.
bool
isFuture(): bool
Determines if the instance is in the future, ie. greater (after) than now
bool
isLastMonth(): bool
Determines if the instance is within the last month
bool
isLastWeek(): bool
Determines if the instance is within the last week
bool
isLastYear(): bool
Determines if the instance is within the last year
bool
isLeapYear(): bool
Determines if the instance is a leap year
bool
isMonday(): bool
Checks if this day is a Monday.
bool
isMutable(): bool
Check if instance of ChronosInterface is mutable.
bool
isNextMonth(): bool
Determines if the instance is within the next month
bool
isNextWeek(): bool
Determines if the instance is within the next week
bool
isNextYear(): bool
Determines if the instance is within the next year
bool
isPast(): bool
Determines if the instance is in the past, ie. less (before) than now
bool
isSameDay(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.
bool
isSaturday(): bool
Checks if this day is a Saturday.
bool
isSunday(): bool
Checks if this day is a Sunday.
bool
isThisMonth(): bool
Returns true if this object represents a date within the current month
bool
isThisWeek(): bool
Returns true if this object represents a date within the current week
bool
isThisYear(): bool
Returns true if this object represents a date within the current year
bool
isThursday(): bool
Checks if this day is a Thursday.
bool
isToday(): bool
Determines if the instance is today
bool
isTomorrow(): bool
Determines if the instance is tomorrow
bool
isTuesday(): bool
Checks if this day is a Tuesday.
bool
isWednesday(): bool
Checks if this day is a Wednesday.
bool
isWeekday(): bool
Determines if the instance is a weekday
bool
isWeekend(): bool
Determines if the instance is a weekend day
bool
isWithinNext(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.
bool
isYesterday(): bool
Determines if the instance is yesterday
bool
jsonSerialize(): string|int
Returns a string that should be serialized when converting this object to JSON
string|int
lastOfMonth(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.
mixed
lastOfQuarter(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.
mixed
lastOfYear(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.
mixed
lenientParsingEnabled(): bool
Gets whether locale format parsing is set to lenient.
bool
lessThan(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) than another
Cake\Chronos\ChronosInterface
$dt The instance to compare with.
bool
lessThanOrEquals(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.
bool
listTimezones(string|int|null $filter = null, string|null $country = null, array<string, mixed>|bool $options = []): array
Get list of timezone identifiers
string|int|null
$filter optional A regex to filter identifier Or one of DateTimeZone class constants
string|null
$country optional A two-letter ISO 3166-1 compatible country code. This option is only used when $filter is set to DateTimeZone::PER_COUNTRY
array<string, mixed>|bool
$options optional If true (default value) groups the identifiers list by primary region. Otherwise, an array containing group
, abbr
, before
, and after
keys. Setting group
and abbr
to true will group results and append timezone abbreviation in the display value. Set before
and after
to customize the abbreviation wrapper.
array
lt(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) than another
Cake\Chronos\ChronosInterface
$dt The instance to compare with.
bool
lte(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.
bool
max(Cake\Chronos\ChronosInterface|null $dt = null): static
Get the maximum instance between a given instance (default now) and the current instance.
Cake\Chronos\ChronosInterface|null
$dt optional The instance to compare with.
static
maxValue(): Cake\Chronos\ChronosInterface
Create a ChronosInterface instance for the greatest supported date.
Cake\Chronos\ChronosInterface
microsecond(int $value): static
Set the instance's microsecond
int
$value The microsecond value.
static
min(Cake\Chronos\ChronosInterface|null $dt = null): static
Get the minimum instance between a given instance (default now) and the current instance.
Cake\Chronos\ChronosInterface|null
$dt optional The instance to compare with.
static
minValue(): Cake\Chronos\ChronosInterface
Create a ChronosInterface instance for the lowest supported date.
Cake\Chronos\ChronosInterface
minute(int $value): static
Set the instance's minute
int
$value The minute value.
static
modify(string $relative): Cake\Chronos\ChronosInterface
string
$relative Cake\Chronos\ChronosInterface
month(int $value): static
Set the instance's month
int
$value The month value.
static
ne(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is not equal to another
Cake\Chronos\ChronosInterface
$dt The instance to compare with.
bool
next(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.
mixed
nice(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)
string
notEquals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is not equal to another
Cake\Chronos\ChronosInterface
$dt The instance to compare with.
bool
now(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.
static
nthOfMonth(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.
mixed
nthOfQuarter(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.
mixed
nthOfYear(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.
mixed
parse(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.
static
parseDate(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|null
parseDateTime(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|null
parseTime(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|null
previous(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.
mixed
resetToStringFormat(): void
Resets the format used to the default when converting an instance of this type to a string
void
safeCreateDateTimeZone(DateTimeZone|string|null $object): DateTimeZone
Creates a DateTimeZone from a string or a DateTimeZone
DateTimeZone|string|null
$object The value to convert.
DateTimeZone
InvalidArgumentException
second(int $value): static
Set the instance's second
int
$value The seconds value.
static
secondsSinceMidnight(): int
The number of seconds since midnight.
int
secondsUntilEndOfDay(): int
The number of seconds until 23:59:59.
int
setDate(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.
static
setDateTime(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.
static
setDefaultLocale(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.
void
setDiffFormatter(Cake\Chronos\DifferenceFormatterInterface $formatter): void
Set the difference formatter instance.
Cake\Chronos\DifferenceFormatterInterface
$formatter The formatter instance when setting.
void
setJsonEncodeFormat(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 void
setTestNow(Cake\Chronos\ChronosInterface|string|null $testNow = null): void
Set a ChronosInterface instance (real or mock) to be returned when a "now" instance is created. The provided instance will be returned specifically under the following conditions:
Note the timezone parameter was left out of the examples above and has no affect as the mock value will be returned regardless of its value.
To clear the test instance call this method using the default parameter of null.
Cake\Chronos\ChronosInterface|string|null
$testNow optional The instance to use for all future instances.
void
setTimeFromTimeString(string $time): static
Set the time by time string
string
$time Time as string.
static
setTimezone(DateTimeZone|string $value): static
Set the instance's timezone from a string or object
DateTimeZone|string
$value The DateTimeZone object or timezone name to use.
static
setToStringFormat(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.
void
setWeekEndsAt(int $day): void
Set the last day of week
int
$day The day the week ends with.
void
setWeekStartsAt(int $day): void
Set the first day of week
int
$day The day the week starts with.
void
setWeekendDays(array $days): void
Set weekend days
array
$days Which days are 'weekends'.
void
startOfCentury(): static
Resets the date to the first day of the century and the time to 00:00:00
static
startOfDay(): static
Resets the time to 00:00:00
static
startOfDecade(): static
Resets the date to the first day of the decade and the time to 00:00:00
static
startOfMonth(): static
Resets the date to the first day of the month and the time to 00:00:00
static
startOfWeek(): static
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
static
startOfYear(): static
Resets the date to the first day of the year and the time to 00:00:00
static
subDay(int $value = 1): static
Remove a day from the instance
int
$value optional The number of days to remove.
static
subDays(int $value): static
Remove days from the instance
int
$value The number of days to remove.
static
subHour(int $value = 1): static
Remove an hour from the instance
int
$value optional The number of hours to remove.
static
subHours(int $value): static
Remove hours from the instance
int
$value The number of hours to remove.
static
subMinute(int $value = 1): static
Remove a minute from the instance
int
$value optional The number of minutes to remove.
static
subMinutes(int $value): static
Remove minutes from the instance
int
$value The number of minutes to remove.
static
subMonth(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.
static
subMonthWithOverflow(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.
static
subMonths(int $value): static
Remove months from the instance.
Has the same behavior as addMonths()
.
int
$value The number of months to remove.
static
subMonthsWithOverflow(int $value): static
Remove months with overflow from the instance.
Has the same behavior as addMonthsWithOverflow()
.
int
$value The number of months to remove.
static
subSecond(int $value = 1): static
Remove a second from the instance
int
$value optional The number of seconds to remove.
static
subSeconds(int $value): static
Remove seconds from the instance
int
$value The number of seconds to remove.
static
subWeek(int $value = 1): static
Remove a week from the instance
int
$value optional The number of weeks to remove.
static
subWeekday(int $value = 1): static
Remove a weekday from the instance
int
$value optional The number of weekdays to remove.
static
subWeekdays(int $value): static
Remove weekdays from the instance
int
$value The number of weekdays to remove.
static
subWeeks(int $value): static
Remove weeks to the instance
int
$value The number of weeks to remove.
static
subYear(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.
static
subYearWithOverflow(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.
static
subYears(int $value): static
Remove years from the instance.
Has the same behavior as addYears()
.
int
$value The number of years to remove.
static
subYearsWithOverflow(int $value): static
Remove years with overflow from the instance
Has the same behavior as addYearsWithOverflow()
.
int
$value The number of years to remove.
static
timeAgoInWords(array<string, mixed> $options = []): string
Returns either a relative or a formatted absolute date depending on the difference between the current time and this object.
from
=> another Time object representing the "now" timeformat
=> 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 time tellingrelativeString
=> The printf compatible string when outputting relative timeabsoluteString
=> The printf compatible string when outputting absolute timetimezone
=> 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.
string
timestamp(int $value): static
Set the instance's timestamp
int
$value The timestamp value to set.
static
timezone(DateTimeZone|string $value): static
Alias for setTimezone()
DateTimeZone|string
$value The DateTimeZone object or timezone name to use.
static
toAtomString(): string
Format the instance as ATOM
string
toCookieString(): string
Format the instance as COOKIE
string
toDateString(): string
Format the instance as date
string
toDateTimeString(): string
Format the instance as date and time
string
toDayDateTimeString(): string
Format the instance with day, date and time
string
toFormattedDateString(): string
Format the instance as a readable date
string
toIso8601String(): string
Format the instance as ISO8601
string
toMutable(): Cake\Chronos\MutableDateTime
Create a new mutable instance from current immutable instance.
Cake\Chronos\MutableDateTime
toQuarter(bool $range = false): int|array
Returns the quarter
bool
$range optional Range.
int|array
toRfc1036String(): string
Format the instance as RFC1036
string
toRfc1123String(): string
Format the instance as RFC1123
string
toRfc2822String(): string
Format the instance as RFC2822
string
toRfc3339String(): string
Format the instance as RFC3339
string
toRfc822String(): string
Format the instance as RFC822
string
toRfc850String(): string
Format the instance as RFC850
string
toRssString(): string
Format the instance as RSS
string
toTimeString(): string
Format the instance as time
string
toUnixString(): string
Returns a UNIX timestamp.
string
toW3cString(): string
Format the instance as W3C
string
toWeek(): int
int
today(DateTimeZone|string|null $tz = null): static
Create a ChronosInterface instance for today
DateTimeZone|string|null
$tz optional The timezone to use.
static
tomorrow(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.
static
tz(DateTimeZone|string $value): static
Alias for setTimezone()
DateTimeZone|string
$value The DateTimeZone object or timezone name to use.
static
wasWithinLast(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.
bool
year(int $value): static
Set the instance's year
int
$value The year value.
static
yesterday(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.
static
In-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|int
Holds the last error generated by createFromFormat
array
The format to use when formatting a time using Cake\I18n\FrozenTime::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|int
does a diffInYears() with default parameters
int
int
1 (for Monday) through 7 (for Sunday)
int
string
0 through 365
int
Names of days of the week.
array
number of days in the given month
int
The default locale to be used for displaying formatted date strings.
Use static::setDefaultLocale() and static::getDefaultLocale() instead.
string|null
Instance of the diff formatting object.
Cake\Chronos\DifferenceFormatterInterface
daylight savings time indicator, true if DST, false otherwise
bool
int
Whether lenient parsing is enabled for IntlDateFormatter.
Defaults to true which is the default for IntlDateFormatter.
bool
checks if the timezone is local, true if local, false otherwise
bool
int
int
int
int
The format to use when formatting a time using Cake\I18n\FrozenTime::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|int
the timezone offset in seconds from UTC
int
the timezone offset in hours from UTC
int
the quarter of this instance, 1 - 4
int
Regex for relative period.
string
int
A test ChronosInterface instance to be returned when now instances are created
There is a single test now for all date/time classes provided by Chronos. This aims to emulate stubbing out 'now' which is a single global fact.
Cake\Chronos\ChronosInterface|null
seconds since the Unix Epoch
int
the current timezone
DateTimeZone
string
Format to use for __toString method when type juggling occurs.
string
alias of timezone
DateTimeZone
string
checks if the timezone is UTC, true if UTC, false otherwise
bool
Last day of week
int
1 through 5
int
ISO-8601 week number of year, weeks starting on Monday
int
First day of week
int
Days of weekend
array
The format to use when formatting a time using Time::timeAgoInWords()
and the difference is less than Time::$wordEnd
array<string>
The end of relative time telling
string
The format to use when formatting a time using Cake\I18n\FrozenTime::timeAgoInWords()
and the difference is more than Cake\I18n\FrozenTime::$wordEnd
array<int>|string|int
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.4/class-Cake.I18n.FrozenTime.html