Constants

PERIOD_PREFIX

PERIOD_PREFIX = 'P'

Interval spec period designators

PERIOD_YEARS

PERIOD_YEARS = 'Y'

PERIOD_MONTHS

PERIOD_MONTHS = 'M'

PERIOD_DAYS

PERIOD_DAYS = 'D'

PERIOD_TIME_PREFIX

PERIOD_TIME_PREFIX = 'T'

PERIOD_HOURS

PERIOD_HOURS = 'H'

PERIOD_MINUTES

PERIOD_MINUTES = 'M'

PERIOD_SECONDS

PERIOD_SECONDS = 'S'

PHP_DAYS_FALSE

PHP_DAYS_FALSE = -99999

Before PHP 5.4.20/5.5.4 instead of `false` days will be set to -99999 when the interval instance was created by DateTime:diff().

Properties

$years

$years : integer

Total years of the current interval.

Type

integer

$months

$months : integer

Total months of the current interval.

Type

integer

$weeks

$weeks : integer

Total weeks of the current interval calculated from the days.

Type

integer

$dayz

$dayz : integer

Total days of the current interval (weeks * 7 + days).

Type

integer

$hours

$hours : integer

Total hours of the current interval.

Type

integer

$minutes

$minutes : integer

Total minutes of the current interval.

Type

integer

$seconds

$seconds : integer

Total seconds of the current interval.

Type

integer

$dayzExcludeWeeks

$dayzExcludeWeeks : integer

Total days remaining in the final week of the current instance (days % 7).

Type

integer

$daysExcludeWeeks

$daysExcludeWeeks : integer

alias of dayzExcludeWeeks

Type

integer

$isHHVM

$isHHVM : boolean

Whether or not this object was created in HHVM

Type

boolean

Methods

__construct()

__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.

Parameters

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()

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().

Parameters

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.

Returns

static

__callStatic()

__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.

Parameters

string $name

The property to configure. Accepts singular and plural forms.

array $args

Contains the value to use.

Returns

static

instance()

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.

Parameters

\DateInterval $di

The DateInterval instance to copy.

Throws

\InvalidArgumentException

Returns

static

__get()

__get(string  $name) : integer

Get a part of the ChronosInterval object

Parameters

string $name

The property to read.

Throws

\InvalidArgumentException

Returns

integer

__set()

__set(string  $name, integer  $val) : void

Set a part of the ChronosInterval object

Parameters

string $name

The property to augment.

integer $val

The value to change.

Throws

\InvalidArgumentException

weeksAndDays()

weeksAndDays(integer  $weeks, integer  $days) : static

Allow setting of weeks and days to be cumulative.

Parameters

integer $weeks

Number of weeks to set

integer $days

Number of days to set

Returns

static

__call()

__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.

Parameters

string $name

The property name to augment. Accepts plural forms in addition to singular ones.

array $args

The value to set.

Returns

static

add()

add(\DateInterval  $interval) : static

Add the passed interval to the current instance

Parameters

\DateInterval $interval

The interval to add.

Returns

static

__toString()

__toString() : string

Returns the ISO 8601 interval string.

Returns

string —

Interval as string representation

years()

years(mixed  $years = 1) : \Cake\Chronos\ChronosInterval

Create instance specifying a number of years.

Parameters

mixed $years

Returns

\Cake\Chronos\ChronosInterval

year()

year(mixed  $years = 1) : \Cake\Chronos\ChronosInterval

Alias for years

Parameters

mixed $years

Returns

\Cake\Chronos\ChronosInterval

months()

months(mixed  $months = 1) : \Cake\Chronos\ChronosInterval

Create instance specifying a number of months.

Parameters

mixed $months

Returns

\Cake\Chronos\ChronosInterval

month()

month(mixed  $months = 1) : \Cake\Chronos\ChronosInterval

Alias for months

Parameters

mixed $months

Returns

\Cake\Chronos\ChronosInterval

weeks()

weeks(mixed  $weeks = 1) : \Cake\Chronos\ChronosInterval

Create instance specifying a number of weeks.

Parameters

mixed $weeks

Returns

\Cake\Chronos\ChronosInterval

week()

week(mixed  $weeks = 1) : \Cake\Chronos\ChronosInterval

Alias for weeks

Parameters

mixed $weeks

Returns

\Cake\Chronos\ChronosInterval

days()

days(mixed  $days = 1) : \Cake\Chronos\ChronosInterval

Create instance specifying a number of days.

Parameters

mixed $days

Returns

\Cake\Chronos\ChronosInterval

dayz()

dayz(mixed  $days = 1) : \Cake\Chronos\ChronosInterval

Alias for days

Parameters

mixed $days

Returns

\Cake\Chronos\ChronosInterval

day()

