$year
$year : integer
A mutable date object that converts all time components into 00:00:00.
This class is useful when you want to represent a calendar date and ignore times. This means that timezone changes take no effect as a calendar date exists in all timezones in each respective date.
$diffFormatter : \Cake\Chronos\DifferenceFormatter
Instance of the diff formatting object.
eq(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is equal to another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
ne(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is not equal to another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
gt(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is greater (after) than another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
gte(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is greater (after) than or equal to another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
lt(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is less (before) than another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
lte(\Cake\Chronos\ChronosInterface $dt) : boolean
Determines if the instance is less (before) or equal to another
\Cake\Chronos\ChronosInterface | $dt | The instance to compare with. |
between(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2, boolean $equal = true) : boolean
Determines if the instance is between two others
\Cake\Chronos\ChronosInterface | $dt1 | The instance to compare with. |
\Cake\Chronos\ChronosInterface | $dt2 | The instance to compare with. |
boolean | $equal | Indicates if a > and < comparison should be used or <= or >= |
closest(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2) : \Cake\Chronos\ChronosInterface
Get the closest date from the instance.
\Cake\Chronos\ChronosInterface | $dt1 | The instance to compare with. |
\Cake\Chronos\ChronosInterface | $dt2 | The instance to compare with. |
farthest(\Cake\Chronos\ChronosInterface $dt1, \Cake\Chronos\ChronosInterface $dt2) : \Cake\Chronos\ChronosInterface
Get the farthest date from the instance.
\Cake\Chronos\ChronosInterface | $dt1 | The instance to compare with. |
\Cake\Chronos\ChronosInterface | $dt2 | The instance to compare with. |
min(\Cake\Chronos\ChronosInterface|null $dt = null) : static
Get the minimum instance between a given instance (default now) and the current instance.
\Cake\Chronos\ChronosInterface|null | $dt | The instance to compare with. |
max(\Cake\Chronos\ChronosInterface|null $dt = null) : static
Get the maximum instance between a given instance (default now) and the current instance.
\Cake\Chronos\ChronosInterface|null | $dt | The instance to compare with. |
isSameDay(\Cake\Chronos\ChronosInterface $dt) : boolean
Checks if the passed in date is the same day as the instance current day.
\Cake\Chronos\ChronosInterface | $dt | The instance to check against. |
isBirthday(\Cake\Chronos\ChronosInterface|null $dt = null) : static
Check if its the birthday. Compares the date/month values of the two dates.
\Cake\Chronos\ChronosInterface|null | $dt | The instance to compare with or null to use current day. |
diffInYears(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in years
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInMonths(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in months
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInWeeks(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in weeks
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInDays(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in days
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInDaysFiltered(callable $callback, \Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in days using a filter callable
callable | $callback | The callback to use for filtering. |
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInHoursFiltered(callable $callback, \Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in hours using a filter callable
callable | $callback | The callback to use for filtering. |
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffFiltered(\Cake\Chronos\ChronosInterval $ci, callable $callback, \Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference by the given interval using a filter callable
\Cake\Chronos\ChronosInterval | $ci | An interval to traverse by |
callable | $callback | The callback to use for filtering. |
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInWeekdays(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in weekdays
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInWeekendDays(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in weekend days using a filter
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInHours(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in hours
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInMinutes(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in minutes
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
diffInSeconds(\Cake\Chronos\ChronosInterface|null $dt = null, boolean $abs = true) : integer
Get the difference in seconds
\Cake\Chronos\ChronosInterface|null | $dt | The instance to difference from. |
boolean | $abs | Get the absolute of the difference |
fromNow(\DateTime|\DateTimeImmutable $datetime) : \DateInterval|boolean
Convenience method for getting the remaining time from a given time.
\DateTime|\DateTimeImmutable | $datetime | The date to get the remaining time from. |
The DateInterval object representing the difference between the two dates or FALSE on failure.
diffForHumans(\Cake\Chronos\ChronosInterface|null $other = null, boolean $absolute = false) : string
Get the difference in a human readable format.
When comparing a value in the past to default now: 1 hour ago 5 months ago
When comparing a value in the future to default now: 1 hour from now 5 months from now
When comparing a value in the past to another value: 1 hour before 5 months before
When comparing a value in the future to another value: 1 hour after 5 months after
\Cake\Chronos\ChronosInterface|null | $other | The datetime to compare with. |
boolean | $absolute | removes time difference modifiers ago, after, etc |
diffFormatter(\Cake\Chronos\DifferenceFormatter|null $formatter = null) : \Cake\Chronos\DifferenceFormatter
Get the difference formatter instance or overwrite the current one.
\Cake\Chronos\DifferenceFormatter|null | $formatter | The formatter instance when setting. |
The formatter instance.
parse(string $time = 'now', \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from a string. This is an alias for the constructor that allows better fluent syntax as it allows you to do ChronosInterface::parse('Monday next week')->fn() rather than (new Chronos('Monday next week'))->fn()
string | $time | The strtotime compatible string to parse |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name. |
maxValue() : \Cake\Chronos\ChronosInterface
Create a ChronosInterface instance for the greatest supported date.
minValue() : \Cake\Chronos\ChronosInterface
Create a ChronosInterface instance for the lowest supported date.
create(integer|null $year = null, integer|null $month = null, integer|null $day = null, integer|null $hour = null, integer|null $minute = null, integer|null $second = null, \DateTimeZone|string|null $tz = null) : static
Create a new ChronosInterface instance from a specific date and time.
If any of $year, $month or $day are set to null their now() values will be used.
If $hour is null it will be set to its now() value and the default values for $minute and $second will be their now() values. If $hour is not null then the default values for $minute and $second will be 0.
integer|null | $year | The year to create an instance with. |
integer|null | $month | The month to create an instance with. |
integer|null | $day | The day to create an instance with. |
integer|null | $hour | The hour to create an instance with. |
integer|null | $minute | The minute to create an instance with. |
integer|null | $second | The second to create an instance with. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
createFromDate(integer $year = null, integer $month = null, integer $day = null, \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from just a date. The time portion is set to now.
integer | $year | The year to create an instance with. |
integer | $month | The month to create an instance with. |
integer | $day | The day to create an instance with. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
createFromTime(integer|null $hour = null, integer|null $minute = null, integer|null $second = null, \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from just a time. The date portion is set to today.
integer|null | $hour | The hour to create an instance with. |
integer|null | $minute | The minute to create an instance with. |
integer|null | $second | The second to create an instance with. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
createFromFormat(string $format, string $time, \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from a specific format
string | $format | The date() compatible format string. |
string | $time | The formatted date string to interpret. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
createFromTimestamp(integer $timestamp, \DateTimeZone|string|null $tz = null) : static
Create a ChronosInterface instance from a timestamp
integer | $timestamp | The timestamp to create an instance from. |
\DateTimeZone|string|null | $tz | The DateTimeZone object or timezone name the new instance should use. |
setTime(integer $hours, integer $minutes, integer $seconds = null, integer $microseconds = null) : static
Modify the time on the Date.
This method ignores all inputs and forces all inputs to 0.
integer | $hours | The hours to set (ignored) |
integer | $minutes | The minutes to set (ignored) |
integer | $seconds | The seconds to set (ignored) |
integer | $microseconds | The microseconds to set (ignored) |
A modified Date instance.
modify(string $relative) : static
Overloaded to ignore time changes.
Changing any aspect of the time will be ignored, and the resulting object will have its time frozen to 00:00:00.
string | $relative | The relative change to make. |
A new date with the applied date changes.
setDateTime(integer $year, integer $month, integer $day, integer $hour, integer $minute, integer $second) : static
Set the date and time all together
integer | $year | The year to set. |
integer | $month | The month to set. |
integer | $day | The day to set. |
integer | $hour | The hour to set. |
integer | $minute | The minute to set. |
integer | $second | The second to set. |
addMonths(integer $value) : static
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month.
(new Chronos('2015-01-03'))->addMonths(1); // Results in 2015-02-03
(new Chronos('2015-01-31'))->addMonths(1); // Results in 2015-02-28
integer | $value | The number of months to add. |
addMonth(integer $value = 1) : static
Add a month to the instance
When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month.
(new Chronos('2015-01-03'))->addMonth(); // Results in 2015-02-03
(new Chronos('2015-01-31'))->addMonth(); // Results in 2015-02-28
integer | $value | The number of months to add. |
subMonth(integer $value = 1) : static
Remove a month from the instance
When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month.
(new Chronos('2015-03-01'))->subMonth(); // Results in 2015-02-01
(new Chronos('2015-03-31'))->subMonth(); // Results in 2015-02-28
integer | $value | The number of months to remove. |
subMonths(integer $value) : static
Remove months from the instance
When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month.
(new Chronos('2015-03-01'))->subMonths(1); // Results in 2015-02-01
(new Chronos('2015-03-31'))->subMonths(1); // Results in 2015-02-28
integer | $value | The number of months to remove. |
next(integer|null $dayOfWeek = null) : mixed
Modify to the next occurrence of a given day of the week.
If no dayOfWeek is provided, modify to the next occurrence of the current day of the week. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
previous(integer|null $dayOfWeek = null) : mixed
Modify to the previous occurrence of a given day of the week.
If no dayOfWeek is provided, modify to the previous occurrence of the current day of the week. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
firstOfMonth(integer|null $dayOfWeek = null) : mixed
Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
lastOfMonth(integer|null $dayOfWeek = null) : mixed
Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
nthOfMonth(integer $nth, integer $dayOfWeek) : mixed
Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer | $nth | The offset to use. |
integer | $dayOfWeek | The day of the week to move to. |
firstOfQuarter(integer|null $dayOfWeek = null) : mixed
Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
lastOfQuarter(integer|null $dayOfWeek = null) : mixed
Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
nthOfQuarter(integer $nth, integer $dayOfWeek) : mixed
Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.
Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer | $nth | The offset to use. |
integer | $dayOfWeek | The day of the week to move to. |
firstOfYear(integer|null $dayOfWeek = null) : mixed
Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
lastOfYear(integer|null $dayOfWeek = null) : mixed
Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer|null | $dayOfWeek | The day of the week to move to. |
nthOfYear(integer $nth, integer $dayOfWeek) : mixed
Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.
Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
integer | $nth | The offset to use. |
integer | $dayOfWeek | The day of the week to move to. |
average(\Cake\Chronos\ChronosInterface|null $dt = null) : static
Modify the current instance to the average of a given instance (default now) and the current instance.
\Cake\Chronos\ChronosInterface|null | $dt | The instance to compare with. |
setTestNow(\Cake\Chronos\ChronosInterface|string|null $testNow = null) : void
Set the test now used by Date and Time classes provided by Chronos
\Cake\Chronos\ChronosInterface|string|null | $testNow | The instance to use for all future instances. |
__construct(string|null $time = 'now')
Create a new mutable Date instance.
Please see the testing aids section (specifically static::setTestNow()) for more on the possibility of this constructor returning a test instance.
Date instances lack time components, however due to limitations in PHP's internal Datetime object the time will always be set to 00:00:00, and the timezone will always be UTC. Normalizing the timezone allows for subtraction/addition to have deterministic results.
string|null | $time | Fixed or relative time |
toImmutable() : \Cake\Chronos\Date
Create a new immutable instance from current mutable instance.
stripTime(string|integer $time) : string
Removes the time components from an input string.
Used to ensure constructed objects always lack time.
string|integer | $time | The input time. Integer values will be assumed to be in UTC. The 'now' and '' values will use the current local time. |
The date component of $time.