Pionia Core

Units

Trait Units.

Add, subtract and set units.

Table of Contents

Methods

add()  : static
Add given units or interval to the current instance.
addRealUnit()  : static
addUnit()  : static
Add given units to the current instance.
addUTCUnit()  : static
Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.
isModifiableUnit()  : bool
Returns true if a property can be changed via setter.
rawAdd()  : static
Call native PHP DateTime/DateTimeImmutable add() method.
rawSub()  : static
Call native PHP DateTime/DateTimeImmutable sub() method.
sub()  : static
Subtract given units or interval to the current instance.
subRealUnit()  : static
subtract()  : static
Subtract given units or interval to the current instance.
subUnit()  : static
Subtract given units to the current instance.
subUTCUnit()  : static
Subtract seconds to the instance using timestamp. Positive $value travels into the past while negative $value travels forward.
rawAddUnit()  : static|null

Methods

add()

Add given units or interval to the current instance.

public add(Unit|string|DateInterval|Closure|CarbonConverterInterface $unit[, int|float $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : Unit|string|DateInterval|Closure|CarbonConverterInterface
$value : int|float = 1
$overflow : bool|null = null
Tags
example

$date->add('hour', 3)

example

$date->add(15, 'days')

example

$date->add(CarbonInterval::days(4))

Return values
static

addRealUnit()

public addRealUnit(string $unit[, int|float|null $value = 1 ]) : static
Parameters
$unit : string
$value : int|float|null = 1
Tags
deprecated

Prefer to use add addUTCUnit() which more accurately defines what it's doing.

Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.

Return values
static

addUnit()

Add given units to the current instance.

public addUnit(Unit|string $unit[, mixed $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : Unit|string
$value : mixed = 1
$overflow : bool|null = null
Return values
static

addUTCUnit()

Add seconds to the instance using timestamp. Positive $value travels forward while negative $value travels into the past.

public addUTCUnit(string $unit[, int|float|null $value = 1 ]) : static
Parameters
$unit : string
$value : int|float|null = 1
Return values
static

isModifiableUnit()

Returns true if a property can be changed via setter.

public static isModifiableUnit(string $unit) : bool
Parameters
$unit : string
Return values
bool

rawAdd()

Call native PHP DateTime/DateTimeImmutable add() method.

public rawAdd(DateInterval $interval) : static
Parameters
$interval : DateInterval
Return values
static

rawSub()

Call native PHP DateTime/DateTimeImmutable sub() method.

public rawSub(DateInterval $interval) : static
Parameters
$interval : DateInterval
Return values
static

sub()

Subtract given units or interval to the current instance.

public sub(Unit|string|DateInterval|Closure|CarbonConverterInterface $unit[, int|float $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : Unit|string|DateInterval|Closure|CarbonConverterInterface
$value : int|float = 1
$overflow : bool|null = null
Tags
example

$date->sub('hour', 3)

example

$date->sub(15, 'days')

example

$date->sub(CarbonInterval::days(4))

Return values
static

subRealUnit()

public subRealUnit(string $unit[, int $value = 1 ]) : static
Parameters
$unit : string
$value : int = 1
Tags
deprecated

Prefer to use add subUTCUnit() which more accurately defines what it's doing.

Subtract seconds to the instance using timestamp. Positive $value travels into the past while negative $value travels forward.

Return values
static

subtract()

Subtract given units or interval to the current instance.

public subtract(string|DateInterval $unit[, int|float $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : string|DateInterval
$value : int|float = 1
$overflow : bool|null = null
Tags
see
sub()
Return values
static

subUnit()

Subtract given units to the current instance.

public subUnit(Unit|string $unit[, mixed $value = 1 ][, bool|null $overflow = null ]) : static
Parameters
$unit : Unit|string
$value : mixed = 1
$overflow : bool|null = null
Return values
static

subUTCUnit()

Subtract seconds to the instance using timestamp. Positive $value travels into the past while negative $value travels forward.

public subUTCUnit(string $unit[, int $value = 1 ]) : static
Parameters
$unit : string
$value : int = 1
Return values
static

rawAddUnit()

private static rawAddUnit(self $date, string $unit, int|float $value) : static|null
Parameters
$date : self
$unit : string
$value : int|float
Return values
static|null

        
On this page

Search results