PERIOD_PREFIX
PERIOD_PREFIX = 'P'
Interval spec period designators
A simple API extension for DateInterval.
The implementation provides helpers to handle weeks but only days are saved. Weeks are calculated based on the total days of the current instance.
__construct(integer|null $years = 1, integer|null $months = null, integer|null $weeks = null, integer|null $days = null, integer|null $hours = null, integer|null $minutes = null, integer|null $seconds = null)
Create a new ChronosInterval instance.
integer|null | $years | The year to use. |
integer|null | $months | The month to use. |
integer|null | $weeks | The week to use. |
integer|null | $days | The day to use. |
integer|null | $hours | The hours to use. |
integer|null | $minutes | The minutes to use. |
integer|null | $seconds | The seconds to use. |
create(integer|null $years = 1, integer|null $months = null, integer|null $weeks = null, integer|null $days = null, integer|null $hours = null, integer|null $minutes = null, integer|null $seconds = null) : static
Create a new ChronosInterval instance from specific values.
This is an alias for the constructor that allows better fluent syntax as it allows you to do ChronosInterval::create(1)->fn() rather than (new ChronosInterval(1))->fn().
integer|null | $years | The year to use. |
integer|null | $months | The month to use. |
integer|null | $weeks | The week to use. |
integer|null | $days | The day to use. |
integer|null | $hours | The hours to use. |
integer|null | $minutes | The minutes to use. |
integer|null | $seconds | The seconds to use. |
__callStatic(string $name, array $args) : static
Provide static helpers to create instances. Allows:
ChronosInterval::years(3)
// or
ChronosInterval::month(1);
Note: This is done using the magic method to allow static and instance methods to have the same names.
string | $name | The property to configure. Accepts singular and plural forms. |
array | $args | Contains the value to use. |
instance(\DateInterval $di) : static
Create a ChronosInterval instance from a DateInterval one. Can not instance DateInterval objects created from DateTime::diff() as you can't externally set the $days field.
\DateInterval | $di | The DateInterval instance to copy. |
__call(string $name, array $args) : static
Allow fluent calls on the setters.
.. ChronosInterval::years(3)->months(5)->day().
Note: This is done using the magic method to allow static and instance methods to have the same names.
string | $name | The property name to augment. Accepts plural forms in addition to singular ones. |
array | $args | The value to set. |