ChronosDate
extends DateTimeImmutable
in package
implements
ChronosInterface
uses
ComparisonTrait, DifferenceTrait, FactoryTrait, FormattingTrait, FrozenTimeTrait, MagicPropertyTrait, ModifierTrait, TestingAidTrait
An immutable 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.
Table of Contents
Interfaces
- ChronosInterface
- An extension to the DateTimeInterface for a friendlier API
Properties
- $age : int
- $day : int
- $dayOfWeek : int
- $dayOfYear : int
- $daysInMonth : int
- $dst : bool
- $hour : int
- $local : bool
- $micro : int
- $microsecond : int
- $minute : int
- $month : int
- $offset : int
- $offsetHours : int
- $quarter : int
- $second : int
- $timestamp : int
- $timezone : DateTimeZone
- $timezoneName : string
- $tz : DateTimeZone
- $tzName : string
- $utc : bool
- $weekOfMonth : int
- $weekOfYear : int
- $year : int
- $yearIso : int
- $_lastErrors : array<string|int, mixed>
- Holds the last error generated by createFromFormat
- $days : array<string|int, mixed>
- Names of days of the week.
- $diffFormatter : DifferenceFormatterInterface|null
- Instance of the diff formatting object.
- $toStringFormat : string
- Format to use for __toString method when type juggling occurs.
- $weekendDays : array<string|int, mixed>
- Days of weekend
- $weekEndsAt : int
- Last day of week
- $weekStartsAt : int
- First day of week
Methods
- __construct() : mixed
- Create a new Immutable Date instance.
- __debugInfo() : array<string|int, mixed>
- Return properties for debugging.
- __get() : string|int|bool|DateTimeZone
- Get a part of the ChronosInterface object
- __isset() : bool
- Check if an attribute exists on the object
- __toString() : string
- Format the instance as a string using the set format
- add() : static
- Add an Interval to a Date
- addDay() : static
- Add a day to the instance
- addDays() : static
- Add days to the instance. Positive $value travels forward while negative $value travels into the past.
- addHour() : static
- Add an hour to the instance
- addHours() : static
- Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
- addMinute() : static
- Add a minute to the instance
- addMinutes() : static
- Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonth() : static
- Add a month to the instance
- addMonths() : static
- Add months to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonthsWithOverflow() : static
- Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
- addMonthWithOverflow() : static
- Add a month with overflow to the instance.
- addSecond() : static
- Add a second to the instance
- addSeconds() : static
- Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
- addWeek() : static
- Add a week to the instance
- addWeekday() : static
- Add a weekday to the instance
- addWeekdays() : static
- Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
- addWeeks() : static
- Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
- addYear() : static
- Add a year to the instance.
- addYears() : static
- Add years to the instance. Positive $value travel forward while negative $value travel into the past.
- addYearsWithOverflow() : static
- Add years with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
- addYearWithOverflow() : static
- Add a year with overflow to the instance.
- average() : static
- Modify the current instance to the average of a given instance (default now) and the current instance.
- between() : bool
- Determines if the instance is between two others
- closest() : ChronosInterface
- Get the closest date from the instance.
- create() : static
- Create an instance from a specific date.
- createFromArray() : static
- Creates a ChronosInterface instance from an array of date and time values.
- createFromDate() : static
- Create a ChronosInterface instance from just a date. The time portion is set to now.
- createFromFormat() : static
- Create a ChronosInterface instance from a specific format
- createFromTime() : static
- Create a ChronosInterface instance from just a time. The date portion is set to today.
- createFromTimestamp() : static
- Create a ChronosInterface instance from a timestamp
- createFromTimestampUTC() : static
- Create a ChronosInterface instance from an UTC timestamp
- day() : static
- Set the instance's day
- diffFiltered() : int
- Get the difference by the given interval using a filter callable
- diffForHumans() : string
- Get the difference in a human readable format.
- diffFormatter() : DifferenceFormatterInterface
- Get the difference formatter instance or overwrite the current one.
- diffInDays() : int
- Get the difference in days
- diffInDaysFiltered() : int
- Get the difference in days using a filter callable
- diffInHours() : int
- Get the difference in hours
- diffInHoursFiltered() : int
- Get the difference in hours using a filter callable
- diffInMinutes() : int
- Get the difference in minutes
- diffInMonths() : int
- Get the difference in months
- diffInMonthsIgnoreTimezone() : 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.
- diffInSeconds() : int
- Get the difference in seconds
- diffInWeekdays() : int
- Get the difference in weekdays
- diffInWeekendDays() : int
- Get the difference in weekend days using a filter
- diffInWeeks() : int
- Get the difference in weeks
- diffInYears() : int
- Get the difference in years
- endOfCentury() : static
- Sets the date to end of the century and time to 23:59:59
- endOfDay() : static
- Sets the time to 23:59:59 or 23:59:59.999999 if `$microseconds` is true.
- endOfDecade() : static
- Sets the date to end of the decade and time to 23:59:59
- endOfMonth() : static
- Sets the date to end of the month and time to 23:59:59
- endOfWeek() : static
- Sets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
- endOfYear() : static
- Sets the date to end of the year and time to 23:59:59
- eq() : bool
- Determines if the instance is equal to another
- equals() : bool
- Determines if the instance is equal to another
- farthest() : ChronosInterface
- Get the farthest date from the instance.
- firstOfMonth() : static
- 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.
- firstOfQuarter() : static
- 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.
- firstOfYear() : static
- 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.
- fromNow() : DateInterval|bool
- Convenience method for getting the remaining time from a given time.
- getLastErrors() : array<string|int, mixed>
- Returns any errors or warnings that were found during the parsing of the last object created by this class.
- getTestNow() : ChronosInterface|null
- Get the test instance stored in Chronos
- getWeekendDays() : array<string|int, mixed>
- Get weekend days
- getWeekEndsAt() : int
- Get the last day of week
- getWeekStartsAt() : int
- Get the first day of week
- greaterThan() : bool
- Determines if the instance is greater (after) than another
- greaterThanOrEquals() : bool
- Determines if the instance is greater (after) than or equal to another
- gt() : bool
- Determines if the instance is greater (after) than another
- gte() : bool
- Determines if the instance is greater (after) than or equal to another
- hasTestNow() : bool
- Get whether or not Chronos has a test instance set.
- hour() : static
- Set the instance's hour
- instance() : static
- Create a ChronosInterface instance from a DateTimeInterface one
- isBirthday() : bool
- Check if its the birthday. Compares the date/month values of the two dates.
- isFriday() : bool
- Checks if this day is a Friday.
- isFuture() : bool
- Determines if the instance is in the future, ie. greater (after) than now
- isLastMonth() : bool
- Determines if the instance is within the last month
- isLastWeek() : bool
- Determines if the instance is within the last week
- isLastYear() : bool
- Determines if the instance is within the last year
- isLeapYear() : bool
- Determines if the instance is a leap year
- isMonday() : bool
- Checks if this day is a Monday.
- isMutable() : bool
- Check if instance of ChronosInterface is mutable.
- isNextMonth() : bool
- Determines if the instance is within the next month
- isNextWeek() : bool
- Determines if the instance is within the next week
- isNextYear() : bool
- Determines if the instance is within the next year
- isPast() : bool
- Determines if the instance is in the past, ie. less (before) than now
- isSameDay() : bool
- Checks if the passed in date is the same day as the instance current day.
- isSaturday() : bool
- Checks if this day is a Saturday.
- isSunday() : bool
- Checks if this day is a Sunday.
- isThisMonth() : bool
- Returns true if this object represents a date within the current month
- isThisWeek() : bool
- Returns true if this object represents a date within the current week
- isThisYear() : bool
- Returns true if this object represents a date within the current year
- isThursday() : bool
- Checks if this day is a Thursday.
- isToday() : bool
- Determines if the instance is today
- isTomorrow() : bool
- Determines if the instance is tomorrow
- isTuesday() : bool
- Checks if this day is a Tuesday.
- isWednesday() : bool
- Checks if this day is a Wednesday.
- isWeekday() : bool
- Determines if the instance is a weekday
- isWeekend() : bool
- Determines if the instance is a weekend day
- isWithinNext() : bool
- Returns true this instance will happen within the specified interval
- isYesterday() : bool
- Determines if the instance is yesterday
- lastOfMonth() : static
- 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.
- lastOfQuarter() : static
- 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.
- lastOfYear() : static
- 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.
- lessThan() : bool
- Determines if the instance is less (before) than another
- lessThanOrEquals() : bool
- Determines if the instance is less (before) or equal to another
- lt() : bool
- Determines if the instance is less (before) than another
- lte() : bool
- Determines if the instance is less (before) or equal to another
- max() : ChronosInterface
- Get the maximum instance between a given instance (default now) and the current instance.
- maxValue() : ChronosInterface
- Create a ChronosInterface instance for the greatest supported date.
- microsecond() : static
- Set the instance's microsecond
- min() : ChronosInterface
- Get the minimum instance between a given instance (default now) and the current instance.
- minute() : static
- Set the instance's minute
- minValue() : ChronosInterface
- Create a ChronosInterface instance for the lowest supported date.
- modify() : static
- Creates a new instance with date modified according to DateTimeImmutable::modifier().
- month() : static
- Set the instance's month
- ne() : bool
- Determines if the instance is not equal to another
- next() : static
- Modify to the next occurrence of a given day of the week.
- notEquals() : bool
- Determines if the instance is not equal to another
- now() : static
- Get a ChronosInterface instance for the current date and time
- nthOfMonth() : static|false
- Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made.
- nthOfQuarter() : static|false
- Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made.
- nthOfYear() : static|false
- Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made.
- parse() : 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()
- previous() : static
- Modify to the previous occurrence of a given day of the week.
- resetToStringFormat() : void
- Reset the format used to the default when type juggling a ChronosInterface instance to a string
- second() : static
- Set the instance's second
- secondsSinceMidnight() : int
- The number of seconds since midnight.
- secondsUntilEndOfDay() : int
- The number of seconds until 23:59:59.
- setDate() : static
- Set the date to a different date.
- setDateTime() : static
- Set the date and time all together
- setTestNow() : void
- Set the test now used by Date and Time classes provided by Chronos
- setTime() : static
- Modify the time on the Date.
- setTimeFromTimeString() : static
- Set the time by time string
- setTimestamp() : mixed
- setTimezone() : $this
- No-op method.
- setToStringFormat() : void
- Set the default format used when type juggling a ChronosInterface instance to a string
- setWeekendDays() : void
- Set weekend days
- setWeekEndsAt() : void
- Set the last day of week
- setWeekStartsAt() : void
- Set the first day of week
- startOfCentury() : static
- Sets the date to the first day of the century and the time to 00:00:00
- startOfDay() : static
- Sets the time to 00:00:00
- startOfDecade() : static
- Sets the date to the first day of the decade and the time to 00:00:00
- startOfMonth() : static
- Sets the date to the first day of the month and the time to 00:00:00
- startOfWeek() : static
- Sets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
- startOfYear() : static
- Sets the date to the first day of the year and the time to 00:00:00
- sub() : static
- Subtract an Interval from a Date.
- subDay() : static
- Remove a day from the instance
- subDays() : static
- Remove days from the instance
- subHour() : static
- Remove an hour from the instance
- subHours() : static
- Remove hours from the instance
- subMinute() : static
- Remove a minute from the instance
- subMinutes() : static
- Remove minutes from the instance
- subMonth() : static
- Remove a month from the instance
- subMonths() : static
- Remove months from the instance
- subMonthsWithOverflow() : static
- Remove months with overflow from the instance.
- subMonthWithOverflow() : static
- Remove a month with overflow from the instance.
- subSecond() : static
- Remove a second from the instance
- subSeconds() : static
- Remove seconds from the instance
- subWeek() : static
- Remove a week from the instance
- subWeekday() : static
- Remove a weekday from the instance
- subWeekdays() : static
- Remove weekdays from the instance
- subWeeks() : static
- Remove weeks to the instance
- subYear() : static
- Remove a year from the instance
- subYears() : static
- Remove years from the instance.
- subYearsWithOverflow() : static
- Remove years with overflow from the instance
- subYearWithOverflow() : static
- Remove a year with overflow from the instance.
- timestamp() : static
- Set the instance's timestamp
- timezone() : $this
- No-op method.
- toAtomString() : string
- Format the instance as ATOM
- toCookieString() : string
- Format the instance as COOKIE
- toDateString() : string
- Format the instance as date
- toDateTimeString() : string
- Format the instance as date and time
- today() : static
- Create a ChronosInterface instance for today
- toDayDateTimeString() : string
- Format the instance with day, date and time
- toFormattedDateString() : string
- Format the instance as a readable date
- toIso8601String() : string
- Format the instance as ISO8601
- tomorrow() : static
- Create a ChronosInterface instance for tomorrow
- toMutable() : MutableDate
- Create a new mutable instance from current immutable instance.
- toQuarter() : int|array<string|int, mixed>
- Returns the quarter
- toRfc1036String() : string
- Format the instance as RFC1036
- toRfc1123String() : string
- Format the instance as RFC1123
- toRfc2822String() : string
- Format the instance as RFC2822
- toRfc3339String() : string
- Format the instance as RFC3339
- toRfc822String() : string
- Format the instance as RFC822
- toRfc850String() : string
- Format the instance as RFC850
- toRssString() : string
- Format the instance as RSS
- toTimeString() : string
- Format the instance as time
- toUnixString() : string
- Returns a UNIX timestamp.
- toW3cString() : string
- Format the instance as W3C
- toWeek() : int
- tz() : $this
- No-op method.
- wasWithinLast() : bool
- Returns true this instance happened within the specified interval
- year() : static
- Set the instance's year
- yesterday() : static
- Create a ChronosInterface instance for yesterday
- safeCreateDateTimeZone() : DateTimeZone
- Creates a DateTimeZone from a string or a DateTimeZone
- stripRelativeTime() : string
- Remove time components from strtotime relative strings.
- stripTime() : string
- Removes the time components from an input string.
- setDateParent() : static
- Just calling to parent setDate It used in overwritten setDate
Properties
$age read-only
public
int
$age
does a diffInYears() with default parameters
$day read-only
public
int
$day
$dayOfWeek read-only
public
int
$dayOfWeek
1 (for Monday) through 7 (for Sunday)
$dayOfYear read-only
public
int
$dayOfYear
0 through 365
$daysInMonth read-only
public
int
$daysInMonth
number of days in the given month
$dst read-only
public
bool
$dst
daylight savings time indicator, true if DST, false otherwise
$hour read-only
public
int
$hour
$local read-only
public
bool
$local
checks if the timezone is local, true if local, false otherwise
$micro read-only
public
int
$micro
$microsecond read-only
public
int
$microsecond
$minute read-only
public
int
$minute
$month read-only
public
int
$month
$offset read-only
public
int
$offset
the timezone offset in seconds from UTC
$offsetHours read-only
public
int
$offsetHours
the timezone offset in hours from UTC
$quarter read-only
public
int
$quarter
the quarter of this instance, 1 - 4
$second read-only
public
int
$second
$timestamp read-only
public
int
$timestamp
seconds since the Unix Epoch
$timezone read-only
public
DateTimeZone
$timezone
the current timezone
$timezoneName read-only
public
string
$timezoneName
$tz read-only
public
DateTimeZone
$tz
alias of timezone
$tzName read-only
public
string
$tzName
$utc read-only
public
bool
$utc
checks if the timezone is UTC, true if UTC, false otherwise
$weekOfMonth read-only
public
int
$weekOfMonth
1 through 5
$weekOfYear read-only
public
int
$weekOfYear
ISO-8601 week number of year, weeks starting on Monday
$year read-only
public
int
$year
$yearIso read-only
public
int
$yearIso
$_lastErrors
Holds the last error generated by createFromFormat
protected
static array<string|int, mixed>
$_lastErrors
= []
$days
Names of days of the week.
protected
static array<string|int, mixed>
$days
= [\Cake\Chronos\ChronosInterface::MONDAY => 'Monday', \Cake\Chronos\ChronosInterface::TUESDAY => 'Tuesday', \Cake\Chronos\ChronosInterface::WEDNESDAY => 'Wednesday', \Cake\Chronos\ChronosInterface::THURSDAY => 'Thursday', \Cake\Chronos\ChronosInterface::FRIDAY => 'Friday', \Cake\Chronos\ChronosInterface::SATURDAY => 'Saturday', \Cake\Chronos\ChronosInterface::SUNDAY => 'Sunday']
$diffFormatter
Instance of the diff formatting object.
protected
static DifferenceFormatterInterface|null
$diffFormatter
$toStringFormat
Format to use for __toString method when type juggling occurs.
protected
static string
$toStringFormat
= 'Y-m-d'
$weekendDays
Days of weekend
protected
static array<string|int, mixed>
$weekendDays
= [\Cake\Chronos\ChronosInterface::SATURDAY, \Cake\Chronos\ChronosInterface::SUNDAY]
$weekEndsAt
Last day of week
protected
static int
$weekEndsAt
= \Cake\Chronos\ChronosInterface::SUNDAY
$weekStartsAt
First day of week
protected
static int
$weekStartsAt
= \Cake\Chronos\ChronosInterface::MONDAY
Methods
__construct()
Create a new Immutable Date instance.
public
__construct([DateTimeInterface|string|int|null $time = 'now' ][, DateTimeZone|string|null $tz = null ]) : mixed
You can specify the timezone for the $time parameter. This timezone will not be used in any future modifications to the Date instance.
The $timezone parameter is ignored if $time is a DateTimeInterface instance.
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 the server local time. Normalizing the timezone allows for subtraction/addition to have deterministic results.
Parameters
- $time : DateTimeInterface|string|int|null = 'now'
-
Fixed or relative time
- $tz : DateTimeZone|string|null = null
-
The timezone in which the date is taken
__debugInfo()
Return properties for debugging.
public
__debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>__get()
Get a part of the ChronosInterface object
public
__get(string $name) : string|int|bool|DateTimeZone
Parameters
- $name : string
-
The property name to read.
Tags
Return values
string|int|bool|DateTimeZone —The property value.
__isset()
Check if an attribute exists on the object
public
__isset(string $name) : bool
Parameters
- $name : string
-
The property name to check.
Return values
bool —Whether or not the property exists.
__toString()
Format the instance as a string using the set format
public
__toString() : string
Return values
stringadd()
Add an Interval to a Date
public
add(DateInterval $interval) : static
Any changes to the time will cause an exception to be raised.
Parameters
- $interval : DateInterval
-
The interval to modify this date by.
Attributes
- #[ReturnTypeWillChange]
Return values
static —A modified Date instance
addDay()
Add a day to the instance
public
addDay([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of days to add.
Return values
staticaddDays()
Add days to the instance. Positive $value travels forward while negative $value travels into the past.
public
addDays(int $value) : static
Parameters
- $value : int
-
The number of days to add.
Return values
staticaddHour()
Add an hour to the instance
public
addHour([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of hours to add.
Return values
staticaddHours()
Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
public
addHours(int $value) : static
Parameters
- $value : int
-
The number of hours to add.
Return values
staticaddMinute()
Add a minute to the instance
public
addMinute([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of minutes to add.
Return values
staticaddMinutes()
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
public
addMinutes(int $value) : static
Parameters
- $value : int
-
The number of minutes to add.
Return values
staticaddMonth()
Add a month to the instance
public
addMonth([int $value = 1 ]) : static
Has the same behavior as addMonths()
.
Parameters
- $value : int = 1
-
The number of months to add.
Return values
staticaddMonths()
Add months to the instance. Positive $value travels forward while negative $value travels into the past.
public
addMonths(int $value) : static
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
- $value : int
-
The number of months to add.
Return values
staticaddMonthsWithOverflow()
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
public
addMonthsWithOverflow(int $value) : static
If the new date does not exist, the days overflow into the next month.
Example:
(new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01
Parameters
- $value : int
-
The number of months to add.
Return values
staticaddMonthWithOverflow()
Add a month with overflow to the instance.
public
addMonthWithOverflow([int $value = 1 ]) : static
Has the same behavior as addMonthsWithOverflow()
.
Parameters
- $value : int = 1
-
The number of months to add.
Return values
staticaddSecond()
Add a second to the instance
public
addSecond([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of seconds to add.
Return values
staticaddSeconds()
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
public
addSeconds(int $value) : static
Parameters
- $value : int
-
The number of seconds to add.
Return values
staticaddWeek()
Add a week to the instance
public
addWeek([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of weeks to add.
Return values
staticaddWeekday()
Add a weekday to the instance
public
addWeekday([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of weekdays to add.
Return values
staticaddWeekdays()
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
public
addWeekdays(int $value) : static
Parameters
- $value : int
-
The number of weekdays to add.
Return values
staticaddWeeks()
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
public
addWeeks(int $value) : static
Parameters
- $value : int
-
The number of weeks to add.
Return values
staticaddYear()
Add a year to the instance.
public
addYear([int $value = 1 ]) : static
Has the same behavior as addYears()
.
Parameters
- $value : int = 1
-
The number of years to add.
Return values
staticaddYears()
Add years to the instance. Positive $value travel forward while negative $value travel into the past.
public
addYears(int $value) : static
If the new date does not exist, the last day of the month is used instead instead of overflowing into the next month.
Example:
(new Chronos('2015-01-03'))->addYears(1); // Results in 2016-01-03
(new Chronos('2012-02-29'))->addYears(1); // Results in 2013-02-28
Parameters
- $value : int
-
The number of years to add.
Return values
staticaddYearsWithOverflow()
Add years with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
public
addYearsWithOverflow(int $value) : static
If the new date does not exist, the days overflow into the next month.
Example:
(new Chronos('2012-02-29'))->addYearsWithOverflow(1); // Results in 2013-03-01
Parameters
- $value : int
-
The number of years to add.
Return values
staticaddYearWithOverflow()
Add a year with overflow to the instance.
public
addYearWithOverflow([int $value = 1 ]) : static
Has the same behavior as addYearsWithOverflow()
.
Parameters
- $value : int = 1
-
The number of years to add.
Return values
staticaverage()
Modify the current instance to the average of a given instance (default now) and the current instance.
public
average([ChronosInterface|null $dt = null ]) : static
Parameters
- $dt : ChronosInterface|null = null
-
The instance to compare with.
Return values
staticbetween()
Determines if the instance is between two others
public
between(ChronosInterface $dt1, ChronosInterface $dt2[, bool $equal = true ]) : bool
Parameters
- $dt1 : ChronosInterface
-
The instance to compare with.
- $dt2 : ChronosInterface
-
The instance to compare with.
- $equal : bool = true
-
Indicates if a > and < comparison should be used or <= or >=
Return values
boolclosest()
Get the closest date from the instance.
public
closest(ChronosInterface $dt1, ChronosInterface $dt2) : ChronosInterface
Parameters
- $dt1 : ChronosInterface
-
The instance to compare with.
- $dt2 : ChronosInterface
-
The instance to compare with.
Return values
ChronosInterfacecreate()
Create an instance from a specific date.
public
static create([int|null $year = null ][, int|null $month = null ][, int|null $day = null ]) : static
Parameters
- $year : int|null = null
-
The year to create an instance with.
- $month : int|null = null
-
The month to create an instance with.
- $day : int|null = null
-
The day to create an instance with.
Return values
staticcreateFromArray()
Creates a ChronosInterface instance from an array of date and time values.
public
static createFromArray(array<string|int, int|string> $values) : static
The 'year', 'month' and 'day' values must all be set for a date. The time values all default to 0.
The 'timezone' value can be any format supported by \DateTimeZone
.
Allowed values:
- year
- month
- day
- hour
- minute
- second
- microsecond
- meridian ('am' or 'pm')
- timezone
Parameters
- $values : array<string|int, int|string>
-
Array of date and time values.
Return values
staticcreateFromDate()
Create a ChronosInterface instance from just a date. The time portion is set to now.
public
static createFromDate([int|null $year = null ][, int|null $month = null ][, int|null $day = null ][, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $year : int|null = null
-
The year to create an instance with.
- $month : int|null = null
-
The month to create an instance with.
- $day : int|null = null
-
The day to create an instance with.
- $tz : DateTimeZone|string|null = null
-
The DateTimeZone object or timezone name the new instance should use.
Return values
staticcreateFromFormat()
Create a ChronosInterface instance from a specific format
public
static createFromFormat(string $format, string $time[, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $format : string
-
The date() compatible format string.
- $time : string
-
The formatted date string to interpret.
- $tz : DateTimeZone|string|null = null
-
The DateTimeZone object or timezone name the new instance should use.
Tags
Attributes
- #[ReturnTypeWillChange]
Return values
staticcreateFromTime()
Create a ChronosInterface instance from just a time. The date portion is set to today.
public
static createFromTime([int|null $hour = null ][, int|null $minute = null ][, int|null $second = null ][, int|null $microsecond = null ][, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $hour : int|null = null
-
The hour to create an instance with.
- $minute : int|null = null
-
The minute to create an instance with.
- $second : int|null = null
-
The second to create an instance with.
- $microsecond : int|null = null
-
The microsecond to create an instance with.
- $tz : DateTimeZone|string|null = null
-
The DateTimeZone object or timezone name the new instance should use.
Return values
staticcreateFromTimestamp()
Create a ChronosInterface instance from a timestamp
public
static createFromTimestamp(int $timestamp[, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $timestamp : int
-
The timestamp to create an instance from.
- $tz : DateTimeZone|string|null = null
-
The DateTimeZone object or timezone name the new instance should use.
Return values
staticcreateFromTimestampUTC()
Create a ChronosInterface instance from an UTC timestamp
public
static createFromTimestampUTC(int $timestamp) : static
Parameters
- $timestamp : int
-
The UTC timestamp to create an instance from.
Return values
staticday()
Set the instance's day
public
day(int $value) : static
Parameters
- $value : int
-
The day value.
Return values
staticdiffFiltered()
Get the difference by the given interval using a filter callable
public
diffFiltered(ChronosInterval|DateInterval $ci, callable $callback[, ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $ci : ChronosInterval|DateInterval
-
An interval to traverse by
- $callback : callable
-
The callback to use for filtering.
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffForHumans()
Get the difference in a human readable format.
public
diffForHumans([ChronosInterface|null $other = null ][, bool $absolute = false ]) : string
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
- $other : ChronosInterface|null = null
-
The datetime to compare with.
- $absolute : bool = false
-
removes time difference modifiers ago, after, etc
Return values
stringdiffFormatter()
Get the difference formatter instance or overwrite the current one.
public
static diffFormatter([DifferenceFormatterInterface|null $formatter = null ]) : DifferenceFormatterInterface
Parameters
- $formatter : DifferenceFormatterInterface|null = null
-
The formatter instance when setting.
Return values
DifferenceFormatterInterface —The formatter instance.
diffInDays()
Get the difference in days
public
diffInDays([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInDaysFiltered()
Get the difference in days using a filter callable
public
diffInDaysFiltered(callable $callback[, ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $callback : callable
-
The callback to use for filtering.
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInHours()
Get the difference in hours
public
diffInHours([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInHoursFiltered()
Get the difference in hours using a filter callable
public
diffInHoursFiltered(callable $callback[, ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $callback : callable
-
The callback to use for filtering.
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInMinutes()
Get the difference in minutes
public
diffInMinutes([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInMonths()
Get the difference in months
public
diffInMonths([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInMonthsIgnoreTimezone()
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.
public
diffInMonthsIgnoreTimezone([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
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()
.
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInSeconds()
Get the difference in seconds
public
diffInSeconds([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInWeekdays()
Get the difference in weekdays
public
diffInWeekdays([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInWeekendDays()
Get the difference in weekend days using a filter
public
diffInWeekendDays([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInWeeks()
Get the difference in weeks
public
diffInWeeks([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intdiffInYears()
Get the difference in years
public
diffInYears([ChronosInterface|null $dt = null ][, bool $abs = true ]) : int
Parameters
- $dt : ChronosInterface|null = null
-
The instance to difference from.
- $abs : bool = true
-
Get the absolute of the difference
Return values
intendOfCentury()
Sets the date to end of the century and time to 23:59:59
public
endOfCentury() : static
Return values
staticendOfDay()
Sets the time to 23:59:59 or 23:59:59.999999 if `$microseconds` is true.
public
endOfDay([bool $microseconds = false ]) : static
Parameters
- $microseconds : bool = false
-
Whether to set microseconds
Return values
staticendOfDecade()
Sets the date to end of the decade and time to 23:59:59
public
endOfDecade() : static
Return values
staticendOfMonth()
Sets the date to end of the month and time to 23:59:59
public
endOfMonth() : static
Return values
staticendOfWeek()
Sets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
public
endOfWeek() : static
Return values
staticendOfYear()
Sets the date to end of the year and time to 23:59:59
public
endOfYear() : static
Return values
staticeq()
Determines if the instance is equal to another
public
eq(ChronosInterface $dt) : bool
eq() is deprecated. Use equals() instead.
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boolequals()
Determines if the instance is equal to another
public
equals(ChronosInterface $dt) : bool
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boolfarthest()
Get the farthest date from the instance.
public
farthest(ChronosInterface $dt1, ChronosInterface $dt2) : ChronosInterface
Parameters
- $dt1 : ChronosInterface
-
The instance to compare with.
- $dt2 : ChronosInterface
-
The instance to compare with.
Return values
ChronosInterfacefirstOfMonth()
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.
public
firstOfMonth([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
The day of the week to move to.
Return values
staticfirstOfQuarter()
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.
public
firstOfQuarter([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
The day of the week to move to.
Return values
staticfirstOfYear()
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.
public
firstOfYear([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
The day of the week to move to.
Return values
staticfromNow()
Convenience method for getting the remaining time from a given time.
public
static fromNow(DateTime|DateTimeImmutable $datetime) : DateInterval|bool
Parameters
- $datetime : DateTime|DateTimeImmutable
-
The date to get the remaining time from.
Return values
DateInterval|bool —The DateInterval object representing the difference between the two dates or FALSE on failure.
getLastErrors()
Returns any errors or warnings that were found during the parsing of the last object created by this class.
public
static getLastErrors() : array<string|int, mixed>
Return values
array<string|int, mixed>getTestNow()
Get the test instance stored in Chronos
public
static getTestNow() : ChronosInterface|null
Tags
Return values
ChronosInterface|null —the current instance used for testing or null.
getWeekendDays()
Get weekend days
public
static getWeekendDays() : array<string|int, mixed>
Return values
array<string|int, mixed>getWeekEndsAt()
Get the last day of week
public
static getWeekEndsAt() : int
Return values
intgetWeekStartsAt()
Get the first day of week
public
static getWeekStartsAt() : int
Return values
intgreaterThan()
Determines if the instance is greater (after) than another
public
greaterThan(ChronosInterface $dt) : bool
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boolgreaterThanOrEquals()
Determines if the instance is greater (after) than or equal to another
public
greaterThanOrEquals(ChronosInterface $dt) : bool
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boolgt()
Determines if the instance is greater (after) than another
public
gt(ChronosInterface $dt) : bool
gt() is deprecated. Use greaterThan() instead.
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boolgte()
Determines if the instance is greater (after) than or equal to another
public
gte(ChronosInterface $dt) : bool
gte() is deprecated. Use greaterThanOrEquals() instead.
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boolhasTestNow()
Get whether or not Chronos has a test instance set.
public
static hasTestNow() : bool
Tags
Return values
bool —True if there is a test instance, otherwise false
hour()
Set the instance's hour
public
hour(int $value) : static
Parameters
- $value : int
-
The hour value.
Tags
Return values
staticinstance()
Create a ChronosInterface instance from a DateTimeInterface one
public
static instance(DateTimeInterface $dt) : static
Parameters
- $dt : DateTimeInterface
-
The datetime instance to convert.
Return values
staticisBirthday()
Check if its the birthday. Compares the date/month values of the two dates.
public
isBirthday([ChronosInterface|null $dt = null ]) : bool
Parameters
- $dt : ChronosInterface|null = null
-
The instance to compare with or null to use current day.
Return values
boolisFriday()
Checks if this day is a Friday.
public
isFriday() : bool
Return values
boolisFuture()
Determines if the instance is in the future, ie. greater (after) than now
public
isFuture() : bool
Return values
boolisLastMonth()
Determines if the instance is within the last month
public
isLastMonth() : bool
Return values
boolisLastWeek()
Determines if the instance is within the last week
public
isLastWeek() : bool
Return values
boolisLastYear()
Determines if the instance is within the last year
public
isLastYear() : bool
Return values
boolisLeapYear()
Determines if the instance is a leap year
public
isLeapYear() : bool
Return values
boolisMonday()
Checks if this day is a Monday.
public
isMonday() : bool
Return values
boolisMutable()
Check if instance of ChronosInterface is mutable.
public
isMutable() : bool
Return values
boolisNextMonth()
Determines if the instance is within the next month
public
isNextMonth() : bool
Return values
boolisNextWeek()
Determines if the instance is within the next week
public
isNextWeek() : bool
Return values
boolisNextYear()
Determines if the instance is within the next year
public
isNextYear() : bool
Return values
boolisPast()
Determines if the instance is in the past, ie. less (before) than now
public
isPast() : bool
Return values
boolisSameDay()
Checks if the passed in date is the same day as the instance current day.
public
isSameDay(ChronosInterface $dt) : bool
Parameters
- $dt : ChronosInterface
-
The instance to check against.
Return values
boolisSaturday()
Checks if this day is a Saturday.
public
isSaturday() : bool
Return values
boolisSunday()
Checks if this day is a Sunday.
public
isSunday() : bool
Return values
boolisThisMonth()
Returns true if this object represents a date within the current month
public
isThisMonth() : bool
Return values
boolisThisWeek()
Returns true if this object represents a date within the current week
public
isThisWeek() : bool
Return values
boolisThisYear()
Returns true if this object represents a date within the current year
public
isThisYear() : bool
Return values
boolisThursday()
Checks if this day is a Thursday.
public
isThursday() : bool
Return values
boolisToday()
Determines if the instance is today
public
isToday() : bool
Return values
boolisTomorrow()
Determines if the instance is tomorrow
public
isTomorrow() : bool
Return values
boolisTuesday()
Checks if this day is a Tuesday.
public
isTuesday() : bool
Return values
boolisWednesday()
Checks if this day is a Wednesday.
public
isWednesday() : bool
Return values
boolisWeekday()
Determines if the instance is a weekday
public
isWeekday() : bool
Return values
boolisWeekend()
Determines if the instance is a weekend day
public
isWeekend() : bool
Return values
boolisWithinNext()
Returns true this instance will happen within the specified interval
public
isWithinNext(string|int $timeInterval) : bool
Parameters
- $timeInterval : string|int
-
the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
Return values
boolisYesterday()
Determines if the instance is yesterday
public
isYesterday() : bool
Return values
boollastOfMonth()
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.
public
lastOfMonth([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
The day of the week to move to.
Return values
staticlastOfQuarter()
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.
public
lastOfQuarter([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
The day of the week to move to.
Return values
staticlastOfYear()
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.
public
lastOfYear([int|null $dayOfWeek = null ]) : static
Parameters
- $dayOfWeek : int|null = null
-
The day of the week to move to.
Return values
staticlessThan()
Determines if the instance is less (before) than another
public
lessThan(ChronosInterface $dt) : bool
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boollessThanOrEquals()
Determines if the instance is less (before) or equal to another
public
lessThanOrEquals(ChronosInterface $dt) : bool
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boollt()
Determines if the instance is less (before) than another
public
lt(ChronosInterface $dt) : bool
lt() is deprecated. Use lessThan instead.
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boollte()
Determines if the instance is less (before) or equal to another
public
lte(ChronosInterface $dt) : bool
lte() is deprecated. Use lessThanOrEquals() instead.
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boolmax()
Get the maximum instance between a given instance (default now) and the current instance.
public
max([ChronosInterface|null $dt = null ]) : ChronosInterface
Parameters
- $dt : ChronosInterface|null = null
-
The instance to compare with.
Return values
ChronosInterfacemaxValue()
Create a ChronosInterface instance for the greatest supported date.
public
static maxValue() : ChronosInterface
Return values
ChronosInterfacemicrosecond()
Set the instance's microsecond
public
microsecond(int $value) : static
Parameters
- $value : int
-
The microsecond value.
Return values
staticmin()
Get the minimum instance between a given instance (default now) and the current instance.
public
min([ChronosInterface|null $dt = null ]) : ChronosInterface
Parameters
- $dt : ChronosInterface|null = null
-
The instance to compare with.
Return values
ChronosInterfaceminute()
Set the instance's minute
public
minute(int $value) : static
Parameters
- $value : int
-
The minute value.
Return values
staticminValue()
Create a ChronosInterface instance for the lowest supported date.
public
static minValue() : ChronosInterface
Return values
ChronosInterfacemodify()
Creates a new instance with date modified according to DateTimeImmutable::modifier().
public
modify(string $modifier) : static
Attempting to change a time component will raise an exception
Parameters
- $modifier : string
-
Date modifier
Attributes
- #[ReturnTypeWillChange]
Return values
staticmonth()
Set the instance's month
public
month(int $value) : static
Parameters
- $value : int
-
The month value.
Return values
staticne()
Determines if the instance is not equal to another
public
ne(ChronosInterface $dt) : bool
ne() is deprecated. Use notEquals() instead.
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boolnext()
Modify to the next occurrence of a given day of the week.
public
next([int|null $dayOfWeek = null ]) : static
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.
Parameters
- $dayOfWeek : int|null = null
-
The day of the week to move to.
Return values
staticnotEquals()
Determines if the instance is not equal to another
public
notEquals(ChronosInterface $dt) : bool
Parameters
- $dt : ChronosInterface
-
The instance to compare with.
Return values
boolnow()
Get a ChronosInterface instance for the current date and time
public
static now([DateTimeZone|string|null $tz = null ]) : static
Parameters
- $tz : DateTimeZone|string|null = null
-
The DateTimeZone object or timezone name.
Return values
staticnthOfMonth()
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.
public
nthOfMonth(int $nth, int $dayOfWeek) : static|false
Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
Parameters
- $nth : int
-
The offset to use.
- $dayOfWeek : int
-
The day of the week to move to.
Return values
static|falsenthOfQuarter()
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.
public
nthOfQuarter(int $nth, int $dayOfWeek) : static|false
Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
Parameters
- $nth : int
-
The offset to use.
- $dayOfWeek : int
-
The day of the week to move to.
Return values
static|falsenthOfYear()
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.
public
nthOfYear(int $nth, int $dayOfWeek) : static|false
Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
Parameters
- $nth : int
-
The offset to use.
- $dayOfWeek : int
-
The day of the week to move to.
Return values
static|falseparse()
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()
public
static parse([DateTimeInterface|string|int $time = 'now' ][, DateTimeZone|string|null $tz = null ]) : static
Parameters
- $time : DateTimeInterface|string|int = 'now'
-
The strtotime compatible string to parse
- $tz : DateTimeZone|string|null = null
-
The DateTimeZone object or timezone name.
Return values
staticprevious()
Modify to the previous occurrence of a given day of the week.
public
previous([int|null $dayOfWeek = null ]) : static
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.
Parameters
- $dayOfWeek : int|null = null
-
The day of the week to move to.
Return values
staticresetToStringFormat()
Reset the format used to the default when type juggling a ChronosInterface instance to a string
public
static resetToStringFormat() : void
second()
Set the instance's second
public
second(int $value) : static
Parameters
- $value : int
-
The seconds value.
Return values
staticsecondsSinceMidnight()
The number of seconds since midnight.
public
secondsSinceMidnight() : int
Return values
intsecondsUntilEndOfDay()
The number of seconds until 23:59:59.
public
secondsUntilEndOfDay() : int
Return values
intsetDate()
Set the date to a different date.
public
setDate(int $year, int $month, int $day) : static
Workaround for a PHP bug related to the first day of a month
Parameters
- $year : int
-
The year to set.
- $month : int
-
The month to set.
- $day : int
-
The day to set.
Attributes
- #[ReturnTypeWillChange]
Return values
staticsetDateTime()
Set the date and time all together
public
setDateTime(int $year, int $month, int $day, int $hour, int $minute[, int $second = 0 ]) : static
Parameters
- $year : int
-
The year to set.
- $month : int
-
The month to set.
- $day : int
-
The day to set.
- $hour : int
-
The hour to set.
- $minute : int
-
The minute to set.
- $second : int = 0
-
The second to set.
Return values
staticsetTestNow()
Set the test now used by Date and Time classes provided by Chronos
public
static setTestNow([ChronosInterface|string|null $testNow = null ]) : void
Parameters
- $testNow : ChronosInterface|string|null = null
-
The instance to use for all future instances.
Tags
setTime()
Modify the time on the Date.
public
setTime(int $hours, int $minutes[, int $seconds = null ][, int $microseconds = null ]) : static
This method ignores all inputs and forces all inputs to 0.
Parameters
- $hours : int
-
The hours to set (ignored)
- $minutes : int
-
The minutes to set (ignored)
- $seconds : int = null
-
The seconds to set (ignored)
- $microseconds : int = null
-
The microseconds to set (ignored)
Attributes
- #[ReturnTypeWillChange]
Return values
static —A modified Date instance.
setTimeFromTimeString()
Set the time by time string
public
setTimeFromTimeString(string $time) : static
Parameters
- $time : string
-
Time as string.
Return values
staticsetTimestamp()
public
setTimestamp(mixed $value) : mixed
Parameters
- $value : mixed
Tags
Attributes
- #[ReturnTypeWillChange]
setTimezone()
No-op method.
public
setTimezone(DateTimeZone|string $value) : $this
Timezones have no effect on calendar dates.
Parameters
- $value : DateTimeZone|string
-
The DateTimeZone object or timezone name to use.
Attributes
- #[ReturnTypeWillChange]
Return values
$thissetToStringFormat()
Set the default format used when type juggling a ChronosInterface instance to a string
public
static setToStringFormat(string $format) : void
Parameters
- $format : string
-
The format to use in future __toString() calls.
setWeekendDays()
Set weekend days
public
static setWeekendDays(array<string|int, mixed> $days) : void
Parameters
- $days : array<string|int, mixed>
-
Which days are 'weekends'.
setWeekEndsAt()
Set the last day of week
public
static setWeekEndsAt(int $day) : void
Parameters
- $day : int
-
The day the week ends with.
setWeekStartsAt()
Set the first day of week
public
static setWeekStartsAt(int $day) : void
Parameters
- $day : int
-
The day the week starts with.
startOfCentury()
Sets the date to the first day of the century and the time to 00:00:00
public
startOfCentury() : static
Return values
staticstartOfDay()
Sets the time to 00:00:00
public
startOfDay() : static
Return values
staticstartOfDecade()
Sets the date to the first day of the decade and the time to 00:00:00
public
startOfDecade() : static
Return values
staticstartOfMonth()
Sets the date to the first day of the month and the time to 00:00:00
public
startOfMonth() : static
Return values
staticstartOfWeek()
Sets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
public
startOfWeek() : static
Return values
staticstartOfYear()
Sets the date to the first day of the year and the time to 00:00:00
public
startOfYear() : static
Return values
staticsub()
Subtract an Interval from a Date.
public
sub(DateInterval $interval) : static
Any changes to the time will cause an exception to be raised.
Parameters
- $interval : DateInterval
-
The interval to modify this date by.
Attributes
- #[ReturnTypeWillChange]
Return values
static —A modified Date instance
subDay()
Remove a day from the instance
public
subDay([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of days to remove.
Return values
staticsubDays()
Remove days from the instance
public
subDays(int $value) : static
Parameters
- $value : int
-
The number of days to remove.
Return values
staticsubHour()
Remove an hour from the instance
public
subHour([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of hours to remove.
Return values
staticsubHours()
Remove hours from the instance
public
subHours(int $value) : static
Parameters
- $value : int
-
The number of hours to remove.
Return values
staticsubMinute()
Remove a minute from the instance
public
subMinute([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of minutes to remove.
Return values
staticsubMinutes()
Remove minutes from the instance
public
subMinutes(int $value) : static
Parameters
- $value : int
-
The number of minutes to remove.
Return values
staticsubMonth()
Remove a month from the instance
public
subMonth([int $value = 1 ]) : static
Has the same behavior as addMonths()
.
Parameters
- $value : int = 1
-
The number of months to remove.
Return values
staticsubMonths()
Remove months from the instance
public
subMonths(int $value) : static
Has the same behavior as addMonths()
.
Parameters
- $value : int
-
The number of months to remove.
Return values
staticsubMonthsWithOverflow()
Remove months with overflow from the instance.
public
subMonthsWithOverflow(int $value) : static
Has the same behavior as addMonthsWithOverflow()
.
Parameters
- $value : int
-
The number of months to remove.
Return values
staticsubMonthWithOverflow()
Remove a month with overflow from the instance.
public
subMonthWithOverflow([int $value = 1 ]) : static
Has the same behavior as addMonthsWithOverflow()
.
Parameters
- $value : int = 1
-
The number of months to remove.
Return values
staticsubSecond()
Remove a second from the instance
public
subSecond([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of seconds to remove.
Return values
staticsubSeconds()
Remove seconds from the instance
public
subSeconds(int $value) : static
Parameters
- $value : int
-
The number of seconds to remove.
Return values
staticsubWeek()
Remove a week from the instance
public
subWeek([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of weeks to remove.
Return values
staticsubWeekday()
Remove a weekday from the instance
public
subWeekday([int $value = 1 ]) : static
Parameters
- $value : int = 1
-
The number of weekdays to remove.
Return values
staticsubWeekdays()
Remove weekdays from the instance
public
subWeekdays(int $value) : static
Parameters
- $value : int
-
The number of weekdays to remove.
Return values
staticsubWeeks()
Remove weeks to the instance
public
subWeeks(int $value) : static
Parameters
- $value : int
-
The number of weeks to remove.
Return values
staticsubYear()
Remove a year from the instance
public
subYear([int $value = 1 ]) : static
Has the same behavior as addYears()
.
Parameters
- $value : int = 1
-
The number of years to remove.
Return values
staticsubYears()
Remove years from the instance.
public
subYears(int $value) : static
Has the same behavior as addYears()
.
Parameters
- $value : int
-
The number of years to remove.
Return values
staticsubYearsWithOverflow()
Remove years with overflow from the instance
public
subYearsWithOverflow(int $value) : static
Has the same behavior as addYeasrWithOverflow()
.
Parameters
- $value : int
-
The number of years to remove.
Return values
staticsubYearWithOverflow()
Remove a year with overflow from the instance.
public
subYearWithOverflow([int $value = 1 ]) : static
Has the same behavior as addYearsWithOverflow()
.
Parameters
- $value : int = 1
-
The number of years to remove.
Return values
statictimestamp()
Set the instance's timestamp
public
timestamp(int $value) : static
Parameters
- $value : int
-
The timestamp value to set.
Return values
statictimezone()
No-op method.
public
timezone(DateTimeZone|string $value) : $this
Timezones have no effect on calendar dates.
Parameters
- $value : DateTimeZone|string
-
The DateTimeZone object or timezone name to use.
Return values
$thistoAtomString()
Format the instance as ATOM
public
toAtomString() : string
Return values
stringtoCookieString()
Format the instance as COOKIE
public
toCookieString() : string
Return values
stringtoDateString()
Format the instance as date
public
toDateString() : string
Return values
stringtoDateTimeString()
Format the instance as date and time
public
toDateTimeString() : string
Return values
stringtoday()
Create a ChronosInterface instance for today
public
static today([DateTimeZone|string|null $tz = null ]) : static
Parameters
- $tz : DateTimeZone|string|null = null
-
The timezone to use.
Return values
statictoDayDateTimeString()
Format the instance with day, date and time
public
toDayDateTimeString() : string
Return values
stringtoFormattedDateString()
Format the instance as a readable date
public
toFormattedDateString() : string
Return values
stringtoIso8601String()
Format the instance as ISO8601
public
toIso8601String() : string
Return values
stringtomorrow()
Create a ChronosInterface instance for tomorrow
public
static tomorrow([DateTimeZone|string|null $tz = null ]) : static
Parameters
- $tz : DateTimeZone|string|null = null
-
The DateTimeZone object or timezone name the new instance should use.
Return values
statictoMutable()
Create a new mutable instance from current immutable instance.
public
toMutable() : MutableDate
Return values
MutableDatetoQuarter()
Returns the quarter
public
toQuarter([bool $range = false ]) : int|array<string|int, mixed>
Parameters
- $range : bool = false
-
Range.
Return values
int|array<string|int, mixed> —1, 2, 3, or 4 quarter of year or array if $range true
toRfc1036String()
Format the instance as RFC1036
public
toRfc1036String() : string
Tags
Return values
stringtoRfc1123String()
Format the instance as RFC1123
public
toRfc1123String() : string
Tags
Return values
stringtoRfc2822String()
Format the instance as RFC2822
public
toRfc2822String() : string
Tags
Return values
stringtoRfc3339String()
Format the instance as RFC3339
public
toRfc3339String() : string
Tags
Return values
stringtoRfc822String()
Format the instance as RFC822
public
toRfc822String() : string
Tags
Return values
stringtoRfc850String()
Format the instance as RFC850
public
toRfc850String() : string
Tags
Return values
stringtoRssString()
Format the instance as RSS
public
toRssString() : string
Return values
stringtoTimeString()
Format the instance as time
public
toTimeString() : string
Return values
stringtoUnixString()
Returns a UNIX timestamp.
public
toUnixString() : string
Return values
string —UNIX timestamp
toW3cString()
Format the instance as W3C
public
toW3cString() : string
Return values
stringtoWeek()
public
toWeek() : int
Tags
Return values
inttz()
No-op method.
public
tz(DateTimeZone|string $value) : $this
Timezones have no effect on calendar dates.
Parameters
- $value : DateTimeZone|string
-
The DateTimeZone object or timezone name to use.
Return values
$thiswasWithinLast()
Returns true this instance happened within the specified interval
public
wasWithinLast(string|int $timeInterval) : bool
Parameters
- $timeInterval : string|int
-
the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute.
Return values
boolyear()
Set the instance's year
public
year(int $value) : static
Parameters
- $value : int
-
The year value.
Return values
staticyesterday()
Create a ChronosInterface instance for yesterday
public
static yesterday([DateTimeZone|string|null $tz = null ]) : static
Parameters
- $tz : DateTimeZone|string|null = null
-
The DateTimeZone object or timezone name the new instance should use.
Return values
staticsafeCreateDateTimeZone()
Creates a DateTimeZone from a string or a DateTimeZone
protected
static safeCreateDateTimeZone(DateTimeZone|string|null $object) : DateTimeZone
Parameters
- $object : DateTimeZone|string|null
-
The value to convert.
Tags
Return values
DateTimeZonestripRelativeTime()
Remove time components from strtotime relative strings.
protected
stripRelativeTime(string $time) : string
Parameters
- $time : string
-
The input expression
Return values
string —The output expression with no time modifiers.
stripTime()
Removes the time components from an input string.
protected
stripTime(DateTime|DateTimeImmutable|string|int|null $time, DateTimeZone|null $tz) : string
Used to ensure constructed objects always lack time.
Parameters
- $time : DateTime|DateTimeImmutable|string|int|null
-
The input time. Integer values will be assumed to be in UTC. The 'now' and '' values will use the current local time.
- $tz : DateTimeZone|null
-
The timezone in which the date is taken
Return values
string —The date component of $time.
setDateParent()
Just calling to parent setDate It used in overwritten setDate
private
setDateParent(int $year, int $month, int $day) : static
Parameters
- $year : int
-
The year to set.
- $month : int
-
The month to set.
- $day : int
-
The day to set.