PHP Трейт Cake\Chronos\Traits\ModifierTrait

These methods let you modify the various aspects of a DateTime with a series of fluent methods. This trait expects that the implementing class also implements a copy() method. This method can be obtained using the CopyTrait.
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$days array Names of days of the week.
$weekEndsAt integer Last day of week
$weekStartsAt integer First day of week

Открытые методы

Метод Описание
addDay ( integer $value = 1 ) : static Add a day to the instance
addDays ( integer $value ) : static Add days to the instance. Positive $value travels forward while negative $value travels into the past.
addHour ( integer $value = 1 ) : static Add an hour to the instance
addHours ( integer $value ) : static Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
addMinute ( integer $value = 1 ) : static Add a minute to the instance
addMinutes ( integer $value ) : static Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
addMonth ( integer $value = 1 ) : static Add a month to the instance
addMonthWithOverflow ( integer $value = 1 ) : static Add a month with overflow to the instance
addMonths ( integer $value ) : static Add months to the instance. Positive $value travels forward while negative $value travels into the past.
addMonthsWithOverflow ( integer $value ) : static Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
addSecond ( integer $value = 1 ) : static Add a second to the instance
addSeconds ( integer $value ) : static Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
addWeek ( integer $value = 1 ) : static Add a week to the instance
addWeekday ( integer $value = 1 ) : static Add a weekday to the instance
addWeekdays ( integer $value ) : static Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
addWeeks ( integer $value ) : static Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
addYear ( integer $value = 1 ) : static Add a year to the instance
addYears ( integer $value ) : static Add years to the instance. Positive $value travel forward while negative $value travel into the past.
average ( Cake\Chronos\ChronosInterface $dt = null ) : static Modify the current instance to the average of a given instance (default now) and the current instance.
day ( integer $value ) : static Set the instance's day
endOfCentury ( ) : static Resets the date to end of the century and time to 23:59:59
endOfDay ( ) : static Resets the time to 23:59:59
endOfDecade ( ) : static Resets the date to end of the decade and time to 23:59:59
endOfMonth ( ) : static Resets the date to end of the month and time to 23:59:59
endOfWeek ( ) : static Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
endOfYear ( ) : static Resets the date to end of the year and time to 23:59:59
firstOfMonth ( integer | null $dayOfWeek = null ) : mixed 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. ChronosInterface::MONDAY.
firstOfQuarter ( integer | null $dayOfWeek = null ) : mixed 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. ChronosInterface::MONDAY.
firstOfYear ( integer | null $dayOfWeek = null ) : mixed 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. ChronosInterface::MONDAY.
getWeekEndsAt ( ) : integer Get the last day of week
getWeekStartsAt ( ) : integer Get the first day of week
hour ( integer $value ) : static Set the instance's hour
lastOfMonth ( integer | null $dayOfWeek = null ) : mixed 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. ChronosInterface::MONDAY.
lastOfQuarter ( integer | null $dayOfWeek = null ) : mixed 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. ChronosInterface::MONDAY.
lastOfYear ( integer | null $dayOfWeek = null ) : mixed 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. ChronosInterface::MONDAY.
minute ( integer $value ) : static Set the instance's minute
month ( integer $value ) : static Set the instance's month
next ( integer | null $dayOfWeek = null ) : mixed Modify to the next occurrence of a given day of the week.
nthOfMonth ( integer $nth, integer $dayOfWeek ) : mixed 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.
nthOfQuarter ( integer $nth, integer $dayOfWeek ) : mixed 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.
nthOfYear ( integer $nth, integer $dayOfWeek ) : mixed 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.
previous ( integer | null $dayOfWeek = null ) : mixed Modify to the previous occurrence of a given day of the week.
second ( integer $value ) : static Set the instance's second
setDate ( integer $year, integer $month, integer $day ) : static Set the date to a different date.
setDateTime ( integer $year, integer $month, integer $day, integer $hour, integer $minute, integer $second ) : static Set the date and time all together
setTimeFromTimeString ( string $time ) : static Set the time by time string
setWeekEndsAt ( integer $day ) : void Set the first day of week
setWeekStartsAt ( integer $day ) : void Set the first day of week
startOfCentury ( ) : static Resets the date to the first day of the century and the time to 00:00:00
startOfDay ( ) : static Resets the time to 00:00:00
startOfDecade ( ) : static Resets the date to the first day of the decade and the time to 00:00:00
startOfMonth ( ) : static Resets the date to the first day of the month and the time to 00:00:00
startOfWeek ( ) : static Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
startOfYear ( ) : static Resets the date to the first day of the year and the time to 00:00:00
subDay ( integer $value = 1 ) : static Remove a day from the instance
subDays ( integer $value ) : static Remove days from the instance
subHour ( integer $value = 1 ) : static Remove an hour from the instance
subHours ( integer $value ) : static Remove hours from the instance
subMinute ( integer $value = 1 ) : static Remove a minute from the instance
subMinutes ( integer $value ) : static Remove minutes from the instance
subMonth ( integer $value = 1 ) : static Remove a month from the instance
subMonthWithOverflow ( integer $value = 1 ) : static Remove a month with overflow from the instance
subMonths ( integer $value ) : static Remove months from the instance
subMonthsWithOverflow ( integer $value ) : static Remove months with overflow from the instance
subSecond ( integer $value = 1 ) : static Remove a second from the instance
subSeconds ( integer $value ) : static Remove seconds from the instance
subWeek ( integer $value = 1 ) : static Remove a week from the instance
subWeekday ( integer $value = 1 ) : static Remove a weekday from the instance
subWeekdays ( integer $value ) : static Remove weekdays from the instance
subWeeks ( integer $value ) : static Remove weeks to the instance
subYear ( integer $value = 1 ) : static Remove a year from the instance
subYears ( integer $value ) : static Remove years from the instance.
timestamp ( integer $value ) : static Set the instance's timestamp
year ( integer $value ) : static Set the instance's year

