code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function addMonthsWithOverflow(int $value): static { return $this->modify($value . ' months'); }
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past. If the new ChronosDate does not exist, the days overflow into the next month. ### Example: ``` (new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01 ``` @param int $value The number of months to add. @return static
addMonthsWithOverflow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subMonthsWithOverflow(int $value): static { return $this->addMonthsWithOverflow(-1 * $value); }
Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past. If the new ChronosDate does not exist, the days overflow into the next month. ### Example: ``` (new Chronos('2012-01-30'))->addMonthsWithOverflow(1); // Results in 2013-03-01 ``` @param int $value The number of months to remove. @return static
subMonthsWithOverflow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addDays(int $value): static { return $this->modify("$value days"); }
Add days to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of days to add. @return static
addDays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subDays(int $value): static { return $this->addDays(-$value); }
Remove days from the instance @param int $value The number of days to remove. @return static
subDays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addWeekdays(int $value): static { return $this->modify($value . ' weekdays, ' . $this->format('H:i:s')); }
Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of weekdays to add. @return static
addWeekdays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subWeekdays(int $value): static { return $this->addWeekdays(-$value); }
Remove weekdays from the instance @param int $value The number of weekdays to remove. @return static
subWeekdays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addWeeks(int $value): static { return $this->modify("$value week"); }
Add weeks to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of weeks to add. @return static
addWeeks
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subWeeks(int $value): static { return $this->addWeeks(-$value); }
Remove weeks to the instance @param int $value The number of weeks to remove. @return static
subWeeks
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addHours(int $value): static { return $this->modify("$value hour"); }
Add hours to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of hours to add. @return static
addHours
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subHours(int $value): static { return $this->addHours(-$value); }
Remove hours from the instance @param int $value The number of hours to remove. @return static
subHours
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addMinutes(int $value): static { return $this->modify("$value minute"); }
Add minutes to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of minutes to add. @return static
addMinutes
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subMinutes(int $value): static { return $this->addMinutes(-$value); }
Remove minutes from the instance @param int $value The number of minutes to remove. @return static
subMinutes
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function addSeconds(int $value): static { return $this->modify("$value second"); }
Add seconds to the instance. Positive $value travels forward while negative $value travels into the past. @param int $value The number of seconds to add. @return static
addSeconds
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function subSeconds(int $value): static { return $this->addSeconds(-$value); }
Remove seconds from the instance @param int $value The number of seconds to remove. @return static
subSeconds
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfDay(): static { return $this->modify('midnight'); }
Sets the time to 00:00:00 @return static
startOfDay
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function endOfDay(bool $microseconds = false): static { if ($microseconds) { return $this->modify('23:59:59.999999'); } return $this->modify('23:59:59'); }
Sets the time to 23:59:59 or 23:59:59.999999 if `$microseconds` is true. @param bool $microseconds Whether to set microseconds @return static
endOfDay
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfMonth(): static { return $this->modify('first day of this month midnight'); }
Sets the date to the first day of the month and the time to 00:00:00 @return static
startOfMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function endOfMonth(): static { return $this->modify('last day of this month, 23:59:59'); }
Sets the date to end of the month and time to 23:59:59 @return static
endOfMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfYear(): static { return $this->modify('first day of january midnight'); }
Sets the date to the first day of the year and the time to 00:00:00 @return static
startOfYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function endOfYear(): static { return $this->modify('last day of december, 23:59:59'); }
Sets the date to end of the year and time to 23:59:59 @return static
endOfYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfDecade(): static { $year = $this->year - $this->year % Chronos::YEARS_PER_DECADE; return $this->modify("first day of january $year, midnight"); }
Sets the date to the first day of the decade and the time to 00:00:00 @return static
startOfDecade
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function endOfDecade(): static { $year = $this->year - $this->year % Chronos::YEARS_PER_DECADE + Chronos::YEARS_PER_DECADE - 1; return $this->modify("last day of december $year, 23:59:59"); }
Sets the date to end of the decade and time to 23:59:59 @return static
endOfDecade
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfCentury(): static { $year = $this->startOfYear() ->year($this->year - 1 - ($this->year - 1) % Chronos::YEARS_PER_CENTURY + 1) ->year; return $this->modify("first day of january $year, midnight"); }
Sets the date to the first day of the century and the time to 00:00:00 @return static
startOfCentury
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function endOfCentury(): static { $y = $this->year - 1 - ($this->year - 1) % Chronos::YEARS_PER_CENTURY + Chronos::YEARS_PER_CENTURY; $year = $this->endOfYear() ->year($y) ->year; return $this->modify("last day of december $year, 23:59:59"); }
Sets the date to end of the century and time to 23:59:59 @return static
endOfCentury
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function startOfWeek(): static { $dateTime = $this; if ($dateTime->dayOfWeek !== static::$weekStartsAt) { $dateTime = $dateTime->previous(static::$weekStartsAt); } return $dateTime->startOfDay(); }
Sets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00 @return static
startOfWeek
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function endOfWeek(): static { $dateTime = $this; if ($dateTime->dayOfWeek !== static::$weekEndsAt) { $dateTime = $dateTime->next(static::$weekEndsAt); } return $dateTime->endOfDay(); }
Sets the date to end of week (defined in $weekEndsAt) and time to 23:59:59 @return static
endOfWeek
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function next(?int $dayOfWeek = null): static { if ($dayOfWeek === null) { $dayOfWeek = $this->dayOfWeek; } $day = static::$days[$dayOfWeek]; return $this->modify("next $day, midnight"); }
Modify to the next occurrence of a given day of the week. If no dayOfWeek is provided, modify to the next occurrence of the current day of the week. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int|null $dayOfWeek The day of the week to move to. @return static
next
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function previous(?int $dayOfWeek = null): static { if ($dayOfWeek === null) { $dayOfWeek = $this->dayOfWeek; } $day = static::$days[$dayOfWeek]; return $this->modify("last $day, midnight"); }
Modify to the previous occurrence of a given day of the week. If no dayOfWeek is provided, modify to the previous occurrence of the current day of the week. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int|null $dayOfWeek The day of the week to move to. @return static
previous
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function firstOfMonth(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; return $this->modify("first $day of this month, midnight"); }
Modify to the first occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the first day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int|null $dayOfWeek The day of the week to move to. @return static
firstOfMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function lastOfMonth(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; return $this->modify("last $day of this month, midnight"); }
Modify to the last occurrence of a given day of the week in the current month. If no dayOfWeek is provided, modify to the last day of the current month. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int|null $dayOfWeek The day of the week to move to. @return static
lastOfMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function nthOfMonth(int $nth, int $dayOfWeek): static|false { $dateTime = $this->firstOfMonth(); $check = $dateTime->format('Y-m'); $dateTime = $dateTime->modify("+$nth " . static::$days[$dayOfWeek]); return $dateTime->format('Y-m') === $check ? $dateTime : false; }
Modify to the given occurrence of a given day of the week in the current month. If the calculated occurrence is outside the scope of the current month, then return false and no modifications are made. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int $nth The offset to use. @param int $dayOfWeek The day of the week to move to. @return static|false
nthOfMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function firstOfQuarter(?int $dayOfWeek = null): static { return $this ->day(1) ->month($this->quarter * Chronos::MONTHS_PER_QUARTER - 2) ->firstOfMonth($dayOfWeek); }
Modify to the first occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the first day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int|null $dayOfWeek The day of the week to move to. @return static
firstOfQuarter
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function lastOfQuarter(?int $dayOfWeek = null): static { return $this ->day(1) ->month($this->quarter * Chronos::MONTHS_PER_QUARTER) ->lastOfMonth($dayOfWeek); }
Modify to the last occurrence of a given day of the week in the current quarter. If no dayOfWeek is provided, modify to the last day of the current quarter. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int|null $dayOfWeek The day of the week to move to. @return static
lastOfQuarter
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function nthOfQuarter(int $nth, int $dayOfWeek): static|false { $dateTime = $this->day(1)->month($this->quarter * Chronos::MONTHS_PER_QUARTER); $lastMonth = $dateTime->month; $year = $dateTime->year; $dateTime = $dateTime->firstOfQuarter()->modify("+$nth" . static::$days[$dayOfWeek]); return $lastMonth < $dateTime->month || $year !== $dateTime->year ? false : $dateTime; }
Modify to the given occurrence of a given day of the week in the current quarter. If the calculated occurrence is outside the scope of the current quarter, then return false and no modifications are made. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int $nth The offset to use. @param int $dayOfWeek The day of the week to move to. @return static|false
nthOfQuarter
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function firstOfYear(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; return $this->modify("first $day of january, midnight"); }
Modify to the first occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the first day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int|null $dayOfWeek The day of the week to move to. @return static
firstOfYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function lastOfYear(?int $dayOfWeek = null): static { $day = $dayOfWeek === null ? 'day' : static::$days[$dayOfWeek]; return $this->modify("last $day of december, midnight"); }
Modify to the last occurrence of a given day of the week in the current year. If no dayOfWeek is provided, modify to the last day of the current year. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int|null $dayOfWeek The day of the week to move to. @return static
lastOfYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function nthOfYear(int $nth, int $dayOfWeek): static|false { $dateTime = $this->firstOfYear()->modify("+$nth " . static::$days[$dayOfWeek]); return $this->year === $dateTime->year ? $dateTime : false; }
Modify to the given occurrence of a given day of the week in the current year. If the calculated occurrence is outside the scope of the current year, then return false and no modifications are made. Use the supplied consts to indicate the desired dayOfWeek, ex. Chronos::MONDAY. @param int $nth The offset to use. @param int $dayOfWeek The day of the week to move to. @return static|false
nthOfYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function equals(DateTimeInterface $other): bool { return $this == $other; }
Determines if the instance is equal to another @param \DateTimeInterface $other The instance to compare with. @return bool
equals
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function notEquals(DateTimeInterface $other): bool { return !$this->equals($other); }
Determines if the instance is not equal to another @param \DateTimeInterface $other The instance to compare with. @return bool
notEquals
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function greaterThan(DateTimeInterface $other): bool { return $this > $other; }
Determines if the instance is greater (after) than another @param \DateTimeInterface $other The instance to compare with. @return bool
greaterThan
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function greaterThanOrEquals(DateTimeInterface $other): bool { return $this >= $other; }
Determines if the instance is greater (after) than or equal to another @param \DateTimeInterface $other The instance to compare with. @return bool
greaterThanOrEquals
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function lessThan(DateTimeInterface $other): bool { return $this < $other; }
Determines if the instance is less (before) than another @param \DateTimeInterface $other The instance to compare with. @return bool
lessThan
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function lessThanOrEquals(DateTimeInterface $other): bool { return $this <= $other; }
Determines if the instance is less (before) or equal to another @param \DateTimeInterface $other The instance to compare with. @return bool
lessThanOrEquals
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function between(DateTimeInterface $start, DateTimeInterface $end, bool $equals = true): bool { if ($start > $end) { [$start, $end] = [$end, $start]; } if ($equals) { return $this->greaterThanOrEquals($start) && $this->lessThanOrEquals($end); } return $this->greaterThan($start) && $this->lessThan($end); }
Determines if the instance is between two others @param \DateTimeInterface $start Start of target range @param \DateTimeInterface $end End of target range @param bool $equals Whether to include the beginning and end of range @return bool
between
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function closest(DateTimeInterface $first, DateTimeInterface $second, DateTimeInterface ...$others): static { $winner = $first; $closestDiffInSeconds = $this->diffInSeconds($first); foreach ([$second, ...$others] as $other) { $otherDiffInSeconds = $this->diffInSeconds($other); if ($otherDiffInSeconds < $closestDiffInSeconds) { $winner = $other; $closestDiffInSeconds = $otherDiffInSeconds; } } if ($winner instanceof static) { return $winner; } return new static($winner); }
Get the closest date from the instance. @param \DateTimeInterface $first The instance to compare with. @param \DateTimeInterface $second The instance to compare with. @param \DateTimeInterface ...$others Others instances to compare with. @return static
closest
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function farthest(DateTimeInterface $first, DateTimeInterface $second, DateTimeInterface ...$others): static { $winner = $first; $farthestDiffInSeconds = $this->diffInSeconds($first); foreach ([$second, ...$others] as $other) { $otherDiffInSeconds = $this->diffInSeconds($other); if ($otherDiffInSeconds > $farthestDiffInSeconds) { $winner = $other; $farthestDiffInSeconds = $otherDiffInSeconds; } } if ($winner instanceof static) { return $winner; } return new static($winner); }
Get the farthest date from the instance. @param \DateTimeInterface $first The instance to compare with. @param \DateTimeInterface $second The instance to compare with. @param \DateTimeInterface ...$others Others instances to compare with. @return static
farthest
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function min(?DateTimeInterface $other = null): static { $other = $other ?? static::now($this->tz); $winner = $this->lessThan($other) ? $this : $other; if ($winner instanceof static) { return $winner; } return new static($winner); }
Get the minimum instance between a given instance (default now) and the current instance. @param \DateTimeInterface|null $other The instance to compare with. @return static
min
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function max(?DateTimeInterface $other = null): static { $other = $other ?? static::now($this->tz); $winner = $this->greaterThan($other) ? $this : $other; if ($winner instanceof static) { return $winner; } return new static($winner); }
Get the maximum instance between a given instance (default now) and the current instance. @param \DateTimeInterface|null $other The instance to compare with. @return static
max
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function average(?DateTimeInterface $other = null): static { $other ??= static::now($this->tz); return $this->addSeconds((int)($this->diffInSeconds($other, false) / 2)); }
Modify the current instance to the average of a given instance (default now) and the current instance. @param \DateTimeInterface|null $other The instance to compare with. @return static
average
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isWeekday(): bool { return !$this->isWeekend(); }
Determines if the instance is a weekday @return bool
isWeekday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isWeekend(): bool { return in_array($this->dayOfWeek, Chronos::getWeekendDays(), true); }
Determines if the instance is a weekend day @return bool
isWeekend
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isYesterday(): bool { return $this->toDateString() === static::yesterday($this->tz)->toDateString(); }
Determines if the instance is yesterday @return bool
isYesterday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isToday(): bool { return $this->toDateString() === static::now($this->tz)->toDateString(); }
Determines if the instance is today @return bool
isToday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isTomorrow(): bool { return $this->toDateString() === static::tomorrow($this->tz)->toDateString(); }
Determines if the instance is tomorrow @return bool
isTomorrow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isNextWeek(): bool { return $this->format('W o') === static::now($this->tz)->addWeeks(1)->format('W o'); }
Determines if the instance is within the next week @return bool
isNextWeek
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isLastWeek(): bool { return $this->format('W o') === static::now($this->tz)->subWeeks(1)->format('W o'); }
Determines if the instance is within the last week @return bool
isLastWeek
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isNextMonth(): bool { return $this->format('m Y') === static::now($this->tz)->addMonths(1)->format('m Y'); }
Determines if the instance is within the next month @return bool
isNextMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isLastMonth(): bool { return $this->format('m Y') === static::now($this->tz)->subMonths(1)->format('m Y'); }
Determines if the instance is within the last month @return bool
isLastMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isNextYear(): bool { return $this->year === static::now($this->tz)->addYears(1)->year; }
Determines if the instance is within the next year @return bool
isNextYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isLastYear(): bool { return $this->year === static::now($this->tz)->subYears(1)->year; }
Determines if the instance is within the last year @return bool
isLastYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isFirstHalf(): bool { return $this->half === 1; }
Determines if the instance is within the first half of year @return bool
isFirstHalf
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isSecondHalf(): bool { return $this->half === 2; }
Determines if the instance is within the second half of year @return bool
isSecondHalf
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isFuture(): bool { return $this->greaterThan(static::now($this->tz)); }
Determines if the instance is in the future, ie. greater (after) than now @return bool
isFuture
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isPast(): bool { return $this->lessThan(static::now($this->tz)); }
Determines if the instance is in the past, ie. less (before) than now @return bool
isPast
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isLeapYear(): bool { return $this->format('L') === '1'; }
Determines if the instance is a leap year @return bool
isLeapYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isSameDay(DateTimeInterface $other): bool { if (!$other instanceof static) { $other = new static($other); } return $this->toDateString() === $other->toDateString(); }
Checks if the passed in date is the same day as the instance current day. @param \DateTimeInterface $other The instance to check against. @return bool
isSameDay
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isSameMonth(DateTimeInterface $other): bool { return $this->format('Y-m') === $other->format('Y-m'); }
Returns whether the passed in date is the same month and year. @param \DateTimeInterface $other The instance to check against. @return bool
isSameMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isSameYear(DateTimeInterface $other): bool { return $this->format('Y') === $other->format('Y'); }
Returns whether passed in date is the same year. @param \DateTimeInterface $other The instance to check against. @return bool
isSameYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isSunday(): bool { return $this->dayOfWeek === Chronos::SUNDAY; }
Checks if this day is a Sunday. @return bool
isSunday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isMonday(): bool { return $this->dayOfWeek === Chronos::MONDAY; }
Checks if this day is a Monday. @return bool
isMonday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isTuesday(): bool { return $this->dayOfWeek === Chronos::TUESDAY; }
Checks if this day is a Tuesday. @return bool
isTuesday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isWednesday(): bool { return $this->dayOfWeek === Chronos::WEDNESDAY; }
Checks if this day is a Wednesday. @return bool
isWednesday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isThursday(): bool { return $this->dayOfWeek === Chronos::THURSDAY; }
Checks if this day is a Thursday. @return bool
isThursday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isFriday(): bool { return $this->dayOfWeek === Chronos::FRIDAY; }
Checks if this day is a Friday. @return bool
isFriday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isSaturday(): bool { return $this->dayOfWeek === Chronos::SATURDAY; }
Checks if this day is a Saturday. @return bool
isSaturday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isThisWeek(): bool { return static::now($this->getTimezone())->format('W o') === $this->format('W o'); }
Returns true if this object represents a date within the current week @return bool
isThisWeek
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isThisMonth(): bool { return static::now($this->getTimezone())->format('m Y') === $this->format('m Y'); }
Returns true if this object represents a date within the current month @return bool
isThisMonth
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isThisYear(): bool { return static::now($this->getTimezone())->format('Y') === $this->format('Y'); }
Returns true if this object represents a date within the current year @return bool
isThisYear
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isBirthday(?DateTimeInterface $other = null): bool { $other ??= static::now($this->tz); return $this->format('md') === $other->format('md'); }
Check if its the birthday. Compares the date/month values of the two dates. @param \DateTimeInterface|null $other The instance to compare with or null to use current day. @return bool
isBirthday
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function wasWithinLast(string|int $timeInterval): bool { $now = new static(); $interval = $now->modify('-' . $timeInterval); $thisTime = $this->format('U'); return $thisTime >= $interval->format('U') && $thisTime <= $now->format('U'); }
Returns true this instance happened within the specified interval @param string|int $timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute. @return bool
wasWithinLast
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function isWithinNext(string|int $timeInterval): bool { $now = new static(); $interval = $now->modify('+' . $timeInterval); $thisTime = $this->format('U'); return $thisTime <= $interval->format('U') && $thisTime >= $now->format('U'); }
Returns true this instance will happen within the specified interval @param string|int $timeInterval the numeric value with space then time type. Example of valid types: 6 hours, 2 days, 1 minute. @return bool
isWithinNext
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffFiltered( DateInterval $interval, callable $callback, ?DateTimeInterface $other = null, bool $absolute = true, int $options = 0, ): int { $start = $this; $end = $other ?? static::now($this->tz); $inverse = false; if ($end < $start) { $start = $end; $end = $this; $inverse = true; } $period = new DatePeriod($start, $interval, $end, $options); $vals = array_filter(iterator_to_array($period), function (DateTimeInterface $date) use ($callback) { return $callback(static::instance($date)); }); $diff = count($vals); return $inverse && !$absolute ? -$diff : $diff; }
Get the difference by the given interval using a filter callable @param \DateInterval $interval An interval to traverse by @param callable $callback The callback to use for filtering. @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @param int $options DatePeriod options, {@see https://www.php.net/manual/en/class.dateperiod.php} @return int
diffFiltered
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInYears(?DateTimeInterface $other = null, bool $absolute = true): int { $diff = $this->diff($other ?? static::now($this->tz), $absolute); return $diff->invert ? -$diff->y : $diff->y; }
Get the difference in years @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @return int
diffInYears
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInMonths(?DateTimeInterface $other = null, bool $absolute = true): int { $diff = $this->diff($other ?? static::now($this->tz), $absolute); $months = $diff->y * Chronos::MONTHS_PER_YEAR + $diff->m; return $diff->invert ? -$months : $months; }
Get the difference in months @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @return int
diffInMonths
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInMonthsIgnoreTimezone(?DateTimeInterface $other = null, bool $absolute = true): int { $utcTz = new DateTimeZone('UTC'); $source = new static($this->format('Y-m-d H:i:s.u'), $utcTz); $other ??= static::now($this->tz); $other = new static($other->format('Y-m-d H:i:s.u'), $utcTz); return $source->diffInMonths($other, $absolute); }
Get the difference in months ignoring the timezone. This means the months are calculated in the specified timezone without converting to UTC first. This prevents the day from changing which can change the month. For example, if comparing `2019-06-01 Asia/Tokyo` and `2019-10-01 Asia/Tokyo`, the result would be 4 months instead of 3 when using normal `DateTime::diff()`. @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @return int
diffInMonthsIgnoreTimezone
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInWeeks(?DateTimeInterface $other = null, bool $absolute = true): int { return (int)($this->diffInDays($other, $absolute) / Chronos::DAYS_PER_WEEK); }
Get the difference in weeks @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @return int
diffInWeeks
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInDays(?DateTimeInterface $other = null, bool $absolute = true): int { $diff = $this->diff($other ?? static::now($this->tz), $absolute); return $diff->invert ? -(int)$diff->days : (int)$diff->days; }
Get the difference in days @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @return int
diffInDays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInDaysFiltered( callable $callback, ?DateTimeInterface $other = null, bool $absolute = true, int $options = 0, ): int { return $this->diffFiltered(new DateInterval('P1D'), $callback, $other, $absolute, $options); }
Get the difference in days using a filter callable @param callable $callback The callback to use for filtering. @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @param int $options DatePeriod options, {@see https://www.php.net/manual/en/class.dateperiod.php} @return int
diffInDaysFiltered
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInHoursFiltered( callable $callback, ?DateTimeInterface $other = null, bool $absolute = true, int $options = 0, ): int { return $this->diffFiltered(new DateInterval('PT1H'), $callback, $other, $absolute, $options); }
Get the difference in hours using a filter callable @param callable $callback The callback to use for filtering. @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @param int $options DatePeriod options, {@see https://www.php.net/manual/en/class.dateperiod.php} @return int
diffInHoursFiltered
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInWeekdays(?DateTimeInterface $other = null, bool $absolute = true, int $options = 0): int { return $this->diffInDaysFiltered(function (Chronos $date) { return $date->isWeekday(); }, $other, $absolute, $options); }
Get the difference in weekdays @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @param int $options DatePeriod options, {@see https://www.php.net/manual/en/class.dateperiod.php} @return int
diffInWeekdays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInWeekendDays(?DateTimeInterface $other = null, bool $absolute = true, int $options = 0): int { return $this->diffInDaysFiltered(function (Chronos $date) { return $date->isWeekend(); }, $other, $absolute, $options); }
Get the difference in weekend days using a filter @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @param int $options DatePeriod options, {@see https://www.php.net/manual/en/class.dateperiod.php} @return int
diffInWeekendDays
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInHours(?DateTimeInterface $other = null, bool $absolute = true): int { return (int)( $this->diffInSeconds($other, $absolute) / Chronos::SECONDS_PER_MINUTE / Chronos::MINUTES_PER_HOUR ); }
Get the difference in hours @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @return int
diffInHours
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInMinutes(?DateTimeInterface $other = null, bool $absolute = true): int { return (int)($this->diffInSeconds($other, $absolute) / Chronos::SECONDS_PER_MINUTE); }
Get the difference in minutes @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @return int
diffInMinutes
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffInSeconds(?DateTimeInterface $other = null, bool $absolute = true): int { $other ??= static::now($this->tz); $value = $other->getTimestamp() - $this->getTimestamp(); return $absolute ? abs($value) : $value; }
Get the difference in seconds @param \DateTimeInterface|null $other The instance to difference from. @param bool $absolute Get the absolute of the difference @return int
diffInSeconds
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function secondsSinceMidnight(): int { return $this->diffInSeconds($this->startOfDay()); }
The number of seconds since midnight. @return int
secondsSinceMidnight
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function secondsUntilEndOfDay(): int { return $this->diffInSeconds($this->endOfDay()); }
The number of seconds until 23:59:59. @return int
secondsUntilEndOfDay
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public static function fromNow(DateTimeInterface $other): DateInterval|bool { $timeNow = new static(); return $timeNow->diff($other); }
Convenience method for getting the remaining time from a given time. @param \DateTimeInterface $other The date to get the remaining time from. @return \DateInterval|bool The DateInterval object representing the difference between the two dates or FALSE on failure.
fromNow
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function diffForHumans(?DateTimeInterface $other = null, bool $absolute = false): string { return static::diffFormatter()->diffForHumans($this, $other, $absolute); }
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 @param \DateTimeInterface|null $other The datetime to compare with. @param bool $absolute removes time difference modifiers ago, after, etc @return string
diffForHumans
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function toNative(): DateTimeImmutable { return new DateTimeImmutable($this->format('Y-m-d H:i:s.u'), $this->getTimezone()); }
Returns a DateTimeImmutable instance This method returns a PHP DateTimeImmutable without Chronos extensions. @return \DateTimeImmutable
toNative
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT
public function __get(string $name): string|float|int|bool|DateTimeZone { static $formats = [ 'year' => 'Y', 'yearIso' => 'o', 'month' => 'n', 'day' => 'j', 'hour' => 'G', 'minute' => 'i', 'second' => 's', 'micro' => 'u', 'microsecond' => 'u', 'dayOfWeek' => 'N', 'dayOfYear' => 'z', 'weekOfYear' => 'W', 'daysInMonth' => 't', 'timestamp' => 'U', ]; switch (true) { case isset($formats[$name]): return (int)$this->format($formats[$name]); case $name === 'dayOfWeekName': return $this->format('l'); case $name === 'weekOfMonth': return (int)ceil($this->day / Chronos::DAYS_PER_WEEK); case $name === 'age': return $this->diffInYears(); case $name === 'quarter': return (int)ceil($this->month / 3); case $name === 'half': return $this->month <= 6 ? 1 : 2; case $name === 'offset': return $this->getOffset(); case $name === 'offsetHours': return $this->getOffset() / Chronos::SECONDS_PER_MINUTE / Chronos::MINUTES_PER_HOUR; case $name === 'dst': return $this->format('I') === '1'; case $name === 'local': return $this->offset === $this->setTimezone(date_default_timezone_get())->offset; case $name === 'utc': return $this->offset === 0; case $name === 'timezone' || $name === 'tz': return $this->getTimezone(); case $name === 'timezoneName' || $name === 'tzName': return $this->getTimezone()->getName(); default: throw new InvalidArgumentException(sprintf('Unknown getter `%s`', $name)); } }
Get a part of the object @param string $name The property name to read. @return \DateTimeZone|string|float|int|bool The property value. @throws \InvalidArgumentException
__get
php
cakephp/chronos
src/Chronos.php
https://github.com/cakephp/chronos/blob/master/src/Chronos.php
MIT