PHP Trait Cake\Chronos\Traits\FactoryTrait

Show file Open project: cakephp/chronos

Protected Properties

Property Type Description
$_lastErrors array Holds the last error generated by createFromFormat

Public Methods

Method Description
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, DateTimeZon\DateTimeZone | string | null $tz = null ) : static Create a new ChronosInterface instance from a specific date and time.
createFromDate ( integer $year = null, integer $month = null, integer $day = null, DateTimeZon\DateTimeZone | string | null $tz = null ) : static Create a ChronosInterface instance from just a date. The time portion is set to now.
createFromFormat ( string $format, string $time, DateTimeZon\DateTimeZone | string | null $tz = null ) : static Create a ChronosInterface instance from a specific format
createFromTime ( integer | null $hour = null, integer | null $minute = null, integer | null $second = null, DateTimeZon\DateTimeZone | string | null $tz = null ) : static Create a ChronosInterface instance from just a time. The date portion is set to today.
createFromTimestamp ( integer $timestamp, DateTimeZon\DateTimeZone | string | null $tz = null ) : static Create a ChronosInterface instance from a timestamp
createFromTimestampUTC ( integer $timestamp ) : static Create a ChronosInterface instance from an UTC timestamp
getLastErrors ( ) : array Returns any errors or warnings that were found during the parsing of the last object created by this class.
instance ( DateTimeInterface $dt ) : static Create a ChronosInterface instance from a DateTimeInterface one
maxValue ( ) : Cake\Chronos\ChronosInterface Create a ChronosInterface instance for the greatest supported date.
minValue ( ) : Cake\Chronos\ChronosInterface Create a ChronosInterface instance for the lowest supported date.
now ( DateTimeZon\DateTimeZone | string | null $tz = null ) : static Get a ChronosInterface instance for the current date and time
parse ( string $time = 'now', DateTimeZon\DateTimeZone | string | null $tz = null ) 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()
today ( DateTimeZon\DateTimeZone | string | null $tz = null ) : static Create a ChronosInterface instance for today
tomorrow ( DateTimeZon\DateTimeZone | string | null $tz = null ) : static Create a ChronosInterface instance for tomorrow
yesterday ( DateTimeZon\DateTimeZone | string | null $tz = null ) : static Create a ChronosInterface instance for yesterday

Protected Methods

Method Description
safeCreateDateTimeZone ( DateTimeZon\DateTimeZone | string | null $object ) : DateTimeZone Creates a DateTimeZone from a string or a DateTimeZone

Method Details

create() public static method

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.
public static 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, DateTimeZon\DateTimeZone | string | null $tz = null ) : static
$year integer | null The year to create an instance with.
$month integer | null The month to create an instance with.
$day integer | null The day to create an instance with.
$hour integer | null The hour to create an instance with.
$minute integer | null The minute to create an instance with.
$second integer | null The second to create an instance with.
$tz DateTimeZon\DateTimeZone | string | null The DateTimeZone object or timezone name the new instance should use.
return static

createFromDate() public static method

Create a ChronosInterface instance from just a date. The time portion is set to now.
public static createFromDate ( integer $year = null, integer $month = null, integer $day = null, DateTimeZon\DateTimeZone | string | null $tz = null ) : static
$year integer The year to create an instance with.
$month integer The month to create an instance with.
$day integer The day to create an instance with.
$tz DateTimeZon\DateTimeZone | string | null The DateTimeZone object or timezone name the new instance should use.
return static

createFromFormat() public static method

Create a ChronosInterface instance from a specific format
public static createFromFormat ( string $format, string $time, DateTimeZon\DateTimeZone | string | null $tz = null ) : static
$format string The date() compatible format string.
$time string The formatted date string to interpret.
$tz DateTimeZon\DateTimeZone | string | null The DateTimeZone object or timezone name the new instance should use.
return static

createFromTime() public static method

Create a ChronosInterface instance from just a time. The date portion is set to today.
public static createFromTime ( integer | null $hour = null, integer | null $minute = null, integer | null $second = null, DateTimeZon\DateTimeZone | string | null $tz = null ) : static
$hour integer | null The hour to create an instance with.
$minute integer | null The minute to create an instance with.
$second integer | null The second to create an instance with.
$tz DateTimeZon\DateTimeZone | string | null The DateTimeZone object or timezone name the new instance should use.
return static

createFromTimestamp() public static method

Create a ChronosInterface instance from a timestamp
public static createFromTimestamp ( integer $timestamp, DateTimeZon\DateTimeZone | string | null $tz = null ) : static
$timestamp integer The timestamp to create an instance from.
$tz DateTimeZon\DateTimeZone | string | null The DateTimeZone object or timezone name the new instance should use.
return static

createFromTimestampUTC() public static method

Create a ChronosInterface instance from an UTC timestamp
public static createFromTimestampUTC ( integer $timestamp ) : static
$timestamp integer The UTC timestamp to create an instance from.
return static

getLastErrors() public static method

Returns any errors or warnings that were found during the parsing of the last object created by this class.
public static getLastErrors ( ) : array
return array

instance() public static method

Create a ChronosInterface instance from a DateTimeInterface one
public static instance ( DateTimeInterface $dt ) : static
$dt DateTimeInterface The datetime instance to convert.
return static

maxValue() public static method

Create a ChronosInterface instance for the greatest supported date.
public static maxValue ( ) : Cake\Chronos\ChronosInterface
return Cake\Chronos\ChronosInterface

minValue() public static method

Create a ChronosInterface instance for the lowest supported date.
public static minValue ( ) : Cake\Chronos\ChronosInterface
return Cake\Chronos\ChronosInterface

now() public static method

Get a ChronosInterface instance for the current date and time
public static now ( DateTimeZon\DateTimeZone | string | null $tz = null ) : static
$tz DateTimeZon\DateTimeZone | string | null The DateTimeZone object or timezone name.
return static

parse() public static method

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()
public static parse ( string $time = 'now', DateTimeZon\DateTimeZone | string | null $tz = null )
$time string The strtotime compatible string to parse
$tz DateTimeZon\DateTimeZone | string | null The DateTimeZone object or timezone name.

safeCreateDateTimeZone() protected static method

Creates a DateTimeZone from a string or a DateTimeZone
protected static safeCreateDateTimeZone ( DateTimeZon\DateTimeZone | string | null $object ) : DateTimeZone
$object DateTimeZon\DateTimeZone | string | null The value to convert.
return DateTimeZone

today() public static method

Create a ChronosInterface instance for today
public static today ( DateTimeZon\DateTimeZone | string | null $tz = null ) : static
$tz DateTimeZon\DateTimeZone | string | null The timezone to use.
return static

tomorrow() public static method

Create a ChronosInterface instance for tomorrow
public static tomorrow ( DateTimeZon\DateTimeZone | string | null $tz = null ) : static
$tz DateTimeZon\DateTimeZone | string | null The DateTimeZone object or timezone name the new instance should use.
return static

yesterday() public static method

Create a ChronosInterface instance for yesterday
public static yesterday ( DateTimeZon\DateTimeZone | string | null $tz = null ) : static
$tz DateTimeZon\DateTimeZone | string | null The DateTimeZone object or timezone name the new instance should use.
return static

Property Details

$_lastErrors protected static property

Holds the last error generated by createFromFormat
protected static array $_lastErrors
return array