day(mixed  $days = 1) : \Cake\Chronos\ChronosInterval

Alias for days

Parameters

mixed $days

Returns

\Cake\Chronos\ChronosInterval

hours()

hours(mixed  $hours = 1) : \Cake\Chronos\ChronosInterval

Create instance specifying a number of hours.

Parameters

mixed $hours

Returns

\Cake\Chronos\ChronosInterval

hour()

hour(mixed  $hours = 1) : \Cake\Chronos\ChronosInterval

Alias for hours

Parameters

mixed $hours

Returns

\Cake\Chronos\ChronosInterval

minutes()

minutes(mixed  $minutes = 1) : \Cake\Chronos\ChronosInterval

Create instance specifying a number of minutes.

Parameters

mixed $minutes

Returns

\Cake\Chronos\ChronosInterval

minute()

minute(mixed  $minutes = 1) : \Cake\Chronos\ChronosInterval

Alias for minutes

Parameters

mixed $minutes

Returns

\Cake\Chronos\ChronosInterval

seconds()

seconds(mixed  $seconds = 1) : \Cake\Chronos\ChronosInterval

Create instance specifying a number of seconds.

Parameters

mixed $seconds

Returns

\Cake\Chronos\ChronosInterval

second()

second(mixed  $seconds = 1) : \Cake\Chronos\ChronosInterval

Alias for seconds

Parameters

mixed $seconds

Returns

\Cake\Chronos\ChronosInterval

years()

years(mixed  $years = 1) : \Cake\Chronos\ChronosInterval

Set the years portion of the current interval.

Parameters

mixed $years

Returns

\Cake\Chronos\ChronosInterval

year()

year(mixed  $years = 1) : \Cake\Chronos\ChronosInterval

Alias for years.

Parameters

mixed $years

Returns

\Cake\Chronos\ChronosInterval

months()

months(mixed  $months = 1) : \Cake\Chronos\ChronosInterval

Set the months portion of the current interval.

Parameters

mixed $months

Returns

\Cake\Chronos\ChronosInterval

month()

month(mixed  $months = 1) : \Cake\Chronos\ChronosInterval

Alias for months.

Parameters

mixed $months

Returns

\Cake\Chronos\ChronosInterval

weeks()

weeks(mixed  $weeks = 1) : \Cake\Chronos\ChronosInterval

Set the weeks portion of the current interval. Will overwrite dayz value.

Parameters

mixed $weeks

Returns

\Cake\Chronos\ChronosInterval

week()

week(mixed  $weeks = 1) : \Cake\Chronos\ChronosInterval

Alias for weeks.

Parameters

mixed $weeks

Returns

\Cake\Chronos\ChronosInterval

days()

days(mixed  $days = 1) : \Cake\Chronos\ChronosInterval

Set the days portion of the current interval.

Parameters

mixed $days

Returns

\Cake\Chronos\ChronosInterval

dayz()

dayz(mixed  $days = 1) : \Cake\Chronos\ChronosInterval

Alias for days.

Parameters

mixed $days

Returns

\Cake\Chronos\ChronosInterval

day()

day(mixed  $days = 1) : \Cake\Chronos\ChronosInterval

Alias for days.

Parameters

mixed $days

Returns

\Cake\Chronos\ChronosInterval

hours()

hours(mixed  $hours = 1) : \Cake\Chronos\ChronosInterval

Set the hours portion of the current interval.

Parameters

mixed $hours

Returns

\Cake\Chronos\ChronosInterval

hour()

hour(mixed  $hours = 1) : \Cake\Chronos\ChronosInterval

Alias for hours.

Parameters

mixed $hours

Returns

\Cake\Chronos\ChronosInterval

minutes()

minutes(mixed  $minutes = 1) : \Cake\Chronos\ChronosInterval

Set the minutes portion of the current interval.

Parameters

mixed $minutes

Returns

\Cake\Chronos\ChronosInterval

minute()

minute(mixed  $minutes = 1) : \Cake\Chronos\ChronosInterval

Alias for minutes.

Parameters

mixed $minutes

Returns

\Cake\Chronos\ChronosInterval

seconds()

seconds(mixed  $seconds = 1) : \Cake\Chronos\ChronosInterval

Set the seconds portion of the current interval.

Parameters

mixed $seconds

Returns

\Cake\Chronos\ChronosInterval

second()

second(mixed  $seconds = 1) : \Cake\Chronos\ChronosInterval

Alias for seconds.

Parameters

mixed $seconds

Returns

\Cake\Chronos\ChronosInterval

wasCreatedFromDiff()

wasCreatedFromDiff(\DateInterval  $interval) : boolean

Determine if the interval was created via DateTime:diff() or not.

Parameters

\DateInterval $interval

The interval to check.

Returns

boolean