\Cake\Chronos\TraitsFrozenTimeTrait

A trait for freezing the time aspect of a DateTime.

Used in making calendar date objects, both mutable and immutable.

Summary

Methods
Properties
Constants
setTime()
add()
sub()
timezone()
tz()
setTimezone()
setTimestamp()
modify()
No public properties found
No constants found
stripTime()
stripRelativeTime()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

setTime()

setTime(integer  $hours, integer  $minutes, integer  $seconds = null, integer  $microseconds = null) : static

Modify the time on the Date.

This method ignores all inputs and forces all inputs to 0.

Parameters

integer $hours

The hours to set (ignored)

integer $minutes

The minutes to set (ignored)

integer $seconds

The seconds to set (ignored)

integer $microseconds

The microseconds to set (ignored)

Returns

static —

A modified Date instance.

add()

add(\DateInterval  $interval) : static

Add an Interval to a Date

Any changes to the time will be ignored and reset to 00:00:00

Parameters

\DateInterval $interval

The interval to modify this date by.

Returns

static —

A modified Date instance

sub()

sub(\DateInterval  $interval) : static

Subtract an Interval from a Date.

Any changes to the time will be ignored and reset to 00:00:00

Parameters

\DateInterval $interval

The interval to modify this date by.

Returns

static —

A modified Date instance

timezone()

timezone(\DateTimeZone|string  $value) : $this

No-op method.

Timezones have no effect on calendar dates.

Parameters

\DateTimeZone|string $value

The DateTimeZone object or timezone name to use.

Returns

$this

tz()

tz(\DateTimeZone|string  $value) : $this

No-op method.

Timezones have no effect on calendar dates.

Parameters

\DateTimeZone|string $value

The DateTimeZone object or timezone name to use.

Returns

$this

setTimezone()

setTimezone(\DateTimeZone|string  $value) : $this

No-op method.

Timezones have no effect on calendar dates.

Parameters

\DateTimeZone|string $value

The DateTimeZone object or timezone name to use.

Returns

$this

setTimestamp()

setTimestamp(integer  $value) : static

Set the timestamp value and get a new object back.

This method will discard the time aspects of the timestamp and only apply the date portions

Parameters

integer $value

The timestamp value to set.

Returns

static

modify()

modify(string  $relative) : static

Overloaded to ignore time changes.

Changing any aspect of the time will be ignored, and the resulting object will have its time frozen to 00:00:00.

Parameters

string $relative

The relative change to make.

Returns

static —

A new date with the applied date changes.

stripTime()

stripTime(string|integer  $time) : string

Removes the time components from an input string.

Used to ensure constructed objects always lack time.

Parameters

string|integer $time

The input time. Integer values will be assumed to be in UTC. The 'now' and '' values will use the current local time.

Returns

string —

The date component of $time.

stripRelativeTime()

stripRelativeTime(string  $time) : string

Remove time components from strtotime relative strings.

Parameters

string $time

The input expression

Returns

string —

The output expression with no time modifiers.