Описание методов

addDay() публичный Метод

Add a day to the instance
public addDay ( integer $value = 1 ) : static
$value integer The number of days to add.
Результат static

addDays() публичный Метод

Add days to the instance. Positive $value travels forward while negative $value travels into the past.
public addDays ( integer $value ) : static
$value integer The number of days to add.
Результат static

addHour() публичный Метод

Add an hour to the instance
public addHour ( integer $value = 1 ) : static
$value integer The number of hours to add.
Результат static

addHours() публичный Метод

Add hours to the instance. Positive $value travels forward while negative $value travels into the past.
public addHours ( integer $value ) : static
$value integer The number of hours to add.
Результат static

addMinute() публичный Метод

Add a minute to the instance
public addMinute ( integer $value = 1 ) : static
$value integer The number of minutes to add.
Результат static

addMinutes() публичный Метод

Add minutes to the instance. Positive $value travels forward while negative $value travels into the past.
public addMinutes ( integer $value ) : static
$value integer The number of minutes to add.
Результат static

addMonth() публичный Метод

When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month. ### Example: (new Chronos('2015-01-03'))->addMonth(); // Results in 2015-02-03 (new Chronos('2015-01-31'))->addMonth(); // Results in 2015-02-28
public addMonth ( integer $value = 1 ) : static
$value integer The number of months to add.
Результат static

addMonthWithOverflow() публичный Метод

Add a month with overflow to the instance
public addMonthWithOverflow ( integer $value = 1 ) : static
$value integer The number of months to add.
Результат static

addMonths() публичный Метод

When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month. ### Example: (new Chronos('2015-01-03'))->addMonths(1); // Results in 2015-02-03 (new Chronos('2015-01-31'))->addMonths(1); // Results in 2015-02-28
public addMonths ( integer $value ) : static
$value integer The number of months to add.
Результат static

addMonthsWithOverflow() публичный Метод

