CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C Chronos 2.x API

  • Project:
    • Chronos
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 2.x
      • 3.x
      • 2.x
      • 1.x

Namespaces

  • Cake\Chronos

Class ChronosInterval

A simple API extension for DateInterval. The implementation provides helpers to handle weeks but only days are saved. Weeks are calculated based on the total days of the current instance.

Namespace: Cake\Chronos

Constants

  • string
    PERIOD_DAYS ¶
    'D'
  • string
    PERIOD_HOURS ¶
    'H'
  • string
    PERIOD_MINUTES ¶
    'M'
  • string
    PERIOD_MONTHS ¶
    'M'
  • string
    PERIOD_PREFIX ¶
    'P'
  • string
    PERIOD_SECONDS ¶
    'S'
  • string
    PERIOD_TIME_PREFIX ¶
    'T'
  • string
    PERIOD_YEARS ¶
    'Y'

Property Summary

  • $daysExcludeWeeks public @property-read
    int

    alias of dayzExcludeWeeks

  • $dayz public @property
    int

    Total days of the current interval (weeks * 7 + days).

  • $dayzExcludeWeeks public @property-read
    int

    Total days remaining in the final week of the current instance (days % 7).

  • $hours public @property
    int

    Total hours of the current interval.

  • $microseconds public @property
    int

    Total microseconds of the current interval.

  • $minutes public @property
    int

    Total minutes of the current interval.

  • $months public @property
    int

    Total months of the current interval.

  • $seconds public @property
    int

    Total seconds of the current interval.

  • $weeks public @property
    int

    Total weeks of the current interval calculated from the days.

  • $years public @property
    int

    Total years of the current interval.

Method Summary

  • __call() public

    Allow fluent calls on the setters... ChronosInterval::years(3)->months(5)->day().

  • __callStatic() public static

    Provide static helpers to create instances. Allows:

  • __construct() public

    Create a new ChronosInterval instance.

  • __get() public

    Get a part of the ChronosInterval object

  • __set() public

    Set a part of the ChronosInterval object

  • __toString() public

    Returns the ISO 8601 interval string.

  • add() public

    Add the passed interval to the current instance

  • create() public static

    Create a new ChronosInterval instance from specific values. 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().

  • day() public @method

    Alias for days

  • days() public @method

    Create instance specifying a number of days.

  • dayz() public @method

    Alias for days

  • hour() public @method

    Alias for hours

  • hours() public @method

    Create instance specifying a number of hours.

  • instance() public 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.

  • microsecond() public @method

    Alias for microseconds

  • microseconds() public @method

    Create instance specifying a number of microseconds.

  • minute() public @method

    Alias for minutes

  • minutes() public @method

    Create instance specifying a number of minutes.

  • month() public @method

    Alias for months

  • months() public @method

    Create instance specifying a number of months.

  • second() public @method

    Alias for seconds

  • seconds() public @method

    Create instance specifying a number of seconds.

  • wasCreatedFromDiff() protected static

    Determine if the interval was created via DateTime:diff() or not.

  • week() public @method

    Alias for weeks

  • weeks() public @method

    Create instance specifying a number of weeks.

  • weeksAndDays() public

    Allow setting of weeks and days to be cumulative.

  • year() public @method

    Alias for years

  • years() public @method

    Create instance specifying a number of years.

Method Detail

__call() ¶ public

__call(string $name, array $args): $this

Allow fluent calls on the setters... 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.

Parameters
string $name

The property name to augment. Accepts plural forms in addition to singular ones.

array $args

The value to set.

Returns
$this

__callStatic() ¶ public static

__callStatic(string $name, array $args): static

Provide static helpers to create instances. Allows:

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.

Parameters
string $name

The property to configure. Accepts singular and plural forms.

array $args

Contains the value to use.

Returns
static

__construct() ¶ public

__construct(int|null $years = 1, int|null $months = null, int|null $weeks = null, int|null $days = null, int|null $hours = null, int|null $minutes = null, int|null $seconds = null, int|null $microseconds = null)

Create a new ChronosInterval instance.

Parameters
int|null $years optional

The year to use.

int|null $months optional

The month to use.

int|null $weeks optional

The week to use.

int|null $days optional

The day to use.

int|null $hours optional

The hours to use.

int|null $minutes optional

The minutes to use.

int|null $seconds optional

The seconds to use.

int|null $microseconds optional

The microseconds to use.

__get() ¶ public

__get(string $name): int

Get a part of the ChronosInterval object

Parameters
string $name

The property to read.

Returns
int
Throws
InvalidArgumentException

__set() ¶ public

__set(string $name, int $val): void

Set a part of the ChronosInterval object

Parameters
string $name

The property to augment.

int $val

The value to change.

Returns
void
Throws
InvalidArgumentException

__toString() ¶ public

__toString(): string

Returns the ISO 8601 interval string.

Returns
string

add() ¶ public

add(DateInterval $interval): $this

Add the passed interval to the current instance

Parameters
DateInterval $interval

The interval to add.

Returns
$this

create() ¶ public static

create(int|null $years = 1, int|null $months = null, int|null $weeks = null, int|null $days = null, int|null $hours = null, int|null $minutes = null, int|null $seconds = null, int|null $microseconds = null): static

Create a new ChronosInterval instance from specific values. 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().

Parameters
int|null $years optional

The year to use.

