\Cake\Chronos\TraitsFactoryTrait

Provides a number of datetime related factory methods.

Summary

Methods
Properties
Constants
instance()
parse()
now()
today()
tomorrow()
yesterday()
maxValue()
minValue()
create()
createFromDate()
createFromTime()
createFromFormat()
createFromTimestamp()
createFromTimestampUTC()
getLastErrors()
No public properties found
No constants found
safeCreateDateTimeZone()
$_lastErrors
N/A
No private methods found
No private properties found
N/A

Properties

$_lastErrors

$_lastErrors : array

Holds the last error generated by createFromFormat

Type

array

Methods

instance()

instance(\DateTimeInterface  $dt) : static

Create a ChronosInterface instance from a DateTimeInterface one

Parameters

\DateTimeInterface $dt

The datetime instance to convert.

Returns

static

parse()

parse(string  $time = 'now', \DateTimeZone|string|null  $tz = null) : static

Create a ChronosInterface instance from a string. This is an alias for the constructor that allows better fluent syntax as it allows you to do ChronosInterface::parse('Monday next week')->fn() rather than (new Chronos('Monday next week'))->fn()

Parameters

string $time

The strtotime compatible string to parse

\DateTimeZone|string|null $tz

The DateTimeZone object or timezone name.

Returns

static

now()

now(\DateTimeZone|string|null  $tz = null) : static

Get a ChronosInterface instance for the current date and time

Parameters

\DateTimeZone|string|null $tz

The DateTimeZone object or timezone name.

Returns

static

today()

today(\DateTimeZone|string|null  $tz = null) : static

Create a ChronosInterface instance for today

Parameters

\DateTimeZone|string|null $tz

The timezone to use.

Returns

static

tomorrow()

tomorrow(\DateTimeZone|string|null  $tz = null) : static

Create a ChronosInterface instance for tomorrow

Parameters

\DateTimeZone|string|null $tz

The DateTimeZone object or timezone name the new instance should use.

Returns

static

yesterday()

yesterday(\DateTimeZone|string|null  $tz = null) : static

Create a ChronosInterface instance for yesterday

Parameters

\DateTimeZone|string|null $tz

The DateTimeZone object or timezone name the new instance should use.

Returns

static

maxValue()

maxValue() : \Cake\Chronos\ChronosInterface

Create a ChronosInterface instance for the greatest supported date.

Returns

\Cake\Chronos\ChronosInterface

minValue()

minValue() : \Cake\Chronos\ChronosInterface

Create a ChronosInterface instance for the lowest supported date.

Returns

\Cake\Chronos\ChronosInterface

create()

create(integer|null  $year = null, integer|null  $month = null, integer|null  $day = null, integer|null  $hour = null, integer|null  $minute = null, integer|null  $second = null, \DateTimeZone|string|null  $tz = null) : static

Create a new ChronosInterface instance from a specific date and time.

If any of $year, $month or $day are set to null their now() values will be used.

If $hour is null it will be set to its now() value and the default values for $minute and $second will be their now() values. If $hour is not null then the default values for $minute and $second will be 0.

Parameters

integer|null $year

The year to create an instance with.

integer|null $month

The month to create an instance with.

integer|null $day

The day to create an instance with.

integer|null $hour

The hour to create an instance with.

integer|null $minute

The minute to create an instance with.

integer|null $second

The second to create an instance with.

\DateTimeZone|string|null $tz

The DateTimeZone object or timezone name the new instance should use.

Returns

static

createFromDate()

createFromDate(integer  $year = null, integer  $month = null, integer  $day = null, \DateTimeZone|string|null  $tz = null) : static

Create a ChronosInterface instance from just a date. The time portion is set to now.

Parameters

integer $year

The year to create an instance with.

integer $month

The month to create an instance with.

integer $day

The day to create an instance with.

\DateTimeZone|string|null $tz

The DateTimeZone object or timezone name the new instance should use.

Returns

static

createFromTime()

createFromTime(integer|null  $hour = null, integer|null  $minute = null, integer|null  $second = null, \DateTimeZone|string|null  $tz = null) : static

Create a ChronosInterface instance from just a time. The date portion is set to today.

Parameters

integer|null $hour

The hour to create an instance with.

integer|null $minute

The minute to create an instance with.

integer|null $second

The second to create an instance with.

\DateTimeZone|string|null $tz

The DateTimeZone object or timezone name the new instance should use.

Returns

static

createFromFormat()

createFromFormat(string  $format, string  $time, \DateTimeZone|string|null  $tz = null) : static

Create a ChronosInterface instance from a specific format

Parameters

string $format

The date() compatible format string.

string $time

The formatted date string to interpret.

\DateTimeZone|string|null $tz

The DateTimeZone object or timezone name the new instance should use.

Throws

\InvalidArgumentException

Returns

static

createFromTimestamp()

createFromTimestamp(integer  $timestamp, \DateTimeZone|string|null  $tz = null) : static

Create a ChronosInterface instance from a timestamp

Parameters

integer $timestamp

The timestamp to create an instance from.

\DateTimeZone|string|null $tz

The DateTimeZone object or timezone name the new instance should use.

Returns

static

createFromTimestampUTC()

createFromTimestampUTC(integer  $timestamp) : static

Create a ChronosInterface instance from an UTC timestamp

Parameters

integer $timestamp

The UTC timestamp to create an instance from.

Returns

static

getLastErrors()

getLastErrors() : array

Returns any errors or warnings that were found during the parsing of the last object created by this class.

Returns

array

safeCreateDateTimeZone()

safeCreateDateTimeZone(\DateTimeZone|string|null  $object) : \DateTimeZone

Creates a DateTimeZone from a string or a DateTimeZone

Parameters

\DateTimeZone|string|null $object

The value to convert.

Throws

\InvalidArgumentException

Returns

\DateTimeZone