Add months with overflowing to the instance. Positive $value travels forward while negative $value travels into the past.
public addMonthsWithOverflow ( integer $value ) : static
$value integer The number of months to add.
Результат static

addSecond() публичный Метод

Add a second to the instance
public addSecond ( integer $value = 1 ) : static
$value integer The number of seconds to add.
Результат static

addSeconds() публичный Метод

Add seconds to the instance. Positive $value travels forward while negative $value travels into the past.
public addSeconds ( integer $value ) : static
$value integer The number of seconds to add.
Результат static

addWeek() публичный Метод

Add a week to the instance
public addWeek ( integer $value = 1 ) : static
$value integer The number of weeks to add.
Результат static

addWeekday() публичный Метод

Add a weekday to the instance
public addWeekday ( integer $value = 1 ) : static
$value integer The number of weekdays to add.
Результат static

addWeekdays() публичный Метод

Add weekdays to the instance. Positive $value travels forward while negative $value travels into the past.
public addWeekdays ( integer $value ) : static
$value integer The number of weekdays to add.
Результат static

addWeeks() публичный Метод

Add weeks to the instance. Positive $value travels forward while negative $value travels into the past.
public addWeeks ( integer $value ) : static
$value integer The number of weeks to add.
Результат static

addYear() публичный Метод

Add a year to the instance
public addYear ( integer $value = 1 ) : static
$value integer The number of years to add.
Результат static

addYears() публичный Метод

Add years to the instance. Positive $value travel forward while negative $value travel into the past.
public addYears ( integer $value ) : static
$value integer The number of years to add.
Результат static

average() публичный Метод

Modify the current instance to the average of a given instance (default now) and the current instance.
public average ( Cake\Chronos\ChronosInterface $dt = null ) : static
$dt Cake\Chronos\ChronosInterface The instance to compare with.
Результат static

day() публичный Метод

Set the instance's day
public day ( integer $value ) : static
$value integer The day value.
Результат static

endOfCentury() публичный Метод

Resets the date to end of the century and time to 23:59:59
public endOfCentury ( ) : static
Результат static

endOfDay() публичный Метод

Resets the time to 23:59:59
public endOfDay ( ) : static
Результат static

endOfDecade() публичный Метод

Resets the date to end of the decade and time to 23:59:59
public endOfDecade ( ) : static
Результат static

endOfMonth() публичный Метод

Resets the date to end of the month and time to 23:59:59
public endOfMonth ( ) : static
Результат static

endOfWeek() публичный Метод

Resets the date to end of week (defined in $weekEndsAt) and time to 23:59:59
public endOfWeek ( ) : static
Результат static

endOfYear() публичный Метод

Resets the date to end of the year and time to 23:59:59
public endOfYear ( ) : static
Результат static

firstOfMonth() публичный Метод

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. ChronosInterface::MONDAY.
public firstOfMonth ( integer | null $dayOfWeek = null ) : mixed
$dayOfWeek integer | null The day of the week to move to.
Результат mixed

firstOfQuarter() публичный Метод

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. ChronosInterface::MONDAY.
public firstOfQuarter ( integer | null $dayOfWeek = null ) : mixed
$dayOfWeek integer | null The day of the week to move to.
Результат mixed

firstOfYear() публичный Метод

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. ChronosInterface::MONDAY.
public firstOfYear ( integer | null $dayOfWeek = null ) : mixed
$dayOfWeek integer | null The day of the week to move to.
Результат mixed

getWeekEndsAt() публичный статический Метод

Get the last day of week
public static getWeekEndsAt ( ) : integer
Результат integer

getWeekStartsAt() публичный статический Метод

Get the first day of week
public static getWeekStartsAt ( ) : integer
Результат integer

hour() публичный Метод

Set the instance's hour
public hour ( integer $value ) : static
$value integer The hour value.
Результат static

lastOfMonth() публичный Метод

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. ChronosInterface::MONDAY.
public lastOfMonth ( integer | null $dayOfWeek = null ) : mixed
$dayOfWeek integer | null The day of the week to move to.
Результат mixed