int|null $months optional

The month to use.

int|null $weeks optional

The week to use.

int|null $days optional

The day to use.

int|null $hours optional

The hours to use.

int|null $minutes optional

The minutes to use.

int|null $seconds optional

The seconds to use.

int|null $microseconds optional

The microseconds to use.

Returns
static

day() ¶ public @method

day(mixed $days = 1): Cake\Chronos\ChronosInterval

Alias for days

Parameters
$days optional
Returns
Cake\Chronos\ChronosInterval

days() ¶ public @method

days(mixed $days = 1): Cake\Chronos\ChronosInterval

Create instance specifying a number of days.

Parameters
$days optional
Returns
Cake\Chronos\ChronosInterval

dayz() ¶ public @method

dayz(mixed $days = 1): Cake\Chronos\ChronosInterval

Alias for days

Parameters
$days optional
Returns
Cake\Chronos\ChronosInterval

hour() ¶ public @method

hour(mixed $hours = 1): Cake\Chronos\ChronosInterval

Alias for hours

Parameters
$hours optional
Returns
Cake\Chronos\ChronosInterval

hours() ¶ public @method

hours(mixed $hours = 1): Cake\Chronos\ChronosInterval

Create instance specifying a number of hours.

Parameters
$hours optional
Returns
Cake\Chronos\ChronosInterval

instance() ¶ public static

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.

Parameters
DateInterval $di

The DateInterval instance to copy.

Returns
static
Throws
InvalidArgumentException

microsecond() ¶ public @method

microsecond(mixed $microseconds = 1): Cake\Chronos\ChronosInterval

Alias for microseconds

Parameters
$microseconds optional
Returns
Cake\Chronos\ChronosInterval

microseconds() ¶ public @method

microseconds(mixed $microseconds = 1): Cake\Chronos\ChronosInterval

Create instance specifying a number of microseconds.

Parameters
$microseconds optional
Returns
Cake\Chronos\ChronosInterval

minute() ¶ public @method

minute(mixed $minutes = 1): Cake\Chronos\ChronosInterval

Alias for minutes

Parameters
$minutes optional
Returns
Cake\Chronos\ChronosInterval

minutes() ¶ public @method

minutes(mixed $minutes = 1): Cake\Chronos\ChronosInterval

Create instance specifying a number of minutes.

Parameters
$minutes optional
Returns
Cake\Chronos\ChronosInterval

month() ¶ public @method

month(mixed $months = 1): Cake\Chronos\ChronosInterval

Alias for months

Parameters
$months optional
Returns
Cake\Chronos\ChronosInterval

months() ¶ public @method

months(mixed $months = 1): Cake\Chronos\ChronosInterval

Create instance specifying a number of months.

Parameters
$months optional
Returns
Cake\Chronos\ChronosInterval

second() ¶ public @method

second(mixed $seconds = 1): Cake\Chronos\ChronosInterval

Alias for seconds

Parameters
$seconds optional
Returns
Cake\Chronos\ChronosInterval

seconds() ¶ public @method

seconds(mixed $seconds = 1): Cake\Chronos\ChronosInterval

Create instance specifying a number of seconds.

Parameters
$seconds optional
Returns
Cake\Chronos\ChronosInterval

wasCreatedFromDiff() ¶ protected static

wasCreatedFromDiff(DateInterval $interval): bool

Determine if the interval was created via DateTime:diff() or not.

Parameters
DateInterval $interval

The interval to check.

Returns
bool

week() ¶ public @method

week(mixed $weeks = 1): Cake\Chronos\ChronosInterval

Alias for weeks

Parameters
$weeks optional
Returns
Cake\Chronos\ChronosInterval

weeks() ¶ public @method

weeks(mixed $weeks = 1): Cake\Chronos\ChronosInterval

Create instance specifying a number of weeks.

Parameters
$weeks optional
Returns
Cake\Chronos\ChronosInterval

weeksAndDays() ¶ public

weeksAndDays(int $weeks, int $days): $this

Allow setting of weeks and days to be cumulative.

Parameters
int $weeks

Number of weeks to set

int $days

Number of days to set

Returns
$this

year() ¶ public @method

year(mixed $years = 1): Cake\Chronos\ChronosInterval

Alias for years

Parameters
$years optional
Returns
Cake\Chronos\ChronosInterval

years() ¶ public @method

years(mixed $years = 1): Cake\Chronos\ChronosInterval

Create instance specifying a number of years.

Parameters
$years optional
Returns
Cake\Chronos\ChronosInterval

Property Detail

$daysExcludeWeeks ¶ public @property-read

alias of dayzExcludeWeeks

Type
int

$dayz ¶ public @property

Total days of the current interval (weeks * 7 + days).

Type
int

$dayzExcludeWeeks ¶ public @property-read

Total days remaining in the final week of the current instance (days % 7).

Type
int

$hours ¶ public @property

Total hours of the current interval.

Type
int

$microseconds ¶ public @property

Total microseconds of the current interval.

Type
int

$minutes ¶ public @property

Total minutes of the current interval.

Type
int

$months ¶ public @property

Total months of the current interval.

Type
int

$seconds ¶ public @property

Total seconds of the current interval.

Type
int

$weeks ¶ public @property

Total weeks of the current interval calculated from the days.

Type
int

$years ¶ public @property

Total years of the current interval.

Type
int
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs