\Cake\Chronos\TraitsDifferenceTrait

Provides methods for getting differences between datetime objects.

Expects that the implementing class implements:

  • static::now()
  • static::instance()
  • copy()

Summary

Methods
Properties
Constants
diffInYears()
diffInMonths()
diffInWeeks()
diffInDays()
diffInDaysFiltered()
diffInHoursFiltered()
diffFiltered()
diffInWeekdays()
diffInWeekendDays()
diffInHours()
diffInMinutes()
diffInSeconds()
secondsSinceMidnight()
secondsUntilEndOfDay()
fromNow()
diffForHumans()
diffFormatter()
No public properties found
No constants found
No protected methods found
$diffFormatter
N/A
No private methods found
No private properties found
N/A

Properties

Methods

diffInYears()

diffInYears(\Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in years

Parameters

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInMonths()

diffInMonths(\Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in months

Parameters

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInWeeks()

diffInWeeks(\Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in weeks

Parameters

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInDays()

diffInDays(\Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in days

Parameters

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInDaysFiltered()

diffInDaysFiltered(callable  $callback, \Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in days using a filter callable

Parameters

callable $callback

The callback to use for filtering.

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInHoursFiltered()

diffInHoursFiltered(callable  $callback, \Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in hours using a filter callable

Parameters

callable $callback

The callback to use for filtering.

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffFiltered()

diffFiltered(\Cake\Chronos\ChronosInterval  $ci, callable  $callback, \Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference by the given interval using a filter callable

Parameters

\Cake\Chronos\ChronosInterval $ci

An interval to traverse by

callable $callback

The callback to use for filtering.

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInWeekdays()

diffInWeekdays(\Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in weekdays

Parameters

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInWeekendDays()

diffInWeekendDays(\Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in weekend days using a filter

Parameters

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInHours()

diffInHours(\Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in hours

Parameters

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInMinutes()

diffInMinutes(\Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in minutes

Parameters

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

diffInSeconds()

diffInSeconds(\Cake\Chronos\ChronosInterface|null  $dt = null, boolean  $abs = true) : integer

Get the difference in seconds

Parameters

\Cake\Chronos\ChronosInterface|null $dt

The instance to difference from.

boolean $abs

Get the absolute of the difference

Returns

integer

secondsSinceMidnight()

secondsSinceMidnight() : integer

The number of seconds since midnight.

Returns

integer

secondsUntilEndOfDay()

secondsUntilEndOfDay() : integer

The number of seconds until 23:59:59.

Returns

integer

fromNow()

fromNow(\DateTime|\DateTimeImmutable  $datetime) : \DateInterval|boolean

Convenience method for getting the remaining time from a given time.

Parameters

\DateTime|\DateTimeImmutable $datetime

The date to get the remaining time from.

Returns

\DateInterval|boolean —

The DateInterval object representing the difference between the two dates or FALSE on failure.

diffForHumans()

diffForHumans(\Cake\Chronos\ChronosInterface|null  $other = null, boolean  $absolute = false) : string

Get the difference in a human readable format.

When comparing a value in the past to default now: 1 hour ago 5 months ago

When comparing a value in the future to default now: 1 hour from now 5 months from now

When comparing a value in the past to another value: 1 hour before 5 months before

When comparing a value in the future to another value: 1 hour after 5 months after

Parameters

\Cake\Chronos\ChronosInterface|null $other

The datetime to compare with.

boolean $absolute

removes time difference modifiers ago, after, etc

Returns

string

diffFormatter()

diffFormatter(\Cake\Chronos\DifferenceFormatter|null  $formatter = null) : \Cake\Chronos\DifferenceFormatter

Get the difference formatter instance or overwrite the current one.

Parameters

\Cake\Chronos\DifferenceFormatter|null $formatter

The formatter instance when setting.

Returns

\Cake\Chronos\DifferenceFormatter

The formatter instance.