lastOfQuarter() публичный Метод

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. ChronosInterface::MONDAY.
public lastOfQuarter ( integer | null $dayOfWeek = null ) : mixed
$dayOfWeek integer | null The day of the week to move to.
Результат mixed

lastOfYear() публичный Метод

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. ChronosInterface::MONDAY.
public lastOfYear ( integer | null $dayOfWeek = null ) : mixed
$dayOfWeek integer | null The day of the week to move to.
Результат mixed

minute() публичный Метод

Set the instance's minute
public minute ( integer $value ) : static
$value integer The minute value.
Результат static

month() публичный Метод

Set the instance's month
public month ( integer $value ) : static
$value integer The month value.
Результат static

next() публичный Метод

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. ChronosInterface::MONDAY.
public next ( integer | null $dayOfWeek = null ) : mixed
$dayOfWeek integer | null The day of the week to move to.
Результат mixed

nthOfMonth() публичный Метод

Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
public nthOfMonth ( integer $nth, integer $dayOfWeek ) : mixed
$nth integer The offset to use.
$dayOfWeek integer The day of the week to move to.
Результат mixed

nthOfQuarter() публичный Метод

Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
public nthOfQuarter ( integer $nth, integer $dayOfWeek ) : mixed
$nth integer The offset to use.
$dayOfWeek integer The day of the week to move to.
Результат mixed

nthOfYear() публичный Метод

Use the supplied consts to indicate the desired dayOfWeek, ex. ChronosInterface::MONDAY.
public nthOfYear ( integer $nth, integer $dayOfWeek ) : mixed
$nth integer The offset to use.
$dayOfWeek integer The day of the week to move to.
Результат mixed

previous() публичный Метод

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. ChronosInterface::MONDAY.
public previous ( integer | null $dayOfWeek = null ) : mixed
$dayOfWeek integer | null The day of the week to move to.
Результат mixed

second() публичный Метод

Set the instance's second
public second ( integer $value ) : static
$value integer The seconds value.
Результат static

setDate() публичный Метод

Workaround for a PHP bug related to the first day of a month
См. также: https://bugs.php.net/bug.php?id=63863
public setDate ( integer $year, integer $month, integer $day ) : static
$year integer The year to set.
$month integer The month to set.
$day integer The day to set.
Результат static

setDateTime() публичный Метод

Set the date and time all together
public setDateTime ( integer $year, integer $month, integer $day, integer $hour, integer $minute, integer $second ) : static
$year integer The year to set.
$month integer The month to set.
$day integer The day to set.
$hour integer The hour to set.
$minute integer The minute to set.
$second integer The second to set.
Результат static

setTimeFromTimeString() публичный Метод

Set the time by time string
public setTimeFromTimeString ( string $time ) : static
$time string Time as string.
Результат static

setWeekEndsAt() публичный статический Метод

Set the first day of week
public static setWeekEndsAt ( integer $day ) : void
$day integer The day the week ends with.
Результат void

setWeekStartsAt() публичный статический Метод

Set the first day of week
public static setWeekStartsAt ( integer $day ) : void
$day integer The day the week starts with.
Результат void

startOfCentury() публичный Метод

Resets the date to the first day of the century and the time to 00:00:00
public startOfCentury ( ) : static
Результат static

startOfDay() публичный Метод

Resets the time to 00:00:00
public startOfDay ( ) : static
Результат static

startOfDecade() публичный Метод

Resets the date to the first day of the decade and the time to 00:00:00
public startOfDecade ( ) : static
Результат static

startOfMonth() публичный Метод

Resets the date to the first day of the month and the time to 00:00:00
public startOfMonth ( ) : static
Результат static

startOfWeek() публичный Метод

Resets the date to the first day of week (defined in $weekStartsAt) and the time to 00:00:00
public startOfWeek ( ) : static
Результат static

