PHP Class Cake\Chronos\ChronosInterval

The implementation provides helpers to handle weeks but only days are saved. Weeks are calculated based on the total days of the current instance.
Inheritance: extends DateInterva\DateInterval
Show file Open project: cakephp/chronos Class Usage Examples

Protected Properties

Property Type Description
$isHHVM boolean Whether or not this object was created in HHVM

Public Methods

Method Description
__call ( string $name, array $args ) : static Allow fluent calls on the setters.
__callStatic ( string $name, array $args ) : static Provide static helpers to create instances. Allows:
__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.
__get ( string $name ) : integer Get a part of the ChronosInterval object
__set ( string $name, integer $val ) : void Set a part of the ChronosInterval object
__toString ( ) : string Returns the ISO 8601 interval string.
add ( DateInterval $interval ) : static Add the passed interval to the current instance
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.
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.
weeksAndDays ( integer $weeks, integer $days ) : static Allow setting of weeks and days to be cumulative.

Protected Methods

Method Description
wasCreatedFromDiff ( DateInterval $interval ) : boolean Determine if the interval was created via DateTime:diff() or not.

Method Details

__call() public method

.. 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.
public __call ( string $name, array $args ) : static
$name string The property name to augment. Accepts plural forms in addition to singular ones.
$args array The value to set.
return static

__callStatic() public static method

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.
public static __callStatic ( string $name, array $args ) : static
$name string The property to configure. Accepts singular and plural forms.
$args array Contains the value to use.
return static

__construct() public method

Create a new ChronosInterval instance.
public __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 )
$years integer | null The year to use.
$months integer | null The month to use.
$weeks integer | null The week to use.
$days integer | null The day to use.
$hours integer | null The hours to use.
$minutes integer | null The minutes to use.
$seconds integer | null The seconds to use.

__get() public method

Get a part of the ChronosInterval object
public __get ( string $name ) : integer
$name string The property to read.
return integer

__set() public method

Set a part of the ChronosInterval object
public __set ( string $name, integer $val ) : void
$name string The property to augment.
$val integer The value to change.
return void

__toString() public method

Returns the ISO 8601 interval string.
public __toString ( ) : string
return string Interval as string representation

add() public method

Add the passed interval to the current instance
public add ( DateInterval $interval ) : static
$interval DateInterval The interval to add.
return static

create() public static method

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().
public static 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
$years integer | null The year to use.
$months integer | null The month to use.
$weeks integer | null The week to use.
$days integer | null The day to use.
$hours integer | null The hours to use.
$minutes integer | null The minutes to use.
$seconds integer | null The seconds to use.
return static

instance() public static method

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.
public static instance ( DateInterval $di ) : static
$di DateInterval The DateInterval instance to copy.
return static

wasCreatedFromDiff() protected static method

Determine if the interval was created via DateTime:diff() or not.
protected static wasCreatedFromDiff ( DateInterval $interval ) : boolean
$interval DateInterval The interval to check.
return boolean

weeksAndDays() public method

Allow setting of weeks and days to be cumulative.
public weeksAndDays ( integer $weeks, integer $days ) : static
$weeks integer Number of weeks to set
$days integer Number of days to set
return static

Property Details

$isHHVM protected property

Whether or not this object was created in HHVM
protected bool $isHHVM
return boolean