Interface ChronosInterface
An extension to the DateTimeInterface for a friendlier API
Constants
-
intDAYS_PER_WEEK ¶7 -
stringDEFAULT_TO_STRING_FORMAT ¶'Y-m-d H:i:s'Default format to use for __toString method when type juggling occurs.
-
intFRIDAY ¶5 -
intHOURS_PER_DAY ¶24 -
intMINUTES_PER_HOUR ¶60 -
intMONDAY ¶1 -
intMONTHS_PER_QUARTER ¶3 -
intMONTHS_PER_YEAR ¶12 -
intSATURDAY ¶6 -
intSECONDS_PER_MINUTE ¶60 -
intSUNDAY ¶7 -
intTHURSDAY ¶4 -
intTUESDAY ¶2 -
intWEDNESDAY ¶3 -
intWEEKS_PER_YEAR ¶52 -
intYEARS_PER_CENTURY ¶100 -
intYEARS_PER_DECADE ¶10
Method Summary
-
addDay() public
Add a day to the instance
-
addDays() public
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
-
addHour() public
Add an hour to the instance
-
addHours() public
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
-
addMinute() public
Add a minute to the instance
-
addMinutes() public
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
-
addMonth() public
Add a month to the instance
-
addMonthWithOverflow() public
Add a month with overflow to the instance
-
addMonths() public
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
-
addMonthsWithOverflow() public
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
-
addSecond() public
Add a second to the instance
-
addSeconds() public
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
-
addWeek() public
Add a week to the instance
-
addWeekday() public
Add a weekday to the instance
-
addWeekdays() public
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
-
addWeeks() public
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
-
addYear() public
Add a year to the instance
-
addYears() public
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
-
average() public
Modify the current instance to the average of a given instance (default now) and the current instance.
-
between() public
Determines if the instance is between two others
-
closest() public
Get the closest date from the instance.
-
copy() public
Get a copy of the instance
-
day() public
Set the instance's day
-
diffFiltered() public
Get the difference by the given interval using a filter callable
-
diffForHumans() public
Get the difference in a human readable format in the current locale.
-
diffInDays() public
Get the difference in days
-
diffInDaysFiltered() public
Get the difference in days using a filter callable
-
diffInHours() public
Get the difference in hours
-
diffInHoursFiltered() public
Get the difference in hours using a filter callable
-
diffInMinutes() public
Get the difference in minutes
-
diffInMonths() public
Get the difference in months
-
diffInSeconds() public
Get the difference in seconds
-
diffInWeekdays() public
Get the difference in weekdays
-
diffInWeekendDays() public
Get the difference in weekend days using a filter
-
diffInWeeks() public
Get the difference in weeks
-
diffInYears() public
Get the difference in years
-
endOfCentury() public
Resets the date to end of the century and time to 23:59:59
-
endOfDay() public
Resets the time to 23:59:59
-
endOfDecade() public
Resets the date to end of the decade and time to 23:59:59
-
endOfMonth() public
Resets the date to end of the month and time to 23:59:59
-
endOfWeek() public
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
-
endOfYear() public
Resets the date to end of the year and time to 23:59:59
-
eq() public
Determines if the instance is equal to another
-
equals() public
Determines if the instance is equal to another
-
farthest() public
Get the farthest date from the instance.
-
firstOfMonth() public
Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
-
firstOfQuarter() public
Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
-
firstOfYear() public
Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
-
greaterThan() public
Determines if the instance is greater (after) than another
-
greaterThanOrEquals() public
Determines if the instance is greater (after) than or equal to another
-
gt() public
Determines if the instance is greater (after) than another
-
gte() public
Determines if the instance is greater (after) than or equal to another
-
hour() public
Set the instance's hour
-
isBirthday() public
Check if its the birthday. Compares the date/month values of the two dates.
-
isFriday() public
Checks if this day is a Friday.
-
isFuture() public
Determines if the instance is in the future, ie. greater (after) than now
-
isLeapYear() public
Determines if the instance is a leap year
-
isMonday() public
Checks if this day is a Monday.
-
isMutable() public
Check if instance of ChronosInterface is mutable.
-
isPast() public
Determines if the instance is in the past, ie. less (before) than now
-
isSameDay() public
Checks if the passed in date is the same day as the instance current day.
-
isSaturday() public
Checks if this day is a Saturday.
-
isSunday() public
Checks if this day is a Sunday.
-
isThisMonth() public
Returns true if this object represents a date within the current month
-
isThisWeek() public
Returns true if this object represents a date within the current week
-
isThisYear() public
Returns true if this object represents a date within the current year
-
isThursday() public
Checks if this day is a Thursday.
-
isToday() public
Determines if the instance is today
-
isTomorrow() public
Determines if the instance is tomorrow
-
isTuesday() public
Checks if this day is a Tuesday.
-
isWednesday() public
Checks if this day is a Wednesday.
-
isWeekday() public
Determines if the instance is a weekday
-
isWeekend() public
Determines if the instance is a weekend day
-
isWithinNext() public
Returns true this instance will happen within the specified interval
-
isYesterday() public
Determines if the instance is yesterday
-
lastOfMonth() public
Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
-
lastOfQuarter() public
Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
-
lastOfYear() public
Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
-
lessThan() public
Determines if the instance is less (before) than another
-
lessThanOrEquals() public
Determines if the instance is less (before) or equal to another
-
lt() public
Determines if the instance is less (before) than another
-
lte() public
Determines if the instance is less (before) or equal to another
-
max() public
Get the maximum instance between a given instance (default now) and the current instance.
-
min() public
Get the minimum instance between a given instance (default now) and the current instance.
-
minute() public
Set the instance's minute
-
modify() public @method
-
month() public
Set the instance's month
-
ne() public
Determines if the instance is not equal to another
-
next() public
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.
-
notEquals() public
Determines if the instance is not equal to another
-
now() public static
Get a ChronosInterface instance for the current date and time
-
nthOfMonth() public
Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
-
nthOfQuarter() public
Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
-
nthOfYear() public
Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made. Use the supplied consts to indicate the desired dayOfWeek, ex. static::MONDAY.
-
previous() public
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.
-
second() public
Set the instance's second
-
secondsSinceMidnight() public
The number of seconds since midnight.
-
secondsUntilEndOfDay() public
The number of seconds until 23:59:59.
-
setDateTime() public
Set the date and time all together
-
setTimeFromTimeString() public
Set the time by time string
-
setTimezone() public
Set the instance's timezone from a string or object
-
startOfCentury() public
Resets the date to the first day of the century and the time to 00:00:00
-
startOfDay() public
Resets the time to 00:00:00
-
startOfDecade() public
Resets the date to the first day of the decade and the time to 00:00:00
-
startOfMonth() public
Resets the date to the first day of the month and the time to 00:00:00
-
startOfWeek() public
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
-
startOfYear() public
Resets the date to the first day of the year and the time to 00:00:00
-
subDay() public
Remove a day from the instance
-
subDays() public
Remove days from the instance
-
subHour() public
Remove an hour from the instance
-
subHours() public
Remove hours from the instance
-
subMinute() public
Remove a minute from the instance
-
subMinutes() public
Remove minutes from the instance
-
subMonth() public
Remove a month from the instance
-
subMonthWithOverflow() public
Remove a month with overflow from the instance
-
subMonths() public
Remove months from the instance
-
subMonthsWithOverflow() public
Remove months with overflow from the instance
-
subSecond() public
Remove a second from the instance
-
subSeconds() public
Remove seconds from the instance
-
subWeek() public
Remove a week from the instance
-
subWeekday() public
Remove a weekday from the instance
-
subWeekdays() public
Remove weekdays from the instance
-
subWeeks() public
Remove weeks to the instance
-
subYear() public
Remove a year from the instance
-
subYears() public
Remove years from the instance.
-
timestamp() public
Set the instance's timestamp
-
timezone() public
Alias for setTimezone()
-
toAtomString() public
Format the instance as ATOM
-
toCookieString() public
Format the instance as COOKIE
-
toDateString() public
Format the instance as date
-
toDateTimeString() public
Format the instance as date and time
-
toDayDateTimeString() public
Format the instance with day, date and time
-
toFormattedDateString() public
Format the instance as a readable date
-
toIso8601String() public
Format the instance as ISO8601
-
toRfc1036String() public
Format the instance as RFC1036
-
toRfc1123String() public
Format the instance as RFC1123
-
toRfc2822String() public
Format the instance as RFC2822
-
toRfc3339String() public
Format the instance as RFC3339
-
toRfc822String() public
Format the instance as RFC822
-
toRfc850String() public
Format the instance as RFC850
-
toRssString() public
Format the instance as RSS
-
toTimeString() public
Format the instance as time
-
toW3cString() public
Format the instance as W3C
-
tz() public
Alias for setTimezone()
-
wasWithinLast() public
Returns true this instance happened within the specified interval
-
year() public
Set the instance's year
Method Detail
addDay() ¶ public
addDay(int $value = 1): static
Add a day to the instance
Parameters
-
int$value optional The number of days to add.
Returns
staticaddDays() ¶ public
addDays(int $value): static
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of days to add.
Returns
staticaddHour() ¶ public
addHour(int $value = 1): static
Add an hour to the instance
Parameters
-
int$value optional The number of hours to add.
Returns
staticaddHours() ¶ public
addHours(int $value): static
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of hours to add.
Returns
staticaddMinute() ¶ public
addMinute(int $value = 1): static
Add a minute to the instance
Parameters
-
int$value optional The number of minutes to add.
Returns
staticaddMinutes() ¶ public
addMinutes(int $value): static
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of minutes to add.
Returns
staticaddMonth() ¶ public
addMonth(int $value = 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.
Example:
(new Chronos('2015-01-03'))->addMonth(); // Results in 2015-02-03
(new Chronos('2015-01-31'))->addMonth(); // Results in 2015-02-28
Parameters
-
int$value optional The number of months to add.
Returns
staticaddMonthWithOverflow() ¶ public
addMonthWithOverflow(int $value = 1): static
Add a month with overflow to the instance
Parameters
-
int$value optional The number of months to add.
Returns
staticaddMonths() ¶ public
addMonths(int $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.
Example:
(new Chronos('2015-01-03'))->addMonths(1); // Results in 2015-02-03
(new Chronos('2015-01-31'))->addMonths(1); // Results in 2015-02-28
Parameters
-
int$value The number of months to add.
Returns
staticaddMonthsWithOverflow() ¶ public
addMonthsWithOverflow(int $value): static
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of months to add.
Returns
staticaddSecond() ¶ public
addSecond(int $value = 1): static
Add a second to the instance
Parameters
-
int$value optional The number of seconds to add.
Returns
staticaddSeconds() ¶ public
addSeconds(int $value): static
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of seconds to add.
Returns
staticaddWeek() ¶ public
addWeek(int $value = 1): static
Add a week to the instance
Parameters
-
int$value optional The number of weeks to add.
Returns
staticaddWeekday() ¶ public
addWeekday(int $value = 1): static
Add a weekday to the instance
Parameters
-
int$value optional The number of weekdays to add.
Returns
staticaddWeekdays() ¶ public
addWeekdays(int $value): static
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of weekdays to add.
Returns
staticaddWeeks() ¶ public
addWeeks(int $value): static
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
Parameters
-
int$value The number of weeks to add.
Returns
staticaddYear() ¶ public
addYear(int $value = 1): static
Add a year to the instance
Parameters
-
int$value optional The number of years to add.
Returns
staticaddYears() ¶ public
addYears(int $value): static
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
Parameters
-
int$value The number of years to add.
Returns
staticaverage() ¶ public
average(Cake\Chronos\ChronosInterface $dt = null): static
Modify the current instance to the average of a given instance (default now) and the current instance.
Parameters
-
Cake\Chronos\ChronosInterface$dt optional The instance to compare with.
Returns
staticbetween() ¶ public
between(Cake\Chronos\ChronosInterface $dt1, Cake\Chronos\ChronosInterface $dt2, bool $equal = true): bool
Determines if the instance is between two others
Parameters
-
Cake\Chronos\ChronosInterface$dt1 The instance to compare with.
-
Cake\Chronos\ChronosInterface$dt2 The instance to compare with.
-
bool$equal optional Indicates if a > and < comparison should be used or <= or >=
Returns
boolclosest() ¶ public
closest(Cake\Chronos\ChronosInterface $dt1, Cake\Chronos\ChronosInterface $dt2): static
Get the closest date from the instance.
Parameters
-
Cake\Chronos\ChronosInterface$dt1 The instance to compare with.
-
Cake\Chronos\ChronosInterface$dt2 The instance to compare with.
Returns
staticday() ¶ public
day(int $value): static
Set the instance's day
Parameters
-
int$value The day value.
Returns
staticdiffFiltered() ¶ public
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
Parameters
-
Cake\Chronos\ChronosInterval$ci An interval to traverse by
-
callable$callback The callback to use for filtering.
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffForHumans() ¶ public
diffForHumans(Cake\Chronos\ChronosInterface|null $other = null, bool $absolute = false): string
Get the difference in a human readable format in the current locale.
When comparing a value in the past to default now: 1 hour ago 5 months ago
When comparing a value in the future to default now: 1 hour from now 5 months from now
When comparing a value in the past to another value: 1 hour before 5 months before
When comparing a value in the future to another value: 1 hour after 5 months after
Parameters
-
Cake\Chronos\ChronosInterface|null$other optional The datetime to compare with.
-
bool$absolute optional Removes time difference modifiers ago, after, etc
Returns
stringdiffInDays() ¶ public
diffInDays(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in days
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInDaysFiltered() ¶ public
diffInDaysFiltered(callable $callback, Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in days using a filter callable
Parameters
-
callable$callback The callback to use for filtering.
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInHours() ¶ public
diffInHours(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in hours
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInHoursFiltered() ¶ public
diffInHoursFiltered(callable $callback, Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in hours using a filter callable
Parameters
-
callable$callback The callback to use for filtering.
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInMinutes() ¶ public
diffInMinutes(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in minutes
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInMonths() ¶ public
diffInMonths(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in months
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInSeconds() ¶ public
diffInSeconds(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in seconds
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInWeekdays() ¶ public
diffInWeekdays(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in weekdays
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInWeekendDays() ¶ public
diffInWeekendDays(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in weekend days using a filter
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInWeeks() ¶ public
diffInWeeks(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in weeks
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intdiffInYears() ¶ public
diffInYears(Cake\Chronos\ChronosInterface|null $dt = null, bool $abs = true): int
Get the difference in years
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to difference from.
-
bool$abs optional Get the absolute of the difference
Returns
intendOfCentury() ¶ public
endOfCentury(): static
Resets the date to end of the century and time to 23:59:59
Returns
staticendOfDecade() ¶ public
endOfDecade(): static
Resets the date to end of the decade and time to 23:59:59
Returns
staticendOfMonth() ¶ public
endOfMonth(): static
Resets the date to end of the month and time to 23:59:59
Returns
staticendOfWeek() ¶ public
endOfWeek(): static
Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
Returns
staticendOfYear() ¶ public
endOfYear(): static
Resets the date to end of the year and time to 23:59:59
Returns
staticeq() ¶ public
eq(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is equal to another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
equals() ¶ public
equals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is equal to another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolfarthest() ¶ public
farthest(Cake\Chronos\ChronosInterface $dt1, Cake\Chronos\ChronosInterface $dt2): static
Get the farthest date from the instance.
Parameters
-
Cake\Chronos\ChronosInterface$dt1 The instance to compare with.
-
Cake\Chronos\ChronosInterface$dt2 The instance to compare with.
Returns
staticfirstOfMonth() ¶ public
firstOfMonth(int $dayOfWeek = 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.
Parameters
-
int$dayOfWeek optional The day of the week to move to.
Returns
mixedfirstOfQuarter() ¶ public
firstOfQuarter(int $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.
Parameters
-
int$dayOfWeek optional The day of the week to move to.
Returns
mixedfirstOfYear() ¶ public
firstOfYear(int $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.
Parameters
-
int$dayOfWeek optional The day of the week to move to.
Returns
mixedgreaterThan() ¶ public
greaterThan(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolgreaterThanOrEquals() ¶ public
greaterThanOrEquals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than or equal to another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolgt() ¶ public
gt(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
gte() ¶ public
gte(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is greater (after) than or equal to another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
hour() ¶ public
hour(int $value): static
Set the instance's hour
Parameters
-
int$value The hour value.
Returns
staticisBirthday() ¶ public
isBirthday(Cake\Chronos\ChronosInterface $dt): bool
Check if its the birthday. Compares the date/month values of the two dates.
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolisFuture() ¶ public
isFuture(): bool
Determines if the instance is in the future, ie. greater (after) than now
Returns
boolisMutable() ¶ public
isMutable(): bool
Check if instance of ChronosInterface is mutable.
Returns
boolisPast() ¶ public
isPast(): bool
Determines if the instance is in the past, ie. less (before) than now
Returns
boolisSameDay() ¶ public
isSameDay(Cake\Chronos\ChronosInterface $dt): bool
Checks if the passed in date is the same day as the instance current day.
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to check against.
Returns
boolisThisMonth() ¶ public
isThisMonth(): bool
Returns true if this object represents a date within the current month
Returns
boolisThisWeek() ¶ public
isThisWeek(): bool
Returns true if this object represents a date within the current week
Returns
boolisThisYear() ¶ public
isThisYear(): bool
Returns true if this object represents a date within the current year
Returns
boolisWithinNext() ¶ public
isWithinNext(string|int $timeInterval): bool
Returns true this instance will happen within the specified interval
Parameters
-
string|int$timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
Returns
boollastOfMonth() ¶ public
lastOfMonth(int $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.
Parameters
-
int$dayOfWeek optional The day of the week to move to.
Returns
mixedlastOfQuarter() ¶ public
lastOfQuarter(int $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.
Parameters
-
int$dayOfWeek optional The day of the week to move to.
Returns
mixedlastOfYear() ¶ public
lastOfYear(int $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.
Parameters
-
int$dayOfWeek optional The day of the week to move to.
Returns
mixedlessThan() ¶ public
lessThan(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) than another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boollessThanOrEquals() ¶ public
lessThanOrEquals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) or equal to another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boollt() ¶ public
lt(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) than another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
lte() ¶ public
lte(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is less (before) or equal to another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
max() ¶ public
max(Cake\Chronos\ChronosInterface|null $dt = null): static
Get the maximum instance between a given instance (default now) and the current instance.
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to compare with.
Returns
staticmin() ¶ public
min(Cake\Chronos\ChronosInterface|null $dt = null): static
Get the minimum instance between a given instance (default now) and the current instance.
Parameters
-
Cake\Chronos\ChronosInterface|null$dt optional The instance to compare with.
Returns
staticminute() ¶ public
minute(int $value): static
Set the instance's minute
Parameters
-
int$value The minute value.
Returns
staticmodify() ¶ public @method
modify(string $relative): static
Parameters
-
string$relative
Returns
staticmonth() ¶ public
month(int $value): static
Set the instance's month
Parameters
-
int$value The month value.
Returns
staticne() ¶ public
ne(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is not equal to another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolSee Also
next() ¶ public
next(int $dayOfWeek = 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.
Parameters
-
int$dayOfWeek optional The day of the week to move to.
Returns
mixednotEquals() ¶ public
notEquals(Cake\Chronos\ChronosInterface $dt): bool
Determines if the instance is not equal to another
Parameters
-
Cake\Chronos\ChronosInterface$dt The instance to compare with.
Returns
boolnow() ¶ public static
now(DateTimeZone|string|null $tz): static
Get a ChronosInterface instance for the current date and time
Parameters
-
DateTimeZone|string|null$tz The DateTimeZone object or timezone name.
Returns
staticnthOfMonth() ¶ public
nthOfMonth(int $nth, int $dayOfWeek): 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.
Parameters
-
int$nth The offset to use.
-
int$dayOfWeek The day of the week to move to.
Returns
mixednthOfQuarter() ¶ public
nthOfQuarter(int $nth, int $dayOfWeek): 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.
Parameters
-
int$nth The offset to use.
-
int$dayOfWeek The day of the week to move to.
Returns
mixednthOfYear() ¶ public
nthOfYear(int $nth, int $dayOfWeek): 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.
Parameters
-
int$nth The offset to use.
-
int$dayOfWeek The day of the week to move to.
Returns
mixedprevious() ¶ public
previous(int $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.
Parameters
-
int$dayOfWeek optional The day of the week to move to.
Returns
mixedsecond() ¶ public
second(int $value): static
Set the instance's second
Parameters
-
int$value The seconds value.
Returns
staticsecondsSinceMidnight() ¶ public
secondsSinceMidnight(): int
The number of seconds since midnight.
Returns
intsecondsUntilEndOfDay() ¶ public
secondsUntilEndOfDay(): int
The number of seconds until 23:59:59.
Returns
intsetDateTime() ¶ public
setDateTime(int $year, int $month, int $day, int $hour, int $minute, int $second = 0): static
Set the date and time all together
Parameters
-
int$year The year to set.
-
int$month The month to set.
-
int$day The day to set.
-
int$hour The hour to set.
-
int$minute The minute to set.
-
int$second optional The second to set.
Returns
staticsetTimeFromTimeString() ¶ public
setTimeFromTimeString(string $time): static
Set the time by time string
Parameters
-
string$time Time as string.
Returns
staticsetTimezone() ¶ public
setTimezone(DateTimeZone|string $value): static
Set the instance's timezone from a string or object
Parameters
-
DateTimeZone|string$value The DateTimeZone object or timezone name to use.
Returns
staticstartOfCentury() ¶ public
startOfCentury(): static
Resets the date to the first day of the century and the time to 00:00:00
Returns
staticstartOfDecade() ¶ public
startOfDecade(): static
Resets the date to the first day of the decade and the time to 00:00:00
Returns
staticstartOfMonth() ¶ public
startOfMonth(): static
Resets the date to the first day of the month and the time to 00:00:00
Returns
staticstartOfWeek() ¶ public
startOfWeek(): static
Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
Returns
staticstartOfYear() ¶ public
startOfYear(): static
Resets the date to the first day of the year and the time to 00:00:00
Returns
staticsubDay() ¶ public
subDay(int $value = 1): static
Remove a day from the instance
Parameters
-
int$value optional The number of days to remove.
Returns
staticsubDays() ¶ public
subDays(int $value): static
Remove days from the instance
Parameters
-
int$value The number of days to remove.
Returns
staticsubHour() ¶ public
subHour(int $value = 1): static
Remove an hour from the instance
Parameters
-
int$value optional The number of hours to remove.
Returns
staticsubHours() ¶ public
subHours(int $value): static
Remove hours from the instance
Parameters
-
int$value The number of hours to remove.
Returns
staticsubMinute() ¶ public
subMinute(int $value = 1): static
Remove a minute from the instance
Parameters
-
int$value optional The number of minutes to remove.
Returns
staticsubMinutes() ¶ public
subMinutes(int $value): static
Remove minutes from the instance
Parameters
-
int$value The number of minutes to remove.
Returns
staticsubMonth() ¶ public
subMonth(int $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.
Example:
(new Chronos('2015-03-01'))->subMonth(); // Results in 2015-02-01
(new Chronos('2015-03-31'))->subMonth(); // Results in 2015-02-28
Parameters
-
int$value optional The number of months to remove.
Returns
staticsubMonthWithOverflow() ¶ public
subMonthWithOverflow(int $value = 1): static
Remove a month with overflow from the instance
Parameters
-
int$value optional The number of months to remove.
Returns
staticsubMonths() ¶ public
subMonths(int $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.
Example:
(new Chronos('2015-03-01'))->subMonths(1); // Results in 2015-02-01
(new Chronos('2015-03-31'))->subMonths(1); // Results in 2015-02-28
Parameters
-
int$value The number of months to remove.
Returns
staticsubMonthsWithOverflow() ¶ public
subMonthsWithOverflow(int $value): static
Remove months with overflow from the instance
Parameters
-
int$value The number of months to remove.
Returns
staticsubSecond() ¶ public
subSecond(int $value = 1): static
Remove a second from the instance
Parameters
-
int$value optional The number of seconds to remove.
Returns
staticsubSeconds() ¶ public
subSeconds(int $value): static
Remove seconds from the instance
Parameters
-
int$value The number of seconds to remove.
Returns
staticsubWeek() ¶ public
subWeek(int $value = 1): static
Remove a week from the instance
Parameters
-
int$value optional The number of weeks to remove.
Returns
staticsubWeekday() ¶ public
subWeekday(int $value = 1): static
Remove a weekday from the instance
Parameters
-
int$value optional The number of weekdays to remove.
Returns
staticsubWeekdays() ¶ public
subWeekdays(int $value): static
Remove weekdays from the instance
Parameters
-
int$value The number of weekdays to remove.
Returns
staticsubWeeks() ¶ public
subWeeks(int $value): static
Remove weeks to the instance
Parameters
-
int$value The number of weeks to remove.
Returns
staticsubYear() ¶ public
subYear(int $value = 1): static
Remove a year from the instance
Parameters
-
int$value optional The number of years to remove.
Returns
staticsubYears() ¶ public
subYears(int $value): static
Remove years from the instance.
Parameters
-
int$value The number of years to remove.
Returns
statictimestamp() ¶ public
timestamp(int $value): static
Set the instance's timestamp
Parameters
-
int$value The timestamp value to set.
Returns
statictimezone() ¶ public
timezone(DateTimeZone|string $value): static
Alias for setTimezone()
Parameters
-
DateTimeZone|string$value The DateTimeZone object or timezone name to use.
Returns
statictoDateTimeString() ¶ public
toDateTimeString(): string
Format the instance as date and time
Returns
stringtoDayDateTimeString() ¶ public
toDayDateTimeString(): string
Format the instance with day, date and time
Returns
stringtoFormattedDateString() ¶ public
toFormattedDateString(): string
Format the instance as a readable date
Returns
stringtz() ¶ public
tz(DateTimeZone|string $value): static
Alias for setTimezone()
Parameters
-
DateTimeZone|string$value The DateTimeZone object or timezone name to use.
Returns
staticwasWithinLast() ¶ public
wasWithinLast(string|int $timeInterval): bool
Returns true this instance happened within the specified interval
Parameters
-
string|int$timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
Returns
boolyear() ¶ public
year(int $value): static
Set the instance's year
Parameters
-
int$value The year value.
Returns
static