startOfYear() публичный Метод

Resets the date to the first day of the year and the time to 00:00:00
public startOfYear ( ) : static
Результат static

subDay() публичный Метод

Remove a day from the instance
public subDay ( integer $value = 1 ) : static
$value integer The number of days to remove.
Результат static

subDays() публичный Метод

Remove days from the instance
public subDays ( integer $value ) : static
$value integer The number of days to remove.
Результат static

subHour() публичный Метод

Remove an hour from the instance
public subHour ( integer $value = 1 ) : static
$value integer The number of hours to remove.
Результат static

subHours() публичный Метод

Remove hours from the instance
public subHours ( integer $value ) : static
$value integer The number of hours to remove.
Результат static

subMinute() публичный Метод

Remove a minute from the instance
public subMinute ( integer $value = 1 ) : static
$value integer The number of minutes to remove.
Результат static

subMinutes() публичный Метод

Remove minutes from the instance
public subMinutes ( integer $value ) : static
$value integer The number of minutes to remove.
Результат static

subMonth() публичный Метод

When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month. ### Example: (new Chronos('2015-03-01'))->subMonth(); // Results in 2015-02-01 (new Chronos('2015-03-31'))->subMonth(); // Results in 2015-02-28
public subMonth ( integer $value = 1 ) : static
$value integer The number of months to remove.
Результат static

subMonthWithOverflow() публичный Метод

Remove a month with overflow from the instance
public subMonthWithOverflow ( integer $value = 1 ) : static
$value integer The number of months to remove.
Результат static

subMonths() публичный Метод

When adding or subtracting months, if the resulting time is a date that does not exist, the result of this operation will always be the last day of the intended month. ### Example: (new Chronos('2015-03-01'))->subMonths(1); // Results in 2015-02-01 (new Chronos('2015-03-31'))->subMonths(1); // Results in 2015-02-28
public subMonths ( integer $value ) : static
$value integer The number of months to remove.
Результат static

subMonthsWithOverflow() публичный Метод

Remove months with overflow from the instance
public subMonthsWithOverflow ( integer $value ) : static
$value integer The number of months to remove.
Результат static

subSecond() публичный Метод

Remove a second from the instance
public subSecond ( integer $value = 1 ) : static
$value integer The number of seconds to remove.
Результат static

subSeconds() публичный Метод

Remove seconds from the instance
public subSeconds ( integer $value ) : static
$value integer The number of seconds to remove.
Результат static

subWeek() публичный Метод

Remove a week from the instance
public subWeek ( integer $value = 1 ) : static
$value integer The number of weeks to remove.
Результат static

subWeekday() публичный Метод

Remove a weekday from the instance
public subWeekday ( integer $value = 1 ) : static
$value integer The number of weekdays to remove.
Результат static

subWeekdays() публичный Метод

Remove weekdays from the instance
public subWeekdays ( integer $value ) : static
$value integer The number of weekdays to remove.
Результат static

subWeeks() публичный Метод

Remove weeks to the instance
public subWeeks ( integer $value ) : static
$value integer The number of weeks to remove.
Результат static

subYear() публичный Метод

Remove a year from the instance
public subYear ( integer $value = 1 ) : static
$value integer The number of years to remove.
Результат static

subYears() публичный Метод

Remove years from the instance.
public subYears ( integer $value ) : static
$value integer The number of years to remove.
Результат static

timestamp() публичный Метод

Set the instance's timestamp
public timestamp ( integer $value ) : static
$value integer The timestamp value to set.
Результат static

year() публичный Метод

Set the instance's year
public year ( integer $value ) : static
$value integer The year value.
Результат static

Описание свойств

$days защищенное статическое свойство

Names of days of the week.
protected static array $days
Результат array

$weekEndsAt защищенное статическое свойство

Last day of week
protected static int $weekEndsAt
Результат integer

$weekStartsAt защищенное статическое свойство

First day of week
protected static int $weekStartsAt
Результат integer