Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/**
4
 * This file is part of the Carbon package.
5
 *
6
 * (c) Brian Nesbitt <brian@nesbot.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Carbon\Traits;
13
 
14
use BadMethodCallException;
15
use Carbon\Carbon;
16
use Carbon\CarbonInterface;
17
use Carbon\CarbonPeriod;
18
use Carbon\CarbonTimeZone;
19
use Carbon\Exceptions\BadComparisonUnitException;
20
use Carbon\Exceptions\ImmutableException;
21
use Carbon\Exceptions\InvalidTimeZoneException;
22
use Carbon\Exceptions\InvalidTypeException;
23
use Carbon\Exceptions\UnknownGetterException;
24
use Carbon\Exceptions\UnknownMethodException;
25
use Carbon\Exceptions\UnknownSetterException;
26
use Carbon\Exceptions\UnknownUnitException;
27
use Closure;
28
use DateInterval;
29
use DatePeriod;
30
use DateTime;
31
use DateTimeImmutable;
32
use DateTimeInterface;
33
use DateTimeZone;
34
use InvalidArgumentException;
35
use ReflectionException;
36
use ReturnTypeWillChange;
37
use Throwable;
38
 
39
/**
40
 * A simple API extension for DateTime.
41
 *
42
 * @mixin DeprecatedProperties
43
 *
44
 * <autodoc generated by `composer phpdoc`>
45
 *
46
 * @property      int              $year
47
 * @property      int              $yearIso
48
 * @property      int              $month
49
 * @property      int              $day
50
 * @property      int              $hour
51
 * @property      int              $minute
52
 * @property      int              $second
53
 * @property      int              $micro
54
 * @property      int              $microsecond
55
 * @property      int|float|string $timestamp                                                                         seconds since the Unix Epoch
56
 * @property      string           $englishDayOfWeek                                                                  the day of week in English
57
 * @property      string           $shortEnglishDayOfWeek                                                             the abbreviated day of week in English
58
 * @property      string           $englishMonth                                                                      the month in English
59
 * @property      string           $shortEnglishMonth                                                                 the abbreviated month in English
60
 * @property      int              $milliseconds
61
 * @property      int              $millisecond
62
 * @property      int              $milli
63
 * @property      int              $week                                                                              1 through 53
64
 * @property      int              $isoWeek                                                                           1 through 53
65
 * @property      int              $weekYear                                                                          year according to week format
66
 * @property      int              $isoWeekYear                                                                       year according to ISO week format
67
 * @property      int              $dayOfYear                                                                         1 through 366
68
 * @property      int              $age                                                                               does a diffInYears() with default parameters
69
 * @property      int              $offset                                                                            the timezone offset in seconds from UTC
70
 * @property      int              $offsetMinutes                                                                     the timezone offset in minutes from UTC
71
 * @property      int              $offsetHours                                                                       the timezone offset in hours from UTC
72
 * @property      CarbonTimeZone   $timezone                                                                          the current timezone
73
 * @property      CarbonTimeZone   $tz                                                                                alias of $timezone
74
 * @property-read int              $dayOfWeek                                                                         0 (for Sunday) through 6 (for Saturday)
75
 * @property-read int              $dayOfWeekIso                                                                      1 (for Monday) through 7 (for Sunday)
76
 * @property-read int              $weekOfYear                                                                        ISO-8601 week number of year, weeks starting on Monday
77
 * @property-read int              $daysInMonth                                                                       number of days in the given month
78
 * @property-read string           $latinMeridiem                                                                     "am"/"pm" (Ante meridiem or Post meridiem latin lowercase mark)
79
 * @property-read string           $latinUpperMeridiem                                                                "AM"/"PM" (Ante meridiem or Post meridiem latin uppercase mark)
80
 * @property-read string           $timezoneAbbreviatedName                                                           the current timezone abbreviated name
81
 * @property-read string           $tzAbbrName                                                                        alias of $timezoneAbbreviatedName
82
 * @property-read string           $dayName                                                                           long name of weekday translated according to Carbon locale, in english if no translation available for current language
83
 * @property-read string           $shortDayName                                                                      short name of weekday translated according to Carbon locale, in english if no translation available for current language
84
 * @property-read string           $minDayName                                                                        very short name of weekday translated according to Carbon locale, in english if no translation available for current language
85
 * @property-read string           $monthName                                                                         long name of month translated according to Carbon locale, in english if no translation available for current language
86
 * @property-read string           $shortMonthName                                                                    short name of month translated according to Carbon locale, in english if no translation available for current language
87
 * @property-read string           $meridiem                                                                          lowercase meridiem mark translated according to Carbon locale, in latin if no translation available for current language
88
 * @property-read string           $upperMeridiem                                                                     uppercase meridiem mark translated according to Carbon locale, in latin if no translation available for current language
89
 * @property-read int              $noZeroHour                                                                        current hour from 1 to 24
90
 * @property-read int              $weeksInYear                                                                       51 through 53
91
 * @property-read int              $isoWeeksInYear                                                                    51 through 53
92
 * @property-read int              $weekOfMonth                                                                       1 through 5
93
 * @property-read int              $weekNumberInMonth                                                                 1 through 5
94
 * @property-read int              $firstWeekDay                                                                      0 through 6
95
 * @property-read int              $lastWeekDay                                                                       0 through 6
96
 * @property-read int              $daysInYear                                                                        365 or 366
97
 * @property-read int              $quarter                                                                           the quarter of this instance, 1 - 4
98
 * @property-read int              $decade                                                                            the decade of this instance
99
 * @property-read int              $century                                                                           the century of this instance
100
 * @property-read int              $millennium                                                                        the millennium of this instance
101
 * @property-read bool             $dst                                                                               daylight savings time indicator, true if DST, false otherwise
102
 * @property-read bool             $local                                                                             checks if the timezone is local, true if local, false otherwise
103
 * @property-read bool             $utc                                                                               checks if the timezone is UTC, true if UTC, false otherwise
104
 * @property-read string           $timezoneName                                                                      the current timezone name
105
 * @property-read string           $tzName                                                                            alias of $timezoneName
106
 * @property-read string           $locale                                                                            locale of the current instance
107
 *
108
 * @method        bool             isUtc()                                                                            Check if the current instance has UTC timezone. (Both isUtc and isUTC cases are valid.)
109
 * @method        bool             isLocal()                                                                          Check if the current instance has non-UTC timezone.
110
 * @method        bool             isValid()                                                                          Check if the current instance is a valid date.
111
 * @method        bool             isDST()                                                                            Check if the current instance is in a daylight saving time.
112
 * @method        bool             isSunday()                                                                         Checks if the instance day is sunday.
113
 * @method        bool             isMonday()                                                                         Checks if the instance day is monday.
114
 * @method        bool             isTuesday()                                                                        Checks if the instance day is tuesday.
115
 * @method        bool             isWednesday()                                                                      Checks if the instance day is wednesday.
116
 * @method        bool             isThursday()                                                                       Checks if the instance day is thursday.
117
 * @method        bool             isFriday()                                                                         Checks if the instance day is friday.
118
 * @method        bool             isSaturday()                                                                       Checks if the instance day is saturday.
119
 * @method        bool             isSameYear(Carbon|DateTimeInterface|string|null $date = null)                      Checks if the given date is in the same year as the instance. If null passed, compare to now (with the same timezone).
120
 * @method        bool             isCurrentYear()                                                                    Checks if the instance is in the same year as the current moment.
121
 * @method        bool             isNextYear()                                                                       Checks if the instance is in the same year as the current moment next year.
122
 * @method        bool             isLastYear()                                                                       Checks if the instance is in the same year as the current moment last year.
123
 * @method        bool             isSameWeek(Carbon|DateTimeInterface|string|null $date = null)                      Checks if the given date is in the same week as the instance. If null passed, compare to now (with the same timezone).
124
 * @method        bool             isCurrentWeek()                                                                    Checks if the instance is in the same week as the current moment.
125
 * @method        bool             isNextWeek()                                                                       Checks if the instance is in the same week as the current moment next week.
126
 * @method        bool             isLastWeek()                                                                       Checks if the instance is in the same week as the current moment last week.
127
 * @method        bool             isSameDay(Carbon|DateTimeInterface|string|null $date = null)                       Checks if the given date is in the same day as the instance. If null passed, compare to now (with the same timezone).
128
 * @method        bool             isCurrentDay()                                                                     Checks if the instance is in the same day as the current moment.
129
 * @method        bool             isNextDay()                                                                        Checks if the instance is in the same day as the current moment next day.
130
 * @method        bool             isLastDay()                                                                        Checks if the instance is in the same day as the current moment last day.
131
 * @method        bool             isSameHour(Carbon|DateTimeInterface|string|null $date = null)                      Checks if the given date is in the same hour as the instance. If null passed, compare to now (with the same timezone).
132
 * @method        bool             isCurrentHour()                                                                    Checks if the instance is in the same hour as the current moment.
133
 * @method        bool             isNextHour()                                                                       Checks if the instance is in the same hour as the current moment next hour.
134
 * @method        bool             isLastHour()                                                                       Checks if the instance is in the same hour as the current moment last hour.
135
 * @method        bool             isSameMinute(Carbon|DateTimeInterface|string|null $date = null)                    Checks if the given date is in the same minute as the instance. If null passed, compare to now (with the same timezone).
136
 * @method        bool             isCurrentMinute()                                                                  Checks if the instance is in the same minute as the current moment.
137
 * @method        bool             isNextMinute()                                                                     Checks if the instance is in the same minute as the current moment next minute.
138
 * @method        bool             isLastMinute()                                                                     Checks if the instance is in the same minute as the current moment last minute.
139
 * @method        bool             isSameSecond(Carbon|DateTimeInterface|string|null $date = null)                    Checks if the given date is in the same second as the instance. If null passed, compare to now (with the same timezone).
140
 * @method        bool             isCurrentSecond()                                                                  Checks if the instance is in the same second as the current moment.
141
 * @method        bool             isNextSecond()                                                                     Checks if the instance is in the same second as the current moment next second.
142
 * @method        bool             isLastSecond()                                                                     Checks if the instance is in the same second as the current moment last second.
143
 * @method        bool             isSameMicro(Carbon|DateTimeInterface|string|null $date = null)                     Checks if the given date is in the same microsecond as the instance. If null passed, compare to now (with the same timezone).
144
 * @method        bool             isCurrentMicro()                                                                   Checks if the instance is in the same microsecond as the current moment.
145
 * @method        bool             isNextMicro()                                                                      Checks if the instance is in the same microsecond as the current moment next microsecond.
146
 * @method        bool             isLastMicro()                                                                      Checks if the instance is in the same microsecond as the current moment last microsecond.
147
 * @method        bool             isSameMicrosecond(Carbon|DateTimeInterface|string|null $date = null)               Checks if the given date is in the same microsecond as the instance. If null passed, compare to now (with the same timezone).
148
 * @method        bool             isCurrentMicrosecond()                                                             Checks if the instance is in the same microsecond as the current moment.
149
 * @method        bool             isNextMicrosecond()                                                                Checks if the instance is in the same microsecond as the current moment next microsecond.
150
 * @method        bool             isLastMicrosecond()                                                                Checks if the instance is in the same microsecond as the current moment last microsecond.
151
 * @method        bool             isCurrentMonth()                                                                   Checks if the instance is in the same month as the current moment.
152
 * @method        bool             isNextMonth()                                                                      Checks if the instance is in the same month as the current moment next month.
153
 * @method        bool             isLastMonth()                                                                      Checks if the instance is in the same month as the current moment last month.
154
 * @method        bool             isCurrentQuarter()                                                                 Checks if the instance is in the same quarter as the current moment.
155
 * @method        bool             isNextQuarter()                                                                    Checks if the instance is in the same quarter as the current moment next quarter.
156
 * @method        bool             isLastQuarter()                                                                    Checks if the instance is in the same quarter as the current moment last quarter.
157
 * @method        bool             isSameDecade(Carbon|DateTimeInterface|string|null $date = null)                    Checks if the given date is in the same decade as the instance. If null passed, compare to now (with the same timezone).
158
 * @method        bool             isCurrentDecade()                                                                  Checks if the instance is in the same decade as the current moment.
159
 * @method        bool             isNextDecade()                                                                     Checks if the instance is in the same decade as the current moment next decade.
160
 * @method        bool             isLastDecade()                                                                     Checks if the instance is in the same decade as the current moment last decade.
161
 * @method        bool             isSameCentury(Carbon|DateTimeInterface|string|null $date = null)                   Checks if the given date is in the same century as the instance. If null passed, compare to now (with the same timezone).
162
 * @method        bool             isCurrentCentury()                                                                 Checks if the instance is in the same century as the current moment.
163
 * @method        bool             isNextCentury()                                                                    Checks if the instance is in the same century as the current moment next century.
164
 * @method        bool             isLastCentury()                                                                    Checks if the instance is in the same century as the current moment last century.
165
 * @method        bool             isSameMillennium(Carbon|DateTimeInterface|string|null $date = null)                Checks if the given date is in the same millennium as the instance. If null passed, compare to now (with the same timezone).
166
 * @method        bool             isCurrentMillennium()                                                              Checks if the instance is in the same millennium as the current moment.
167
 * @method        bool             isNextMillennium()                                                                 Checks if the instance is in the same millennium as the current moment next millennium.
168
 * @method        bool             isLastMillennium()                                                                 Checks if the instance is in the same millennium as the current moment last millennium.
169
 * @method        CarbonInterface  years(int $value)                                                                  Set current instance year to the given value.
170
 * @method        CarbonInterface  year(int $value)                                                                   Set current instance year to the given value.
171
 * @method        CarbonInterface  setYears(int $value)                                                               Set current instance year to the given value.
172
 * @method        CarbonInterface  setYear(int $value)                                                                Set current instance year to the given value.
173
 * @method        CarbonInterface  months(int $value)                                                                 Set current instance month to the given value.
174
 * @method        CarbonInterface  month(int $value)                                                                  Set current instance month to the given value.
175
 * @method        CarbonInterface  setMonths(int $value)                                                              Set current instance month to the given value.
176
 * @method        CarbonInterface  setMonth(int $value)                                                               Set current instance month to the given value.
177
 * @method        CarbonInterface  days(int $value)                                                                   Set current instance day to the given value.
178
 * @method        CarbonInterface  day(int $value)                                                                    Set current instance day to the given value.
179
 * @method        CarbonInterface  setDays(int $value)                                                                Set current instance day to the given value.
180
 * @method        CarbonInterface  setDay(int $value)                                                                 Set current instance day to the given value.
181
 * @method        CarbonInterface  hours(int $value)                                                                  Set current instance hour to the given value.
182
 * @method        CarbonInterface  hour(int $value)                                                                   Set current instance hour to the given value.
183
 * @method        CarbonInterface  setHours(int $value)                                                               Set current instance hour to the given value.
184
 * @method        CarbonInterface  setHour(int $value)                                                                Set current instance hour to the given value.
185
 * @method        CarbonInterface  minutes(int $value)                                                                Set current instance minute to the given value.
186
 * @method        CarbonInterface  minute(int $value)                                                                 Set current instance minute to the given value.
187
 * @method        CarbonInterface  setMinutes(int $value)                                                             Set current instance minute to the given value.
188
 * @method        CarbonInterface  setMinute(int $value)                                                              Set current instance minute to the given value.
189
 * @method        CarbonInterface  seconds(int $value)                                                                Set current instance second to the given value.
190
 * @method        CarbonInterface  second(int $value)                                                                 Set current instance second to the given value.
191
 * @method        CarbonInterface  setSeconds(int $value)                                                             Set current instance second to the given value.
192
 * @method        CarbonInterface  setSecond(int $value)                                                              Set current instance second to the given value.
193
 * @method        CarbonInterface  millis(int $value)                                                                 Set current instance millisecond to the given value.
194
 * @method        CarbonInterface  milli(int $value)                                                                  Set current instance millisecond to the given value.
195
 * @method        CarbonInterface  setMillis(int $value)                                                              Set current instance millisecond to the given value.
196
 * @method        CarbonInterface  setMilli(int $value)                                                               Set current instance millisecond to the given value.
197
 * @method        CarbonInterface  milliseconds(int $value)                                                           Set current instance millisecond to the given value.
198
 * @method        CarbonInterface  millisecond(int $value)                                                            Set current instance millisecond to the given value.
199
 * @method        CarbonInterface  setMilliseconds(int $value)                                                        Set current instance millisecond to the given value.
200
 * @method        CarbonInterface  setMillisecond(int $value)                                                         Set current instance millisecond to the given value.
201
 * @method        CarbonInterface  micros(int $value)                                                                 Set current instance microsecond to the given value.
202
 * @method        CarbonInterface  micro(int $value)                                                                  Set current instance microsecond to the given value.
203
 * @method        CarbonInterface  setMicros(int $value)                                                              Set current instance microsecond to the given value.
204
 * @method        CarbonInterface  setMicro(int $value)                                                               Set current instance microsecond to the given value.
205
 * @method        CarbonInterface  microseconds(int $value)                                                           Set current instance microsecond to the given value.
206
 * @method        CarbonInterface  microsecond(int $value)                                                            Set current instance microsecond to the given value.
207
 * @method        CarbonInterface  setMicroseconds(int $value)                                                        Set current instance microsecond to the given value.
208
 * @method        CarbonInterface  setMicrosecond(int $value)                                                         Set current instance microsecond to the given value.
209
 * @method        CarbonInterface  addYears(int $value = 1)                                                           Add years (the $value count passed in) to the instance (using date interval).
210
 * @method        CarbonInterface  addYear()                                                                          Add one year to the instance (using date interval).
211
 * @method        CarbonInterface  subYears(int $value = 1)                                                           Sub years (the $value count passed in) to the instance (using date interval).
212
 * @method        CarbonInterface  subYear()                                                                          Sub one year to the instance (using date interval).
213
 * @method        CarbonInterface  addYearsWithOverflow(int $value = 1)                                               Add years (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
214
 * @method        CarbonInterface  addYearWithOverflow()                                                              Add one year to the instance (using date interval) with overflow explicitly allowed.
215
 * @method        CarbonInterface  subYearsWithOverflow(int $value = 1)                                               Sub years (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
216
 * @method        CarbonInterface  subYearWithOverflow()                                                              Sub one year to the instance (using date interval) with overflow explicitly allowed.
217
 * @method        CarbonInterface  addYearsWithoutOverflow(int $value = 1)                                            Add years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
218
 * @method        CarbonInterface  addYearWithoutOverflow()                                                           Add one year to the instance (using date interval) with overflow explicitly forbidden.
219
 * @method        CarbonInterface  subYearsWithoutOverflow(int $value = 1)                                            Sub years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
220
 * @method        CarbonInterface  subYearWithoutOverflow()                                                           Sub one year to the instance (using date interval) with overflow explicitly forbidden.
221
 * @method        CarbonInterface  addYearsWithNoOverflow(int $value = 1)                                             Add years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
222
 * @method        CarbonInterface  addYearWithNoOverflow()                                                            Add one year to the instance (using date interval) with overflow explicitly forbidden.
223
 * @method        CarbonInterface  subYearsWithNoOverflow(int $value = 1)                                             Sub years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
224
 * @method        CarbonInterface  subYearWithNoOverflow()                                                            Sub one year to the instance (using date interval) with overflow explicitly forbidden.
225
 * @method        CarbonInterface  addYearsNoOverflow(int $value = 1)                                                 Add years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
226
 * @method        CarbonInterface  addYearNoOverflow()                                                                Add one year to the instance (using date interval) with overflow explicitly forbidden.
227
 * @method        CarbonInterface  subYearsNoOverflow(int $value = 1)                                                 Sub years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
228
 * @method        CarbonInterface  subYearNoOverflow()                                                                Sub one year to the instance (using date interval) with overflow explicitly forbidden.
229
 * @method        CarbonInterface  addMonths(int $value = 1)                                                          Add months (the $value count passed in) to the instance (using date interval).
230
 * @method        CarbonInterface  addMonth()                                                                         Add one month to the instance (using date interval).
231
 * @method        CarbonInterface  subMonths(int $value = 1)                                                          Sub months (the $value count passed in) to the instance (using date interval).
232
 * @method        CarbonInterface  subMonth()                                                                         Sub one month to the instance (using date interval).
233
 * @method        CarbonInterface  addMonthsWithOverflow(int $value = 1)                                              Add months (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
234
 * @method        CarbonInterface  addMonthWithOverflow()                                                             Add one month to the instance (using date interval) with overflow explicitly allowed.
235
 * @method        CarbonInterface  subMonthsWithOverflow(int $value = 1)                                              Sub months (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
236
 * @method        CarbonInterface  subMonthWithOverflow()                                                             Sub one month to the instance (using date interval) with overflow explicitly allowed.
237
 * @method        CarbonInterface  addMonthsWithoutOverflow(int $value = 1)                                           Add months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
238
 * @method        CarbonInterface  addMonthWithoutOverflow()                                                          Add one month to the instance (using date interval) with overflow explicitly forbidden.
239
 * @method        CarbonInterface  subMonthsWithoutOverflow(int $value = 1)                                           Sub months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
240
 * @method        CarbonInterface  subMonthWithoutOverflow()                                                          Sub one month to the instance (using date interval) with overflow explicitly forbidden.
241
 * @method        CarbonInterface  addMonthsWithNoOverflow(int $value = 1)                                            Add months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
242
 * @method        CarbonInterface  addMonthWithNoOverflow()                                                           Add one month to the instance (using date interval) with overflow explicitly forbidden.
243
 * @method        CarbonInterface  subMonthsWithNoOverflow(int $value = 1)                                            Sub months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
244
 * @method        CarbonInterface  subMonthWithNoOverflow()                                                           Sub one month to the instance (using date interval) with overflow explicitly forbidden.
245
 * @method        CarbonInterface  addMonthsNoOverflow(int $value = 1)                                                Add months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
246
 * @method        CarbonInterface  addMonthNoOverflow()                                                               Add one month to the instance (using date interval) with overflow explicitly forbidden.
247
 * @method        CarbonInterface  subMonthsNoOverflow(int $value = 1)                                                Sub months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
248
 * @method        CarbonInterface  subMonthNoOverflow()                                                               Sub one month to the instance (using date interval) with overflow explicitly forbidden.
249
 * @method        CarbonInterface  addDays(int $value = 1)                                                            Add days (the $value count passed in) to the instance (using date interval).
250
 * @method        CarbonInterface  addDay()                                                                           Add one day to the instance (using date interval).
251
 * @method        CarbonInterface  subDays(int $value = 1)                                                            Sub days (the $value count passed in) to the instance (using date interval).
252
 * @method        CarbonInterface  subDay()                                                                           Sub one day to the instance (using date interval).
253
 * @method        CarbonInterface  addHours(int $value = 1)                                                           Add hours (the $value count passed in) to the instance (using date interval).
254
 * @method        CarbonInterface  addHour()                                                                          Add one hour to the instance (using date interval).
255
 * @method        CarbonInterface  subHours(int $value = 1)                                                           Sub hours (the $value count passed in) to the instance (using date interval).
256
 * @method        CarbonInterface  subHour()                                                                          Sub one hour to the instance (using date interval).
257
 * @method        CarbonInterface  addMinutes(int $value = 1)                                                         Add minutes (the $value count passed in) to the instance (using date interval).
258
 * @method        CarbonInterface  addMinute()                                                                        Add one minute to the instance (using date interval).
259
 * @method        CarbonInterface  subMinutes(int $value = 1)                                                         Sub minutes (the $value count passed in) to the instance (using date interval).
260
 * @method        CarbonInterface  subMinute()                                                                        Sub one minute to the instance (using date interval).
261
 * @method        CarbonInterface  addSeconds(int $value = 1)                                                         Add seconds (the $value count passed in) to the instance (using date interval).
262
 * @method        CarbonInterface  addSecond()                                                                        Add one second to the instance (using date interval).
263
 * @method        CarbonInterface  subSeconds(int $value = 1)                                                         Sub seconds (the $value count passed in) to the instance (using date interval).
264
 * @method        CarbonInterface  subSecond()                                                                        Sub one second to the instance (using date interval).
265
 * @method        CarbonInterface  addMillis(int $value = 1)                                                          Add milliseconds (the $value count passed in) to the instance (using date interval).
266
 * @method        CarbonInterface  addMilli()                                                                         Add one millisecond to the instance (using date interval).
267
 * @method        CarbonInterface  subMillis(int $value = 1)                                                          Sub milliseconds (the $value count passed in) to the instance (using date interval).
268
 * @method        CarbonInterface  subMilli()                                                                         Sub one millisecond to the instance (using date interval).
269
 * @method        CarbonInterface  addMilliseconds(int $value = 1)                                                    Add milliseconds (the $value count passed in) to the instance (using date interval).
270
 * @method        CarbonInterface  addMillisecond()                                                                   Add one millisecond to the instance (using date interval).
271
 * @method        CarbonInterface  subMilliseconds(int $value = 1)                                                    Sub milliseconds (the $value count passed in) to the instance (using date interval).
272
 * @method        CarbonInterface  subMillisecond()                                                                   Sub one millisecond to the instance (using date interval).
273
 * @method        CarbonInterface  addMicros(int $value = 1)                                                          Add microseconds (the $value count passed in) to the instance (using date interval).
274
 * @method        CarbonInterface  addMicro()                                                                         Add one microsecond to the instance (using date interval).
275
 * @method        CarbonInterface  subMicros(int $value = 1)                                                          Sub microseconds (the $value count passed in) to the instance (using date interval).
276
 * @method        CarbonInterface  subMicro()                                                                         Sub one microsecond to the instance (using date interval).
277
 * @method        CarbonInterface  addMicroseconds(int $value = 1)                                                    Add microseconds (the $value count passed in) to the instance (using date interval).
278
 * @method        CarbonInterface  addMicrosecond()                                                                   Add one microsecond to the instance (using date interval).
279
 * @method        CarbonInterface  subMicroseconds(int $value = 1)                                                    Sub microseconds (the $value count passed in) to the instance (using date interval).
280
 * @method        CarbonInterface  subMicrosecond()                                                                   Sub one microsecond to the instance (using date interval).
281
 * @method        CarbonInterface  addMillennia(int $value = 1)                                                       Add millennia (the $value count passed in) to the instance (using date interval).
282
 * @method        CarbonInterface  addMillennium()                                                                    Add one millennium to the instance (using date interval).
283
 * @method        CarbonInterface  subMillennia(int $value = 1)                                                       Sub millennia (the $value count passed in) to the instance (using date interval).
284
 * @method        CarbonInterface  subMillennium()                                                                    Sub one millennium to the instance (using date interval).
285
 * @method        CarbonInterface  addMillenniaWithOverflow(int $value = 1)                                           Add millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
286
 * @method        CarbonInterface  addMillenniumWithOverflow()                                                        Add one millennium to the instance (using date interval) with overflow explicitly allowed.
287
 * @method        CarbonInterface  subMillenniaWithOverflow(int $value = 1)                                           Sub millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
288
 * @method        CarbonInterface  subMillenniumWithOverflow()                                                        Sub one millennium to the instance (using date interval) with overflow explicitly allowed.
289
 * @method        CarbonInterface  addMillenniaWithoutOverflow(int $value = 1)                                        Add millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
290
 * @method        CarbonInterface  addMillenniumWithoutOverflow()                                                     Add one millennium to the instance (using date interval) with overflow explicitly forbidden.
291
 * @method        CarbonInterface  subMillenniaWithoutOverflow(int $value = 1)                                        Sub millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
292
 * @method        CarbonInterface  subMillenniumWithoutOverflow()                                                     Sub one millennium to the instance (using date interval) with overflow explicitly forbidden.
293
 * @method        CarbonInterface  addMillenniaWithNoOverflow(int $value = 1)                                         Add millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
294
 * @method        CarbonInterface  addMillenniumWithNoOverflow()                                                      Add one millennium to the instance (using date interval) with overflow explicitly forbidden.
295
 * @method        CarbonInterface  subMillenniaWithNoOverflow(int $value = 1)                                         Sub millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
296
 * @method        CarbonInterface  subMillenniumWithNoOverflow()                                                      Sub one millennium to the instance (using date interval) with overflow explicitly forbidden.
297
 * @method        CarbonInterface  addMillenniaNoOverflow(int $value = 1)                                             Add millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
298
 * @method        CarbonInterface  addMillenniumNoOverflow()                                                          Add one millennium to the instance (using date interval) with overflow explicitly forbidden.
299
 * @method        CarbonInterface  subMillenniaNoOverflow(int $value = 1)                                             Sub millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
300
 * @method        CarbonInterface  subMillenniumNoOverflow()                                                          Sub one millennium to the instance (using date interval) with overflow explicitly forbidden.
301
 * @method        CarbonInterface  addCenturies(int $value = 1)                                                       Add centuries (the $value count passed in) to the instance (using date interval).
302
 * @method        CarbonInterface  addCentury()                                                                       Add one century to the instance (using date interval).
303
 * @method        CarbonInterface  subCenturies(int $value = 1)                                                       Sub centuries (the $value count passed in) to the instance (using date interval).
304
 * @method        CarbonInterface  subCentury()                                                                       Sub one century to the instance (using date interval).
305
 * @method        CarbonInterface  addCenturiesWithOverflow(int $value = 1)                                           Add centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
306
 * @method        CarbonInterface  addCenturyWithOverflow()                                                           Add one century to the instance (using date interval) with overflow explicitly allowed.
307
 * @method        CarbonInterface  subCenturiesWithOverflow(int $value = 1)                                           Sub centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
308
 * @method        CarbonInterface  subCenturyWithOverflow()                                                           Sub one century to the instance (using date interval) with overflow explicitly allowed.
309
 * @method        CarbonInterface  addCenturiesWithoutOverflow(int $value = 1)                                        Add centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
310
 * @method        CarbonInterface  addCenturyWithoutOverflow()                                                        Add one century to the instance (using date interval) with overflow explicitly forbidden.
311
 * @method        CarbonInterface  subCenturiesWithoutOverflow(int $value = 1)                                        Sub centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
312
 * @method        CarbonInterface  subCenturyWithoutOverflow()                                                        Sub one century to the instance (using date interval) with overflow explicitly forbidden.
313
 * @method        CarbonInterface  addCenturiesWithNoOverflow(int $value = 1)                                         Add centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
314
 * @method        CarbonInterface  addCenturyWithNoOverflow()                                                         Add one century to the instance (using date interval) with overflow explicitly forbidden.
315
 * @method        CarbonInterface  subCenturiesWithNoOverflow(int $value = 1)                                         Sub centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
316
 * @method        CarbonInterface  subCenturyWithNoOverflow()                                                         Sub one century to the instance (using date interval) with overflow explicitly forbidden.
317
 * @method        CarbonInterface  addCenturiesNoOverflow(int $value = 1)                                             Add centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
318
 * @method        CarbonInterface  addCenturyNoOverflow()                                                             Add one century to the instance (using date interval) with overflow explicitly forbidden.
319
 * @method        CarbonInterface  subCenturiesNoOverflow(int $value = 1)                                             Sub centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
320
 * @method        CarbonInterface  subCenturyNoOverflow()                                                             Sub one century to the instance (using date interval) with overflow explicitly forbidden.
321
 * @method        CarbonInterface  addDecades(int $value = 1)                                                         Add decades (the $value count passed in) to the instance (using date interval).
322
 * @method        CarbonInterface  addDecade()                                                                        Add one decade to the instance (using date interval).
323
 * @method        CarbonInterface  subDecades(int $value = 1)                                                         Sub decades (the $value count passed in) to the instance (using date interval).
324
 * @method        CarbonInterface  subDecade()                                                                        Sub one decade to the instance (using date interval).
325
 * @method        CarbonInterface  addDecadesWithOverflow(int $value = 1)                                             Add decades (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
326
 * @method        CarbonInterface  addDecadeWithOverflow()                                                            Add one decade to the instance (using date interval) with overflow explicitly allowed.
327
 * @method        CarbonInterface  subDecadesWithOverflow(int $value = 1)                                             Sub decades (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
328
 * @method        CarbonInterface  subDecadeWithOverflow()                                                            Sub one decade to the instance (using date interval) with overflow explicitly allowed.
329
 * @method        CarbonInterface  addDecadesWithoutOverflow(int $value = 1)                                          Add decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
330
 * @method        CarbonInterface  addDecadeWithoutOverflow()                                                         Add one decade to the instance (using date interval) with overflow explicitly forbidden.
331
 * @method        CarbonInterface  subDecadesWithoutOverflow(int $value = 1)                                          Sub decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
332
 * @method        CarbonInterface  subDecadeWithoutOverflow()                                                         Sub one decade to the instance (using date interval) with overflow explicitly forbidden.
333
 * @method        CarbonInterface  addDecadesWithNoOverflow(int $value = 1)                                           Add decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
334
 * @method        CarbonInterface  addDecadeWithNoOverflow()                                                          Add one decade to the instance (using date interval) with overflow explicitly forbidden.
335
 * @method        CarbonInterface  subDecadesWithNoOverflow(int $value = 1)                                           Sub decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
336
 * @method        CarbonInterface  subDecadeWithNoOverflow()                                                          Sub one decade to the instance (using date interval) with overflow explicitly forbidden.
337
 * @method        CarbonInterface  addDecadesNoOverflow(int $value = 1)                                               Add decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
338
 * @method        CarbonInterface  addDecadeNoOverflow()                                                              Add one decade to the instance (using date interval) with overflow explicitly forbidden.
339
 * @method        CarbonInterface  subDecadesNoOverflow(int $value = 1)                                               Sub decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
340
 * @method        CarbonInterface  subDecadeNoOverflow()                                                              Sub one decade to the instance (using date interval) with overflow explicitly forbidden.
341
 * @method        CarbonInterface  addQuarters(int $value = 1)                                                        Add quarters (the $value count passed in) to the instance (using date interval).
342
 * @method        CarbonInterface  addQuarter()                                                                       Add one quarter to the instance (using date interval).
343
 * @method        CarbonInterface  subQuarters(int $value = 1)                                                        Sub quarters (the $value count passed in) to the instance (using date interval).
344
 * @method        CarbonInterface  subQuarter()                                                                       Sub one quarter to the instance (using date interval).
345
 * @method        CarbonInterface  addQuartersWithOverflow(int $value = 1)                                            Add quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
346
 * @method        CarbonInterface  addQuarterWithOverflow()                                                           Add one quarter to the instance (using date interval) with overflow explicitly allowed.
347
 * @method        CarbonInterface  subQuartersWithOverflow(int $value = 1)                                            Sub quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
348
 * @method        CarbonInterface  subQuarterWithOverflow()                                                           Sub one quarter to the instance (using date interval) with overflow explicitly allowed.
349
 * @method        CarbonInterface  addQuartersWithoutOverflow(int $value = 1)                                         Add quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
350
 * @method        CarbonInterface  addQuarterWithoutOverflow()                                                        Add one quarter to the instance (using date interval) with overflow explicitly forbidden.
351
 * @method        CarbonInterface  subQuartersWithoutOverflow(int $value = 1)                                         Sub quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
352
 * @method        CarbonInterface  subQuarterWithoutOverflow()                                                        Sub one quarter to the instance (using date interval) with overflow explicitly forbidden.
353
 * @method        CarbonInterface  addQuartersWithNoOverflow(int $value = 1)                                          Add quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
354
 * @method        CarbonInterface  addQuarterWithNoOverflow()                                                         Add one quarter to the instance (using date interval) with overflow explicitly forbidden.
355
 * @method        CarbonInterface  subQuartersWithNoOverflow(int $value = 1)                                          Sub quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
356
 * @method        CarbonInterface  subQuarterWithNoOverflow()                                                         Sub one quarter to the instance (using date interval) with overflow explicitly forbidden.
357
 * @method        CarbonInterface  addQuartersNoOverflow(int $value = 1)                                              Add quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
358
 * @method        CarbonInterface  addQuarterNoOverflow()                                                             Add one quarter to the instance (using date interval) with overflow explicitly forbidden.
359
 * @method        CarbonInterface  subQuartersNoOverflow(int $value = 1)                                              Sub quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
360
 * @method        CarbonInterface  subQuarterNoOverflow()                                                             Sub one quarter to the instance (using date interval) with overflow explicitly forbidden.
361
 * @method        CarbonInterface  addWeeks(int $value = 1)                                                           Add weeks (the $value count passed in) to the instance (using date interval).
362
 * @method        CarbonInterface  addWeek()                                                                          Add one week to the instance (using date interval).
363
 * @method        CarbonInterface  subWeeks(int $value = 1)                                                           Sub weeks (the $value count passed in) to the instance (using date interval).
364
 * @method        CarbonInterface  subWeek()                                                                          Sub one week to the instance (using date interval).
365
 * @method        CarbonInterface  addWeekdays(int $value = 1)                                                        Add weekdays (the $value count passed in) to the instance (using date interval).
366
 * @method        CarbonInterface  addWeekday()                                                                       Add one weekday to the instance (using date interval).
367
 * @method        CarbonInterface  subWeekdays(int $value = 1)                                                        Sub weekdays (the $value count passed in) to the instance (using date interval).
368
 * @method        CarbonInterface  subWeekday()                                                                       Sub one weekday to the instance (using date interval).
369
 * @method        CarbonInterface  addRealMicros(int $value = 1)                                                      Add microseconds (the $value count passed in) to the instance (using timestamp).
370
 * @method        CarbonInterface  addRealMicro()                                                                     Add one microsecond to the instance (using timestamp).
371
 * @method        CarbonInterface  subRealMicros(int $value = 1)                                                      Sub microseconds (the $value count passed in) to the instance (using timestamp).
372
 * @method        CarbonInterface  subRealMicro()                                                                     Sub one microsecond to the instance (using timestamp).
373
 * @method        CarbonPeriod     microsUntil($endDate = null, int $factor = 1)                                      Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each microsecond or every X microseconds if a factor is given.
374
 * @method        CarbonInterface  addRealMicroseconds(int $value = 1)                                                Add microseconds (the $value count passed in) to the instance (using timestamp).
375
 * @method        CarbonInterface  addRealMicrosecond()                                                               Add one microsecond to the instance (using timestamp).
376
 * @method        CarbonInterface  subRealMicroseconds(int $value = 1)                                                Sub microseconds (the $value count passed in) to the instance (using timestamp).
377
 * @method        CarbonInterface  subRealMicrosecond()                                                               Sub one microsecond to the instance (using timestamp).
378
 * @method        CarbonPeriod     microsecondsUntil($endDate = null, int $factor = 1)                                Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each microsecond or every X microseconds if a factor is given.
379
 * @method        CarbonInterface  addRealMillis(int $value = 1)                                                      Add milliseconds (the $value count passed in) to the instance (using timestamp).
380
 * @method        CarbonInterface  addRealMilli()                                                                     Add one millisecond to the instance (using timestamp).
381
 * @method        CarbonInterface  subRealMillis(int $value = 1)                                                      Sub milliseconds (the $value count passed in) to the instance (using timestamp).
382
 * @method        CarbonInterface  subRealMilli()                                                                     Sub one millisecond to the instance (using timestamp).
383
 * @method        CarbonPeriod     millisUntil($endDate = null, int $factor = 1)                                      Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each millisecond or every X milliseconds if a factor is given.
384
 * @method        CarbonInterface  addRealMilliseconds(int $value = 1)                                                Add milliseconds (the $value count passed in) to the instance (using timestamp).
385
 * @method        CarbonInterface  addRealMillisecond()                                                               Add one millisecond to the instance (using timestamp).
386
 * @method        CarbonInterface  subRealMilliseconds(int $value = 1)                                                Sub milliseconds (the $value count passed in) to the instance (using timestamp).
387
 * @method        CarbonInterface  subRealMillisecond()                                                               Sub one millisecond to the instance (using timestamp).
388
 * @method        CarbonPeriod     millisecondsUntil($endDate = null, int $factor = 1)                                Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each millisecond or every X milliseconds if a factor is given.
389
 * @method        CarbonInterface  addRealSeconds(int $value = 1)                                                     Add seconds (the $value count passed in) to the instance (using timestamp).
390
 * @method        CarbonInterface  addRealSecond()                                                                    Add one second to the instance (using timestamp).
391
 * @method        CarbonInterface  subRealSeconds(int $value = 1)                                                     Sub seconds (the $value count passed in) to the instance (using timestamp).
392
 * @method        CarbonInterface  subRealSecond()                                                                    Sub one second to the instance (using timestamp).
393
 * @method        CarbonPeriod     secondsUntil($endDate = null, int $factor = 1)                                     Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each second or every X seconds if a factor is given.
394
 * @method        CarbonInterface  addRealMinutes(int $value = 1)                                                     Add minutes (the $value count passed in) to the instance (using timestamp).
395
 * @method        CarbonInterface  addRealMinute()                                                                    Add one minute to the instance (using timestamp).
396
 * @method        CarbonInterface  subRealMinutes(int $value = 1)                                                     Sub minutes (the $value count passed in) to the instance (using timestamp).
397
 * @method        CarbonInterface  subRealMinute()                                                                    Sub one minute to the instance (using timestamp).
398
 * @method        CarbonPeriod     minutesUntil($endDate = null, int $factor = 1)                                     Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each minute or every X minutes if a factor is given.
399
 * @method        CarbonInterface  addRealHours(int $value = 1)                                                       Add hours (the $value count passed in) to the instance (using timestamp).
400
 * @method        CarbonInterface  addRealHour()                                                                      Add one hour to the instance (using timestamp).
401
 * @method        CarbonInterface  subRealHours(int $value = 1)                                                       Sub hours (the $value count passed in) to the instance (using timestamp).
402
 * @method        CarbonInterface  subRealHour()                                                                      Sub one hour to the instance (using timestamp).
403
 * @method        CarbonPeriod     hoursUntil($endDate = null, int $factor = 1)                                       Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each hour or every X hours if a factor is given.
404
 * @method        CarbonInterface  addRealDays(int $value = 1)                                                        Add days (the $value count passed in) to the instance (using timestamp).
405
 * @method        CarbonInterface  addRealDay()                                                                       Add one day to the instance (using timestamp).
406
 * @method        CarbonInterface  subRealDays(int $value = 1)                                                        Sub days (the $value count passed in) to the instance (using timestamp).
407
 * @method        CarbonInterface  subRealDay()                                                                       Sub one day to the instance (using timestamp).
408
 * @method        CarbonPeriod     daysUntil($endDate = null, int $factor = 1)                                        Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each day or every X days if a factor is given.
409
 * @method        CarbonInterface  addRealWeeks(int $value = 1)                                                       Add weeks (the $value count passed in) to the instance (using timestamp).
410
 * @method        CarbonInterface  addRealWeek()                                                                      Add one week to the instance (using timestamp).
411
 * @method        CarbonInterface  subRealWeeks(int $value = 1)                                                       Sub weeks (the $value count passed in) to the instance (using timestamp).
412
 * @method        CarbonInterface  subRealWeek()                                                                      Sub one week to the instance (using timestamp).
413
 * @method        CarbonPeriod     weeksUntil($endDate = null, int $factor = 1)                                       Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each week or every X weeks if a factor is given.
414
 * @method        CarbonInterface  addRealMonths(int $value = 1)                                                      Add months (the $value count passed in) to the instance (using timestamp).
415
 * @method        CarbonInterface  addRealMonth()                                                                     Add one month to the instance (using timestamp).
416
 * @method        CarbonInterface  subRealMonths(int $value = 1)                                                      Sub months (the $value count passed in) to the instance (using timestamp).
417
 * @method        CarbonInterface  subRealMonth()                                                                     Sub one month to the instance (using timestamp).
418
 * @method        CarbonPeriod     monthsUntil($endDate = null, int $factor = 1)                                      Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each month or every X months if a factor is given.
419
 * @method        CarbonInterface  addRealQuarters(int $value = 1)                                                    Add quarters (the $value count passed in) to the instance (using timestamp).
420
 * @method        CarbonInterface  addRealQuarter()                                                                   Add one quarter to the instance (using timestamp).
421
 * @method        CarbonInterface  subRealQuarters(int $value = 1)                                                    Sub quarters (the $value count passed in) to the instance (using timestamp).
422
 * @method        CarbonInterface  subRealQuarter()                                                                   Sub one quarter to the instance (using timestamp).
423
 * @method        CarbonPeriod     quartersUntil($endDate = null, int $factor = 1)                                    Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each quarter or every X quarters if a factor is given.
424
 * @method        CarbonInterface  addRealYears(int $value = 1)                                                       Add years (the $value count passed in) to the instance (using timestamp).
425
 * @method        CarbonInterface  addRealYear()                                                                      Add one year to the instance (using timestamp).
426
 * @method        CarbonInterface  subRealYears(int $value = 1)                                                       Sub years (the $value count passed in) to the instance (using timestamp).
427
 * @method        CarbonInterface  subRealYear()                                                                      Sub one year to the instance (using timestamp).
428
 * @method        CarbonPeriod     yearsUntil($endDate = null, int $factor = 1)                                       Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each year or every X years if a factor is given.
429
 * @method        CarbonInterface  addRealDecades(int $value = 1)                                                     Add decades (the $value count passed in) to the instance (using timestamp).
430
 * @method        CarbonInterface  addRealDecade()                                                                    Add one decade to the instance (using timestamp).
431
 * @method        CarbonInterface  subRealDecades(int $value = 1)                                                     Sub decades (the $value count passed in) to the instance (using timestamp).
432
 * @method        CarbonInterface  subRealDecade()                                                                    Sub one decade to the instance (using timestamp).
433
 * @method        CarbonPeriod     decadesUntil($endDate = null, int $factor = 1)                                     Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each decade or every X decades if a factor is given.
434
 * @method        CarbonInterface  addRealCenturies(int $value = 1)                                                   Add centuries (the $value count passed in) to the instance (using timestamp).
435
 * @method        CarbonInterface  addRealCentury()                                                                   Add one century to the instance (using timestamp).
436
 * @method        CarbonInterface  subRealCenturies(int $value = 1)                                                   Sub centuries (the $value count passed in) to the instance (using timestamp).
437
 * @method        CarbonInterface  subRealCentury()                                                                   Sub one century to the instance (using timestamp).
438
 * @method        CarbonPeriod     centuriesUntil($endDate = null, int $factor = 1)                                   Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each century or every X centuries if a factor is given.
439
 * @method        CarbonInterface  addRealMillennia(int $value = 1)                                                   Add millennia (the $value count passed in) to the instance (using timestamp).
440
 * @method        CarbonInterface  addRealMillennium()                                                                Add one millennium to the instance (using timestamp).
441
 * @method        CarbonInterface  subRealMillennia(int $value = 1)                                                   Sub millennia (the $value count passed in) to the instance (using timestamp).
442
 * @method        CarbonInterface  subRealMillennium()                                                                Sub one millennium to the instance (using timestamp).
443
 * @method        CarbonPeriod     millenniaUntil($endDate = null, int $factor = 1)                                   Return an iterable period from current date to given end (string, DateTime or Carbon instance) for each millennium or every X millennia if a factor is given.
444
 * @method        CarbonInterface  roundYear(float $precision = 1, string $function = "round")                        Round the current instance year with given precision using the given function.
445
 * @method        CarbonInterface  roundYears(float $precision = 1, string $function = "round")                       Round the current instance year with given precision using the given function.
446
 * @method        CarbonInterface  floorYear(float $precision = 1)                                                    Truncate the current instance year with given precision.
447
 * @method        CarbonInterface  floorYears(float $precision = 1)                                                   Truncate the current instance year with given precision.
448
 * @method        CarbonInterface  ceilYear(float $precision = 1)                                                     Ceil the current instance year with given precision.
449
 * @method        CarbonInterface  ceilYears(float $precision = 1)                                                    Ceil the current instance year with given precision.
450
 * @method        CarbonInterface  roundMonth(float $precision = 1, string $function = "round")                       Round the current instance month with given precision using the given function.
451
 * @method        CarbonInterface  roundMonths(float $precision = 1, string $function = "round")                      Round the current instance month with given precision using the given function.
452
 * @method        CarbonInterface  floorMonth(float $precision = 1)                                                   Truncate the current instance month with given precision.
453
 * @method        CarbonInterface  floorMonths(float $precision = 1)                                                  Truncate the current instance month with given precision.
454
 * @method        CarbonInterface  ceilMonth(float $precision = 1)                                                    Ceil the current instance month with given precision.
455
 * @method        CarbonInterface  ceilMonths(float $precision = 1)                                                   Ceil the current instance month with given precision.
456
 * @method        CarbonInterface  roundDay(float $precision = 1, string $function = "round")                         Round the current instance day with given precision using the given function.
457
 * @method        CarbonInterface  roundDays(float $precision = 1, string $function = "round")                        Round the current instance day with given precision using the given function.
458
 * @method        CarbonInterface  floorDay(float $precision = 1)                                                     Truncate the current instance day with given precision.
459
 * @method        CarbonInterface  floorDays(float $precision = 1)                                                    Truncate the current instance day with given precision.
460
 * @method        CarbonInterface  ceilDay(float $precision = 1)                                                      Ceil the current instance day with given precision.
461
 * @method        CarbonInterface  ceilDays(float $precision = 1)                                                     Ceil the current instance day with given precision.
462
 * @method        CarbonInterface  roundHour(float $precision = 1, string $function = "round")                        Round the current instance hour with given precision using the given function.
463
 * @method        CarbonInterface  roundHours(float $precision = 1, string $function = "round")                       Round the current instance hour with given precision using the given function.
464
 * @method        CarbonInterface  floorHour(float $precision = 1)                                                    Truncate the current instance hour with given precision.
465
 * @method        CarbonInterface  floorHours(float $precision = 1)                                                   Truncate the current instance hour with given precision.
466
 * @method        CarbonInterface  ceilHour(float $precision = 1)                                                     Ceil the current instance hour with given precision.
467
 * @method        CarbonInterface  ceilHours(float $precision = 1)                                                    Ceil the current instance hour with given precision.
468
 * @method        CarbonInterface  roundMinute(float $precision = 1, string $function = "round")                      Round the current instance minute with given precision using the given function.
469
 * @method        CarbonInterface  roundMinutes(float $precision = 1, string $function = "round")                     Round the current instance minute with given precision using the given function.
470
 * @method        CarbonInterface  floorMinute(float $precision = 1)                                                  Truncate the current instance minute with given precision.
471
 * @method        CarbonInterface  floorMinutes(float $precision = 1)                                                 Truncate the current instance minute with given precision.
472
 * @method        CarbonInterface  ceilMinute(float $precision = 1)                                                   Ceil the current instance minute with given precision.
473
 * @method        CarbonInterface  ceilMinutes(float $precision = 1)                                                  Ceil the current instance minute with given precision.
474
 * @method        CarbonInterface  roundSecond(float $precision = 1, string $function = "round")                      Round the current instance second with given precision using the given function.
475
 * @method        CarbonInterface  roundSeconds(float $precision = 1, string $function = "round")                     Round the current instance second with given precision using the given function.
476
 * @method        CarbonInterface  floorSecond(float $precision = 1)                                                  Truncate the current instance second with given precision.
477
 * @method        CarbonInterface  floorSeconds(float $precision = 1)                                                 Truncate the current instance second with given precision.
478
 * @method        CarbonInterface  ceilSecond(float $precision = 1)                                                   Ceil the current instance second with given precision.
479
 * @method        CarbonInterface  ceilSeconds(float $precision = 1)                                                  Ceil the current instance second with given precision.
480
 * @method        CarbonInterface  roundMillennium(float $precision = 1, string $function = "round")                  Round the current instance millennium with given precision using the given function.
481
 * @method        CarbonInterface  roundMillennia(float $precision = 1, string $function = "round")                   Round the current instance millennium with given precision using the given function.
482
 * @method        CarbonInterface  floorMillennium(float $precision = 1)                                              Truncate the current instance millennium with given precision.
483
 * @method        CarbonInterface  floorMillennia(float $precision = 1)                                               Truncate the current instance millennium with given precision.
484
 * @method        CarbonInterface  ceilMillennium(float $precision = 1)                                               Ceil the current instance millennium with given precision.
485
 * @method        CarbonInterface  ceilMillennia(float $precision = 1)                                                Ceil the current instance millennium with given precision.
486
 * @method        CarbonInterface  roundCentury(float $precision = 1, string $function = "round")                     Round the current instance century with given precision using the given function.
487
 * @method        CarbonInterface  roundCenturies(float $precision = 1, string $function = "round")                   Round the current instance century with given precision using the given function.
488
 * @method        CarbonInterface  floorCentury(float $precision = 1)                                                 Truncate the current instance century with given precision.
489
 * @method        CarbonInterface  floorCenturies(float $precision = 1)                                               Truncate the current instance century with given precision.
490
 * @method        CarbonInterface  ceilCentury(float $precision = 1)                                                  Ceil the current instance century with given precision.
491
 * @method        CarbonInterface  ceilCenturies(float $precision = 1)                                                Ceil the current instance century with given precision.
492
 * @method        CarbonInterface  roundDecade(float $precision = 1, string $function = "round")                      Round the current instance decade with given precision using the given function.
493
 * @method        CarbonInterface  roundDecades(float $precision = 1, string $function = "round")                     Round the current instance decade with given precision using the given function.
494
 * @method        CarbonInterface  floorDecade(float $precision = 1)                                                  Truncate the current instance decade with given precision.
495
 * @method        CarbonInterface  floorDecades(float $precision = 1)                                                 Truncate the current instance decade with given precision.
496
 * @method        CarbonInterface  ceilDecade(float $precision = 1)                                                   Ceil the current instance decade with given precision.
497
 * @method        CarbonInterface  ceilDecades(float $precision = 1)                                                  Ceil the current instance decade with given precision.
498
 * @method        CarbonInterface  roundQuarter(float $precision = 1, string $function = "round")                     Round the current instance quarter with given precision using the given function.
499
 * @method        CarbonInterface  roundQuarters(float $precision = 1, string $function = "round")                    Round the current instance quarter with given precision using the given function.
500
 * @method        CarbonInterface  floorQuarter(float $precision = 1)                                                 Truncate the current instance quarter with given precision.
501
 * @method        CarbonInterface  floorQuarters(float $precision = 1)                                                Truncate the current instance quarter with given precision.
502
 * @method        CarbonInterface  ceilQuarter(float $precision = 1)                                                  Ceil the current instance quarter with given precision.
503
 * @method        CarbonInterface  ceilQuarters(float $precision = 1)                                                 Ceil the current instance quarter with given precision.
504
 * @method        CarbonInterface  roundMillisecond(float $precision = 1, string $function = "round")                 Round the current instance millisecond with given precision using the given function.
505
 * @method        CarbonInterface  roundMilliseconds(float $precision = 1, string $function = "round")                Round the current instance millisecond with given precision using the given function.
506
 * @method        CarbonInterface  floorMillisecond(float $precision = 1)                                             Truncate the current instance millisecond with given precision.
507
 * @method        CarbonInterface  floorMilliseconds(float $precision = 1)                                            Truncate the current instance millisecond with given precision.
508
 * @method        CarbonInterface  ceilMillisecond(float $precision = 1)                                              Ceil the current instance millisecond with given precision.
509
 * @method        CarbonInterface  ceilMilliseconds(float $precision = 1)                                             Ceil the current instance millisecond with given precision.
510
 * @method        CarbonInterface  roundMicrosecond(float $precision = 1, string $function = "round")                 Round the current instance microsecond with given precision using the given function.
511
 * @method        CarbonInterface  roundMicroseconds(float $precision = 1, string $function = "round")                Round the current instance microsecond with given precision using the given function.
512
 * @method        CarbonInterface  floorMicrosecond(float $precision = 1)                                             Truncate the current instance microsecond with given precision.
513
 * @method        CarbonInterface  floorMicroseconds(float $precision = 1)                                            Truncate the current instance microsecond with given precision.
514
 * @method        CarbonInterface  ceilMicrosecond(float $precision = 1)                                              Ceil the current instance microsecond with given precision.
515
 * @method        CarbonInterface  ceilMicroseconds(float $precision = 1)                                             Ceil the current instance microsecond with given precision.
516
 * @method        string           shortAbsoluteDiffForHumans(DateTimeInterface $other = null, int $parts = 1)        Get the difference (short format, 'Absolute' mode) in a human readable format in the current locale. ($other and $parts parameters can be swapped.)
517
 * @method        string           longAbsoluteDiffForHumans(DateTimeInterface $other = null, int $parts = 1)         Get the difference (long format, 'Absolute' mode) in a human readable format in the current locale. ($other and $parts parameters can be swapped.)
518
 * @method        string           shortRelativeDiffForHumans(DateTimeInterface $other = null, int $parts = 1)        Get the difference (short format, 'Relative' mode) in a human readable format in the current locale. ($other and $parts parameters can be swapped.)
519
 * @method        string           longRelativeDiffForHumans(DateTimeInterface $other = null, int $parts = 1)         Get the difference (long format, 'Relative' mode) in a human readable format in the current locale. ($other and $parts parameters can be swapped.)
520
 * @method        string           shortRelativeToNowDiffForHumans(DateTimeInterface $other = null, int $parts = 1)   Get the difference (short format, 'RelativeToNow' mode) in a human readable format in the current locale. ($other and $parts parameters can be swapped.)
521
 * @method        string           longRelativeToNowDiffForHumans(DateTimeInterface $other = null, int $parts = 1)    Get the difference (long format, 'RelativeToNow' mode) in a human readable format in the current locale. ($other and $parts parameters can be swapped.)
522
 * @method        string           shortRelativeToOtherDiffForHumans(DateTimeInterface $other = null, int $parts = 1) Get the difference (short format, 'RelativeToOther' mode) in a human readable format in the current locale. ($other and $parts parameters can be swapped.)
523
 * @method        string           longRelativeToOtherDiffForHumans(DateTimeInterface $other = null, int $parts = 1)  Get the difference (long format, 'RelativeToOther' mode) in a human readable format in the current locale. ($other and $parts parameters can be swapped.)
524
 *
525
 * </autodoc>
526
 */
527
trait Date
528
{
529
    use Boundaries;
530
    use Comparison;
531
    use Converter;
532
    use Creator;
533
    use Difference;
534
    use Macro;
535
    use MagicParameter;
536
    use Modifiers;
537
    use Mutability;
538
    use ObjectInitialisation;
539
    use Options;
540
    use Rounding;
541
    use Serialization;
542
    use Test;
543
    use Timestamp;
544
    use Units;
545
    use Week;
546
 
547
    /**
548
     * Names of days of the week.
549
     *
550
     * @var array
551
     */
552
    protected static $days = [
553
        // @call isDayOfWeek
554
        CarbonInterface::SUNDAY => 'Sunday',
555
        // @call isDayOfWeek
556
        CarbonInterface::MONDAY => 'Monday',
557
        // @call isDayOfWeek
558
        CarbonInterface::TUESDAY => 'Tuesday',
559
        // @call isDayOfWeek
560
        CarbonInterface::WEDNESDAY => 'Wednesday',
561
        // @call isDayOfWeek
562
        CarbonInterface::THURSDAY => 'Thursday',
563
        // @call isDayOfWeek
564
        CarbonInterface::FRIDAY => 'Friday',
565
        // @call isDayOfWeek
566
        CarbonInterface::SATURDAY => 'Saturday',
567
    ];
568
 
569
    /**
570
     * Will UTF8 encoding be used to print localized date/time ?
571
     *
572
     * @var bool
573
     */
574
    protected static $utf8 = false;
575
 
576
    /**
577
     * List of unit and magic methods associated as doc-comments.
578
     *
579
     * @var array
580
     */
581
    protected static $units = [
582
        // @call setUnit
583
        // @call addUnit
584
        'year',
585
        // @call setUnit
586
        // @call addUnit
587
        'month',
588
        // @call setUnit
589
        // @call addUnit
590
        'day',
591
        // @call setUnit
592
        // @call addUnit
593
        'hour',
594
        // @call setUnit
595
        // @call addUnit
596
        'minute',
597
        // @call setUnit
598
        // @call addUnit
599
        'second',
600
        // @call setUnit
601
        // @call addUnit
602
        'milli',
603
        // @call setUnit
604
        // @call addUnit
605
        'millisecond',
606
        // @call setUnit
607
        // @call addUnit
608
        'micro',
609
        // @call setUnit
610
        // @call addUnit
611
        'microsecond',
612
    ];
613
 
614
    /**
615
     * Creates a DateTimeZone from a string, DateTimeZone or integer offset.
616
     *
617
     * @param DateTimeZone|string|int|null $object     original value to get CarbonTimeZone from it.
618
     * @param DateTimeZone|string|int|null $objectDump dump of the object for error messages.
619
     *
620
     * @throws InvalidTimeZoneException
621
     *
622
     * @return CarbonTimeZone|false
623
     */
624
    protected static function safeCreateDateTimeZone($object, $objectDump = null)
625
    {
626
        return CarbonTimeZone::instance($object, $objectDump);
627
    }
628
 
629
    /**
630
     * Get the TimeZone associated with the Carbon instance (as CarbonTimeZone).
631
     *
632
     * @return CarbonTimeZone
633
     *
634
     * @link https://php.net/manual/en/datetime.gettimezone.php
635
     */
636
    #[ReturnTypeWillChange]
637
    public function getTimezone()
638
    {
639
        return CarbonTimeZone::instance(parent::getTimezone());
640
    }
641
 
642
    /**
643
     * List of minimum and maximums for each unit.
644
     *
645
     * @param int $daysInMonth
646
     *
647
     * @return array
648
     */
649
    protected static function getRangesByUnit(int $daysInMonth = 31): array
650
    {
651
        return [
652
            // @call roundUnit
653
            'year' => [1, 9999],
654
            // @call roundUnit
655
            'month' => [1, static::MONTHS_PER_YEAR],
656
            // @call roundUnit
657
            'day' => [1, $daysInMonth],
658
            // @call roundUnit
659
            'hour' => [0, static::HOURS_PER_DAY - 1],
660
            // @call roundUnit
661
            'minute' => [0, static::MINUTES_PER_HOUR - 1],
662
            // @call roundUnit
663
            'second' => [0, static::SECONDS_PER_MINUTE - 1],
664
        ];
665
    }
666
 
667
    /**
668
     * Get a copy of the instance.
669
     *
670
     * @return static
671
     */
672
    public function copy()
673
    {
674
        return clone $this;
675
    }
676
 
677
    /**
678
     * @alias copy
679
     *
680
     * Get a copy of the instance.
681
     *
682
     * @return static
683
     */
684
    public function clone()
685
    {
686
        return clone $this;
687
    }
688
 
689
    /**
690
     * Clone the current instance if it's mutable.
691
     *
692
     * This method is convenient to ensure you don't mutate the initial object
693
     * but avoid to make a useless copy of it if it's already immutable.
694
     *
695
     * @return static
696
     */
697
    public function avoidMutation(): self
698
    {
699
        if ($this instanceof DateTimeImmutable) {
700
            return $this;
701
        }
702
 
703
        return clone $this;
704
    }
705
 
706
    /**
707
     * Returns a present instance in the same timezone.
708
     *
709
     * @return static
710
     */
711
    public function nowWithSameTz()
712
    {
713
        return static::now($this->getTimezone());
714
    }
715
 
716
    /**
717
     * Throws an exception if the given object is not a DateTime and does not implement DateTimeInterface.
718
     *
719
     * @param mixed        $date
720
     * @param string|array $other
721
     *
722
     * @throws InvalidTypeException
723
     */
724
    protected static function expectDateTime($date, $other = [])
725
    {
726
        $message = 'Expected ';
727
        foreach ((array) $other as $expect) {
728
            $message .= "$expect, ";
729
        }
730
 
731
        if (!$date instanceof DateTime && !$date instanceof DateTimeInterface) {
732
            throw new InvalidTypeException(
733
                $message.'DateTime or DateTimeInterface, '.
734
                (\is_object($date) ? \get_class($date) : \gettype($date)).' given'
735
            );
736
        }
737
    }
738
 
739
    /**
740
     * Return the Carbon instance passed through, a now instance in the same timezone
741
     * if null given or parse the input if string given.
742
     *
743
     * @param Carbon|DateTimeInterface|string|null $date
744
     *
745
     * @return static
746
     */
747
    protected function resolveCarbon($date = null)
748
    {
749
        if (!$date) {
750
            return $this->nowWithSameTz();
751
        }
752
 
753
        if (\is_string($date)) {
754
            return static::parse($date, $this->getTimezone());
755
        }
756
 
757
        static::expectDateTime($date, ['null', 'string']);
758
 
759
        return $date instanceof self ? $date : static::instance($date);
760
    }
761
 
762
    /**
763
     * Return the Carbon instance passed through, a now instance in UTC
764
     * if null given or parse the input if string given (using current timezone
765
     * then switching to UTC).
766
     *
767
     * @param Carbon|DateTimeInterface|string|null $date
768
     *
769
     * @return static
770
     */
771
    protected function resolveUTC($date = null): self
772
    {
773
        if (!$date) {
774
            return static::now('UTC');
775
        }
776
 
777
        if (\is_string($date)) {
778
            return static::parse($date, $this->getTimezone())->utc();
779
        }
780
 
781
        static::expectDateTime($date, ['null', 'string']);
782
 
783
        return $date instanceof self ? $date : static::instance($date)->utc();
784
    }
785
 
786
    /**
787
     * Return the Carbon instance passed through, a now instance in the same timezone
788
     * if null given or parse the input if string given.
789
     *
790
     * @param Carbon|\Carbon\CarbonPeriod|\Carbon\CarbonInterval|\DateInterval|\DatePeriod|DateTimeInterface|string|null $date
791
     *
792
     * @return static
793
     */
794
    public function carbonize($date = null)
795
    {
796
        if ($date instanceof DateInterval) {
797
            return $this->avoidMutation()->add($date);
798
        }
799
 
800
        if ($date instanceof DatePeriod || $date instanceof CarbonPeriod) {
801
            $date = $date->getStartDate();
802
        }
803
 
804
        return $this->resolveCarbon($date);
805
    }
806
 
807
    ///////////////////////////////////////////////////////////////////
808
    ///////////////////////// GETTERS AND SETTERS /////////////////////
809
    ///////////////////////////////////////////////////////////////////
810
 
811
    /**
812
     * Get a part of the Carbon object
813
     *
814
     * @param string $name
815
     *
816
     * @throws UnknownGetterException
817
     *
818
     * @return string|int|bool|DateTimeZone|null
819
     */
820
    public function __get($name)
821
    {
822
        return $this->get($name);
823
    }
824
 
825
    /**
826
     * Get a part of the Carbon object
827
     *
828
     * @param string $name
829
     *
830
     * @throws UnknownGetterException
831
     *
832
     * @return string|int|bool|DateTimeZone|null
833
     */
834
    public function get($name)
835
    {
836
        static $formats = [
837
            // @property int
838
            'year' => 'Y',
839
            // @property int
840
            'yearIso' => 'o',
841
            // @property int
842
            // @call isSameUnit
843
            'month' => 'n',
844
            // @property int
845
            'day' => 'j',
846
            // @property int
847
            'hour' => 'G',
848
            // @property int
849
            'minute' => 'i',
850
            // @property int
851
            'second' => 's',
852
            // @property int
853
            'micro' => 'u',
854
            // @property int
855
            'microsecond' => 'u',
856
            // @property-read int 0 (for Sunday) through 6 (for Saturday)
857
            'dayOfWeek' => 'w',
858
            // @property-read int 1 (for Monday) through 7 (for Sunday)
859
            'dayOfWeekIso' => 'N',
860
            // @property-read int ISO-8601 week number of year, weeks starting on Monday
861
            'weekOfYear' => 'W',
862
            // @property-read int number of days in the given month
863
            'daysInMonth' => 't',
864
            // @property int|float|string seconds since the Unix Epoch
865
            'timestamp' => 'U',
866
            // @property-read string "am"/"pm" (Ante meridiem or Post meridiem latin lowercase mark)
867
            'latinMeridiem' => 'a',
868
            // @property-read string "AM"/"PM" (Ante meridiem or Post meridiem latin uppercase mark)
869
            'latinUpperMeridiem' => 'A',
870
            // @property string the day of week in English
871
            'englishDayOfWeek' => 'l',
872
            // @property string the abbreviated day of week in English
873
            'shortEnglishDayOfWeek' => 'D',
874
            // @property string the month in English
875
            'englishMonth' => 'F',
876
            // @property string the abbreviated month in English
877
            'shortEnglishMonth' => 'M',
878
            // @property string the day of week in current locale LC_TIME
879
            // @deprecated
880
            //   reason: It uses OS language package and strftime() which is deprecated since PHP 8.1.
881
            //   replacement: Use ->isoFormat('MMM') instead.
882
            //   since: 2.55.0
883
            'localeDayOfWeek' => '%A',
884
            // @property string the abbreviated day of week in current locale LC_TIME
885
            // @deprecated
886
            //   reason: It uses OS language package and strftime() which is deprecated since PHP 8.1.
887
            //   replacement: Use ->isoFormat('dddd') instead.
888
            //   since: 2.55.0
889
            'shortLocaleDayOfWeek' => '%a',
890
            // @property string the month in current locale LC_TIME
891
            // @deprecated
892
            //   reason: It uses OS language package and strftime() which is deprecated since PHP 8.1.
893
            //   replacement: Use ->isoFormat('ddd') instead.
894
            //   since: 2.55.0
895
            'localeMonth' => '%B',
896
            // @property string the abbreviated month in current locale LC_TIME
897
            // @deprecated
898
            //   reason: It uses OS language package and strftime() which is deprecated since PHP 8.1.
899
            //   replacement: Use ->isoFormat('MMMM') instead.
900
            //   since: 2.55.0
901
            'shortLocaleMonth' => '%b',
902
            // @property-read string $timezoneAbbreviatedName the current timezone abbreviated name
903
            'timezoneAbbreviatedName' => 'T',
904
            // @property-read string $tzAbbrName alias of $timezoneAbbreviatedName
905
            'tzAbbrName' => 'T',
906
        ];
907
 
908
        switch (true) {
909
            case isset($formats[$name]):
910
                $format = $formats[$name];
911
                $method = str_starts_with($format, '%') ? 'formatLocalized' : 'rawFormat';
912
                $value = $this->$method($format);
913
 
914
                return is_numeric($value) ? (int) $value : $value;
915
 
916
            // @property-read string long name of weekday translated according to Carbon locale, in english if no translation available for current language
917
            case $name === 'dayName':
918
                return $this->getTranslatedDayName();
919
            // @property-read string short name of weekday translated according to Carbon locale, in english if no translation available for current language
920
            case $name === 'shortDayName':
921
                return $this->getTranslatedShortDayName();
922
            // @property-read string very short name of weekday translated according to Carbon locale, in english if no translation available for current language
923
            case $name === 'minDayName':
924
                return $this->getTranslatedMinDayName();
925
            // @property-read string long name of month translated according to Carbon locale, in english if no translation available for current language
926
            case $name === 'monthName':
927
                return $this->getTranslatedMonthName();
928
            // @property-read string short name of month translated according to Carbon locale, in english if no translation available for current language
929
            case $name === 'shortMonthName':
930
                return $this->getTranslatedShortMonthName();
931
            // @property-read string lowercase meridiem mark translated according to Carbon locale, in latin if no translation available for current language
932
            case $name === 'meridiem':
933
                return $this->meridiem(true);
934
            // @property-read string uppercase meridiem mark translated according to Carbon locale, in latin if no translation available for current language
935
            case $name === 'upperMeridiem':
936
                return $this->meridiem();
937
            // @property-read int current hour from 1 to 24
938
            case $name === 'noZeroHour':
939
                return $this->hour ?: 24;
940
            // @property int
941
            case $name === 'milliseconds':
942
                // @property int
943
            case $name === 'millisecond':
944
            // @property int
945
            case $name === 'milli':
946
                return (int) floor(((int) $this->rawFormat('u')) / 1000);
947
 
948
            // @property int 1 through 53
949
            case $name === 'week':
950
                return (int) $this->week();
951
 
952
            // @property int 1 through 53
953
            case $name === 'isoWeek':
954
                return (int) $this->isoWeek();
955
 
956
            // @property int year according to week format
957
            case $name === 'weekYear':
958
                return (int) $this->weekYear();
959
 
960
            // @property int year according to ISO week format
961
            case $name === 'isoWeekYear':
962
                return (int) $this->isoWeekYear();
963
 
964
            // @property-read int 51 through 53
965
            case $name === 'weeksInYear':
966
                return $this->weeksInYear();
967
 
968
            // @property-read int 51 through 53
969
            case $name === 'isoWeeksInYear':
970
                return $this->isoWeeksInYear();
971
 
972
            // @property-read int 1 through 5
973
            case $name === 'weekOfMonth':
974
                return (int) ceil($this->day / static::DAYS_PER_WEEK);
975
 
976
            // @property-read int 1 through 5
977
            case $name === 'weekNumberInMonth':
978
                return (int) ceil(($this->day + $this->avoidMutation()->startOfMonth()->dayOfWeekIso - 1) / static::DAYS_PER_WEEK);
979
 
980
            // @property-read int 0 through 6
981
            case $name === 'firstWeekDay':
982
                return $this->localTranslator ? ($this->getTranslationMessage('first_day_of_week') ?? 0) : static::getWeekStartsAt();
983
 
984
            // @property-read int 0 through 6
985
            case $name === 'lastWeekDay':
986
                return $this->localTranslator ? (($this->getTranslationMessage('first_day_of_week') ?? 0) + static::DAYS_PER_WEEK - 1) % static::DAYS_PER_WEEK : static::getWeekEndsAt();
987
 
988
            // @property int 1 through 366
989
            case $name === 'dayOfYear':
990
                return 1 + (int) ($this->rawFormat('z'));
991
 
992
            // @property-read int 365 or 366
993
            case $name === 'daysInYear':
994
                return $this->isLeapYear() ? 366 : 365;
995
 
996
            // @property int does a diffInYears() with default parameters
997
            case $name === 'age':
998
                return $this->diffInYears();
999
 
1000
            // @property-read int the quarter of this instance, 1 - 4
1001
            // @call isSameUnit
1002
            case $name === 'quarter':
1003
                return (int) ceil($this->month / static::MONTHS_PER_QUARTER);
1004
 
1005
            // @property-read int the decade of this instance
1006
            // @call isSameUnit
1007
            case $name === 'decade':
1008
                return (int) ceil($this->year / static::YEARS_PER_DECADE);
1009
 
1010
            // @property-read int the century of this instance
1011
            // @call isSameUnit
1012
            case $name === 'century':
1013
                $factor = 1;
1014
                $year = $this->year;
1015
                if ($year < 0) {
1016
                    $year = -$year;
1017
                    $factor = -1;
1018
                }
1019
 
1020
                return (int) ($factor * ceil($year / static::YEARS_PER_CENTURY));
1021
 
1022
            // @property-read int the millennium of this instance
1023
            // @call isSameUnit
1024
            case $name === 'millennium':
1025
                $factor = 1;
1026
                $year = $this->year;
1027
                if ($year < 0) {
1028
                    $year = -$year;
1029
                    $factor = -1;
1030
                }
1031
 
1032
                return (int) ($factor * ceil($year / static::YEARS_PER_MILLENNIUM));
1033
 
1034
            // @property int the timezone offset in seconds from UTC
1035
            case $name === 'offset':
1036
                return $this->getOffset();
1037
 
1038
            // @property int the timezone offset in minutes from UTC
1039
            case $name === 'offsetMinutes':
1040
                return $this->getOffset() / static::SECONDS_PER_MINUTE;
1041
 
1042
            // @property int the timezone offset in hours from UTC
1043
            case $name === 'offsetHours':
1044
                return $this->getOffset() / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR;
1045
 
1046
            // @property-read bool daylight savings time indicator, true if DST, false otherwise
1047
            case $name === 'dst':
1048
                return $this->rawFormat('I') === '1';
1049
 
1050
            // @property-read bool checks if the timezone is local, true if local, false otherwise
1051
            case $name === 'local':
1052
                return $this->getOffset() === $this->avoidMutation()->setTimezone(date_default_timezone_get())->getOffset();
1053
 
1054
            // @property-read bool checks if the timezone is UTC, true if UTC, false otherwise
1055
            case $name === 'utc':
1056
                return $this->getOffset() === 0;
1057
 
1058
            // @property CarbonTimeZone $timezone the current timezone
1059
            // @property CarbonTimeZone $tz alias of $timezone
1060
            case $name === 'timezone' || $name === 'tz':
1061
                return CarbonTimeZone::instance($this->getTimezone());
1062
 
1063
            // @property-read string $timezoneName the current timezone name
1064
            // @property-read string $tzName alias of $timezoneName
1065
            case $name === 'timezoneName' || $name === 'tzName':
1066
                return $this->getTimezone()->getName();
1067
 
1068
            // @property-read string locale of the current instance
1069
            case $name === 'locale':
1070
                return $this->getTranslatorLocale();
1071
 
1072
            default:
1073
                $macro = $this->getLocalMacro('get'.ucfirst($name));
1074
 
1075
                if ($macro) {
1076
                    return $this->executeCallableWithContext($macro);
1077
                }
1078
 
1079
                throw new UnknownGetterException($name);
1080
        }
1081
    }
1082
 
1083
    /**
1084
     * Check if an attribute exists on the object
1085
     *
1086
     * @param string $name
1087
     *
1088
     * @return bool
1089
     */
1090
    public function __isset($name)
1091
    {
1092
        try {
1093
            $this->__get($name);
1094
        } catch (UnknownGetterException | ReflectionException $e) {
1095
            return false;
1096
        }
1097
 
1098
        return true;
1099
    }
1100
 
1101
    /**
1102
     * Set a part of the Carbon object
1103
     *
1104
     * @param string                  $name
1105
     * @param string|int|DateTimeZone $value
1106
     *
1107
     * @throws UnknownSetterException|ReflectionException
1108
     *
1109
     * @return void
1110
     */
1111
    public function __set($name, $value)
1112
    {
1113
        if ($this->constructedObjectId === spl_object_hash($this)) {
1114
            $this->set($name, $value);
1115
 
1116
            return;
1117
        }
1118
 
1119
        $this->$name = $value;
1120
    }
1121
 
1122
    /**
1123
     * Set a part of the Carbon object
1124
     *
1125
     * @param string|array            $name
1126
     * @param string|int|DateTimeZone $value
1127
     *
1128
     * @throws ImmutableException|UnknownSetterException
1129
     *
1130
     * @return $this
1131
     */
1132
    public function set($name, $value = null)
1133
    {
1134
        if ($this->isImmutable()) {
1135
            throw new ImmutableException(sprintf('%s class', static::class));
1136
        }
1137
 
1138
        if (\is_array($name)) {
1139
            foreach ($name as $key => $value) {
1140
                $this->set($key, $value);
1141
            }
1142
 
1143
            return $this;
1144
        }
1145
 
1146
        switch ($name) {
1147
            case 'milliseconds':
1148
            case 'millisecond':
1149
            case 'milli':
1150
            case 'microseconds':
1151
            case 'microsecond':
1152
            case 'micro':
1153
                if (str_starts_with($name, 'milli')) {
1154
                    $value *= 1000;
1155
                }
1156
 
1157
                while ($value < 0) {
1158
                    $this->subSecond();
1159
                    $value += static::MICROSECONDS_PER_SECOND;
1160
                }
1161
 
1162
                while ($value >= static::MICROSECONDS_PER_SECOND) {
1163
                    $this->addSecond();
1164
                    $value -= static::MICROSECONDS_PER_SECOND;
1165
                }
1166
 
1167
                $this->modify($this->rawFormat('H:i:s.').str_pad((string) round($value), 6, '0', STR_PAD_LEFT));
1168
 
1169
                break;
1170
 
1171
            case 'year':
1172
            case 'month':
1173
            case 'day':
1174
            case 'hour':
1175
            case 'minute':
1176
            case 'second':
1177
                [$year, $month, $day, $hour, $minute, $second] = array_map('intval', explode('-', $this->rawFormat('Y-n-j-G-i-s')));
1178
                $$name = $value;
1179
                $this->setDateTime($year, $month, $day, $hour, $minute, $second);
1180
 
1181
                break;
1182
 
1183
            case 'week':
1184
                $this->week($value);
1185
 
1186
                break;
1187
 
1188
            case 'isoWeek':
1189
                $this->isoWeek($value);
1190
 
1191
                break;
1192
 
1193
            case 'weekYear':
1194
                $this->weekYear($value);
1195
 
1196
                break;
1197
 
1198
            case 'isoWeekYear':
1199
                $this->isoWeekYear($value);
1200
 
1201
                break;
1202
 
1203
            case 'dayOfYear':
1204
                $this->addDays($value - $this->dayOfYear);
1205
 
1206
                break;
1207
 
1208
            case 'timestamp':
1209
                $this->setTimestamp($value);
1210
 
1211
                break;
1212
 
1213
            case 'offset':
1214
                $this->setTimezone(static::safeCreateDateTimeZone($value / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR));
1215
 
1216
                break;
1217
 
1218
            case 'offsetMinutes':
1219
                $this->setTimezone(static::safeCreateDateTimeZone($value / static::MINUTES_PER_HOUR));
1220
 
1221
                break;
1222
 
1223
            case 'offsetHours':
1224
                $this->setTimezone(static::safeCreateDateTimeZone($value));
1225
 
1226
                break;
1227
 
1228
            case 'timezone':
1229
            case 'tz':
1230
                $this->setTimezone($value);
1231
 
1232
                break;
1233
 
1234
            default:
1235
                $macro = $this->getLocalMacro('set'.ucfirst($name));
1236
 
1237
                if ($macro) {
1238
                    $this->executeCallableWithContext($macro, $value);
1239
 
1240
                    break;
1241
                }
1242
 
1243
                if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) {
1244
                    throw new UnknownSetterException($name);
1245
                }
1246
 
1247
                $this->$name = $value;
1248
        }
1249
 
1250
        return $this;
1251
    }
1252
 
1253
    protected function getTranslatedFormByRegExp($baseKey, $keySuffix, $context, $subKey, $defaultValue)
1254
    {
1255
        $key = $baseKey.$keySuffix;
1256
        $standaloneKey = "{$key}_standalone";
1257
        $baseTranslation = $this->getTranslationMessage($key);
1258
 
1259
        if ($baseTranslation instanceof Closure) {
1260
            return $baseTranslation($this, $context, $subKey) ?: $defaultValue;
1261
        }
1262
 
1263
        if (
1264
            $this->getTranslationMessage("$standaloneKey.$subKey") &&
1265
            (!$context || (($regExp = $this->getTranslationMessage("{$baseKey}_regexp")) && !preg_match($regExp, $context)))
1266
        ) {
1267
            $key = $standaloneKey;
1268
        }
1269
 
1270
        return $this->getTranslationMessage("$key.$subKey", null, $defaultValue);
1271
    }
1272
 
1273
    /**
1274
     * Get the translation of the current week day name (with context for languages with multiple forms).
1275
     *
1276
     * @param string|null $context      whole format string
1277
     * @param string      $keySuffix    "", "_short" or "_min"
1278
     * @param string|null $defaultValue default value if translation missing
1279
     *
1280
     * @return string
1281
     */
1282
    public function getTranslatedDayName($context = null, $keySuffix = '', $defaultValue = null)
1283
    {
1284
        return $this->getTranslatedFormByRegExp('weekdays', $keySuffix, $context, $this->dayOfWeek, $defaultValue ?: $this->englishDayOfWeek);
1285
    }
1286
 
1287
    /**
1288
     * Get the translation of the current short week day name (with context for languages with multiple forms).
1289
     *
1290
     * @param string|null $context whole format string
1291
     *
1292
     * @return string
1293
     */
1294
    public function getTranslatedShortDayName($context = null)
1295
    {
1296
        return $this->getTranslatedDayName($context, '_short', $this->shortEnglishDayOfWeek);
1297
    }
1298
 
1299
    /**
1300
     * Get the translation of the current abbreviated week day name (with context for languages with multiple forms).
1301
     *
1302
     * @param string|null $context whole format string
1303
     *
1304
     * @return string
1305
     */
1306
    public function getTranslatedMinDayName($context = null)
1307
    {
1308
        return $this->getTranslatedDayName($context, '_min', $this->shortEnglishDayOfWeek);
1309
    }
1310
 
1311
    /**
1312
     * Get the translation of the current month day name (with context for languages with multiple forms).
1313
     *
1314
     * @param string|null $context      whole format string
1315
     * @param string      $keySuffix    "" or "_short"
1316
     * @param string|null $defaultValue default value if translation missing
1317
     *
1318
     * @return string
1319
     */
1320
    public function getTranslatedMonthName($context = null, $keySuffix = '', $defaultValue = null)
1321
    {
1322
        return $this->getTranslatedFormByRegExp('months', $keySuffix, $context, $this->month - 1, $defaultValue ?: $this->englishMonth);
1323
    }
1324
 
1325
    /**
1326
     * Get the translation of the current short month day name (with context for languages with multiple forms).
1327
     *
1328
     * @param string|null $context whole format string
1329
     *
1330
     * @return string
1331
     */
1332
    public function getTranslatedShortMonthName($context = null)
1333
    {
1334
        return $this->getTranslatedMonthName($context, '_short', $this->shortEnglishMonth);
1335
    }
1336
 
1337
    /**
1338
     * Get/set the day of year.
1339
     *
1340
     * @param int|null $value new value for day of year if using as setter.
1341
     *
1342
     * @return static|int
1343
     */
1344
    public function dayOfYear($value = null)
1345
    {
1346
        $dayOfYear = $this->dayOfYear;
1347
 
1348
        return $value === null ? $dayOfYear : $this->addDays($value - $dayOfYear);
1349
    }
1350
 
1351
    /**
1352
     * Get/set the weekday from 0 (Sunday) to 6 (Saturday).
1353
     *
1354
     * @param int|null $value new value for weekday if using as setter.
1355
     *
1356
     * @return static|int
1357
     */
1358
    public function weekday($value = null)
1359
    {
1360
        if ($value === null) {
1361
            return $this->dayOfWeek;
1362
        }
1363
 
1364
        $firstDay = (int) ($this->getTranslationMessage('first_day_of_week') ?? 0);
1365
        $dayOfWeek = ($this->dayOfWeek + 7 - $firstDay) % 7;
1366
 
1367
        return $this->addDays((($value + 7 - $firstDay) % 7) - $dayOfWeek);
1368
    }
1369
 
1370
    /**
1371
     * Get/set the ISO weekday from 1 (Monday) to 7 (Sunday).
1372
     *
1373
     * @param int|null $value new value for weekday if using as setter.
1374
     *
1375
     * @return static|int
1376
     */
1377
    public function isoWeekday($value = null)
1378
    {
1379
        $dayOfWeekIso = $this->dayOfWeekIso;
1380
 
1381
        return $value === null ? $dayOfWeekIso : $this->addDays($value - $dayOfWeekIso);
1382
    }
1383
 
1384
    /**
1385
     * Return the number of days since the start of the week (using the current locale or the first parameter
1386
     * if explicitly given).
1387
     *
1388
     * @param int|null $weekStartsAt optional start allow you to specify the day of week to use to start the week,
1389
     *                               if not provided, start of week is inferred from the locale
1390
     *                               (Sunday for en_US, Monday for de_DE, etc.)
1391
     *
1392
     * @return int
1393
     */
1394
    public function getDaysFromStartOfWeek(int $weekStartsAt = null): int
1395
    {
1396
        $firstDay = (int) ($weekStartsAt ?? $this->getTranslationMessage('first_day_of_week') ?? 0);
1397
 
1398
        return ($this->dayOfWeek + 7 - $firstDay) % 7;
1399
    }
1400
 
1401
    /**
1402
     * Set the day (keeping the current time) to the start of the week + the number of days passed as the first
1403
     * parameter. First day of week is driven by the locale unless explicitly set with the second parameter.
1404
     *
1405
     * @param int      $numberOfDays number of days to add after the start of the current week
1406
     * @param int|null $weekStartsAt optional start allow you to specify the day of week to use to start the week,
1407
     *                               if not provided, start of week is inferred from the locale
1408
     *                               (Sunday for en_US, Monday for de_DE, etc.)
1409
     *
1410
     * @return static
1411
     */
1412
    public function setDaysFromStartOfWeek(int $numberOfDays, int $weekStartsAt = null)
1413
    {
1414
        return $this->addDays($numberOfDays - $this->getDaysFromStartOfWeek($weekStartsAt));
1415
    }
1416
 
1417
    /**
1418
     * Set any unit to a new value without overflowing current other unit given.
1419
     *
1420
     * @param string $valueUnit    unit name to modify
1421
     * @param int    $value        new value for the input unit
1422
     * @param string $overflowUnit unit name to not overflow
1423
     *
1424
     * @return static
1425
     */
1426
    public function setUnitNoOverflow($valueUnit, $value, $overflowUnit)
1427
    {
1428
        try {
1429
            $original = $this->avoidMutation();
1430
            /** @var static $date */
1431
            $date = $this->$valueUnit($value);
1432
            $end = $original->avoidMutation()->endOf($overflowUnit);
1433
            $start = $original->avoidMutation()->startOf($overflowUnit);
1434
            if ($date < $start) {
1435
                $date = $date->setDateTimeFrom($start);
1436
            } elseif ($date > $end) {
1437
                $date = $date->setDateTimeFrom($end);
1438
            }
1439
 
1440
            return $date;
1441
        } catch (BadMethodCallException | ReflectionException $exception) {
1442
            throw new UnknownUnitException($valueUnit, 0, $exception);
1443
        }
1444
    }
1445
 
1446
    /**
1447
     * Add any unit to a new value without overflowing current other unit given.
1448
     *
1449
     * @param string $valueUnit    unit name to modify
1450
     * @param int    $value        amount to add to the input unit
1451
     * @param string $overflowUnit unit name to not overflow
1452
     *
1453
     * @return static
1454
     */
1455
    public function addUnitNoOverflow($valueUnit, $value, $overflowUnit)
1456
    {
1457
        return $this->setUnitNoOverflow($valueUnit, $this->$valueUnit + $value, $overflowUnit);
1458
    }
1459
 
1460
    /**
1461
     * Subtract any unit to a new value without overflowing current other unit given.
1462
     *
1463
     * @param string $valueUnit    unit name to modify
1464
     * @param int    $value        amount to subtract to the input unit
1465
     * @param string $overflowUnit unit name to not overflow
1466
     *
1467
     * @return static
1468
     */
1469
    public function subUnitNoOverflow($valueUnit, $value, $overflowUnit)
1470
    {
1471
        return $this->setUnitNoOverflow($valueUnit, $this->$valueUnit - $value, $overflowUnit);
1472
    }
1473
 
1474
    /**
1475
     * Returns the minutes offset to UTC if no arguments passed, else set the timezone with given minutes shift passed.
1476
     *
1477
     * @param int|null $minuteOffset
1478
     *
1479
     * @return int|static
1480
     */
1481
    public function utcOffset(int $minuteOffset = null)
1482
    {
1483
        if (\func_num_args() < 1) {
1484
            return $this->offsetMinutes;
1485
        }
1486
 
1487
        return $this->setTimezone(CarbonTimeZone::createFromMinuteOffset($minuteOffset));
1488
    }
1489
 
1490
    /**
1491
     * Set the date with gregorian year, month and day numbers.
1492
     *
1493
     * @see https://php.net/manual/en/datetime.setdate.php
1494
     *
1495
     * @param int $year
1496
     * @param int $month
1497
     * @param int $day
1498
     *
1499
     * @return static
1500
     */
1501
    #[ReturnTypeWillChange]
1502
    public function setDate($year, $month, $day)
1503
    {
1504
        return parent::setDate((int) $year, (int) $month, (int) $day);
1505
    }
1506
 
1507
    /**
1508
     * Set a date according to the ISO 8601 standard - using weeks and day offsets rather than specific dates.
1509
     *
1510
     * @see https://php.net/manual/en/datetime.setisodate.php
1511
     *
1512
     * @param int $year
1513
     * @param int $week
1514
     * @param int $day
1515
     *
1516
     * @return static
1517
     */
1518
    #[ReturnTypeWillChange]
1519
    public function setISODate($year, $week, $day = 1)
1520
    {
1521
        return parent::setISODate((int) $year, (int) $week, (int) $day);
1522
    }
1523
 
1524
    /**
1525
     * Set the date and time all together.
1526
     *
1527
     * @param int $year
1528
     * @param int $month
1529
     * @param int $day
1530
     * @param int $hour
1531
     * @param int $minute
1532
     * @param int $second
1533
     * @param int $microseconds
1534
     *
1535
     * @return static
1536
     */
1537
    public function setDateTime($year, $month, $day, $hour, $minute, $second = 0, $microseconds = 0)
1538
    {
1539
        return $this->setDate($year, $month, $day)->setTime((int) $hour, (int) $minute, (int) $second, (int) $microseconds);
1540
    }
1541
 
1542
    /**
1543
     * Resets the current time of the DateTime object to a different time.
1544
     *
1545
     * @see https://php.net/manual/en/datetime.settime.php
1546
     *
1547
     * @param int $hour
1548
     * @param int $minute
1549
     * @param int $second
1550
     * @param int $microseconds
1551
     *
1552
     * @return static
1553
     */
1554
    #[ReturnTypeWillChange]
1555
    public function setTime($hour, $minute, $second = 0, $microseconds = 0)
1556
    {
1557
        return parent::setTime((int) $hour, (int) $minute, (int) $second, (int) $microseconds);
1558
    }
1559
 
1560
    /**
1561
     * Set the instance's timestamp.
1562
     *
1563
     * Timestamp input can be given as int, float or a string containing one or more numbers.
1564
     *
1565
     * @param float|int|string $unixTimestamp
1566
     *
1567
     * @return static
1568
     */
1569
    #[ReturnTypeWillChange]
1570
    public function setTimestamp($unixTimestamp)
1571
    {
1572
        [$timestamp, $microseconds] = self::getIntegerAndDecimalParts($unixTimestamp);
1573
 
1574
        return parent::setTimestamp((int) $timestamp)->setMicroseconds((int) $microseconds);
1575
    }
1576
 
1577
    /**
1578
     * Set the time by time string.
1579
     *
1580
     * @param string $time
1581
     *
1582
     * @return static
1583
     */
1584
    public function setTimeFromTimeString($time)
1585
    {
1586
        if (!str_contains($time, ':')) {
1587
            $time .= ':0';
1588
        }
1589
 
1590
        return $this->modify($time);
1591
    }
1592
 
1593
    /**
1594
     * @alias setTimezone
1595
     *
1596
     * @param DateTimeZone|string $value
1597
     *
1598
     * @return static
1599
     */
1600
    public function timezone($value)
1601
    {
1602
        return $this->setTimezone($value);
1603
    }
1604
 
1605
    /**
1606
     * Set the timezone or returns the timezone name if no arguments passed.
1607
     *
1608
     * @param DateTimeZone|string $value
1609
     *
1610
     * @return static|string
1611
     */
1612
    public function tz($value = null)
1613
    {
1614
        if (\func_num_args() < 1) {
1615
            return $this->tzName;
1616
        }
1617
 
1618
        return $this->setTimezone($value);
1619
    }
1620
 
1621
    /**
1622
     * Set the instance's timezone from a string or object.
1623
     *
1624
     * @param DateTimeZone|string $value
1625
     *
1626
     * @return static
1627
     */
1628
    #[ReturnTypeWillChange]
1629
    public function setTimezone($value)
1630
    {
1631
        $tz = static::safeCreateDateTimeZone($value);
1632
 
1633
        if ($tz === false && !self::isStrictModeEnabled()) {
1634
            $tz = new CarbonTimeZone();
1635
        }
1636
 
1637
        return parent::setTimezone($tz);
1638
    }
1639
 
1640
    /**
1641
     * Set the instance's timezone from a string or object and add/subtract the offset difference.
1642
     *
1643
     * @param DateTimeZone|string $value
1644
     *
1645
     * @return static
1646
     */
1647
    public function shiftTimezone($value)
1648
    {
1649
        $dateTimeString = $this->format('Y-m-d H:i:s.u');
1650
 
1651
        return $this
1652
            ->setTimezone($value)
1653
            ->modify($dateTimeString);
1654
    }
1655
 
1656
    /**
1657
     * Set the instance's timezone to UTC.
1658
     *
1659
     * @return static
1660
     */
1661
    public function utc()
1662
    {
1663
        return $this->setTimezone('UTC');
1664
    }
1665
 
1666
    /**
1667
     * Set the year, month, and date for this instance to that of the passed instance.
1668
     *
1669
     * @param Carbon|DateTimeInterface $date now if null
1670
     *
1671
     * @return static
1672
     */
1673
    public function setDateFrom($date = null)
1674
    {
1675
        $date = $this->resolveCarbon($date);
1676
 
1677
        return $this->setDate($date->year, $date->month, $date->day);
1678
    }
1679
 
1680
    /**
1681
     * Set the hour, minute, second and microseconds for this instance to that of the passed instance.
1682
     *
1683
     * @param Carbon|DateTimeInterface $date now if null
1684
     *
1685
     * @return static
1686
     */
1687
    public function setTimeFrom($date = null)
1688
    {
1689
        $date = $this->resolveCarbon($date);
1690
 
1691
        return $this->setTime($date->hour, $date->minute, $date->second, $date->microsecond);
1692
    }
1693
 
1694
    /**
1695
     * Set the date and time for this instance to that of the passed instance.
1696
     *
1697
     * @param Carbon|DateTimeInterface $date
1698
     *
1699
     * @return static
1700
     */
1701
    public function setDateTimeFrom($date = null)
1702
    {
1703
        $date = $this->resolveCarbon($date);
1704
 
1705
        return $this->modify($date->rawFormat('Y-m-d H:i:s.u'));
1706
    }
1707
 
1708
    /**
1709
     * Get the days of the week
1710
     *
1711
     * @return array
1712
     */
1713
    public static function getDays()
1714
    {
1715
        return static::$days;
1716
    }
1717
 
1718
    ///////////////////////////////////////////////////////////////////
1719
    /////////////////////// WEEK SPECIAL DAYS /////////////////////////
1720
    ///////////////////////////////////////////////////////////////////
1721
 
1722
    private static function getFirstDayOfWeek(): int
1723
    {
1724
        return (int) static::getTranslationMessageWith(
1725
            static::getTranslator(),
1726
            'first_day_of_week'
1727
        );
1728
    }
1729
 
1730
    /**
1731
     * Get the first day of week
1732
     *
1733
     * @return int
1734
     */
1735
    public static function getWeekStartsAt()
1736
    {
1737
        if (static::$weekStartsAt === static::WEEK_DAY_AUTO) {
1738
            return self::getFirstDayOfWeek();
1739
        }
1740
 
1741
        return static::$weekStartsAt;
1742
    }
1743
 
1744
    /**
1745
     * @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
1746
     *             Use $weekEndsAt optional parameter instead when using endOfWeek method. You can also use the
1747
     *             'first_day_of_week' locale setting to change the start of week according to current locale
1748
     *             selected and implicitly the end of week.
1749
     *
1750
     * Set the first day of week
1751
     *
1752
     * @param int|string $day week start day (or 'auto' to get the first day of week from Carbon::getLocale() culture).
1753
     *
1754
     * @return void
1755
     */
1756
    public static function setWeekStartsAt($day)
1757
    {
1758
        static::$weekStartsAt = $day === static::WEEK_DAY_AUTO ? $day : max(0, (7 + $day) % 7);
1759
    }
1760
 
1761
    /**
1762
     * Get the last day of week
1763
     *
1764
     * @return int
1765
     */
1766
    public static function getWeekEndsAt()
1767
    {
1768
        if (static::$weekStartsAt === static::WEEK_DAY_AUTO) {
1769
            return (int) (static::DAYS_PER_WEEK - 1 + self::getFirstDayOfWeek()) % static::DAYS_PER_WEEK;
1770
        }
1771
 
1772
        return static::$weekEndsAt;
1773
    }
1774
 
1775
    /**
1776
     * @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
1777
     *             Use $weekStartsAt optional parameter instead when using startOfWeek, floorWeek, ceilWeek
1778
     *             or roundWeek method. You can also use the 'first_day_of_week' locale setting to change the
1779
     *             start of week according to current locale selected and implicitly the end of week.
1780
     *
1781
     * Set the last day of week
1782
     *
1783
     * @param int|string $day week end day (or 'auto' to get the day before the first day of week
1784
     *                        from Carbon::getLocale() culture).
1785
     *
1786
     * @return void
1787
     */
1788
    public static function setWeekEndsAt($day)
1789
    {
1790
        static::$weekEndsAt = $day === static::WEEK_DAY_AUTO ? $day : max(0, (7 + $day) % 7);
1791
    }
1792
 
1793
    /**
1794
     * Get weekend days
1795
     *
1796
     * @return array
1797
     */
1798
    public static function getWeekendDays()
1799
    {
1800
        return static::$weekendDays;
1801
    }
1802
 
1803
    /**
1804
     * @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
1805
     *             You should rather consider week-end is always saturday and sunday, and if you have some custom
1806
     *             week-end days to handle, give to those days an other name and create a macro for them:
1807
     *
1808
     *             ```
1809
     *             Carbon::macro('isDayOff', function ($date) {
1810
     *                 return $date->isSunday() || $date->isMonday();
1811
     *             });
1812
     *             Carbon::macro('isNotDayOff', function ($date) {
1813
     *                 return !$date->isDayOff();
1814
     *             });
1815
     *             if ($someDate->isDayOff()) ...
1816
     *             if ($someDate->isNotDayOff()) ...
1817
     *             // Add 5 not-off days
1818
     *             $count = 5;
1819
     *             while ($someDate->isDayOff() || ($count-- > 0)) {
1820
     *                 $someDate->addDay();
1821
     *             }
1822
     *             ```
1823
     *
1824
     * Set weekend days
1825
     *
1826
     * @param array $days
1827
     *
1828
     * @return void
1829
     */
1830
    public static function setWeekendDays($days)
1831
    {
1832
        static::$weekendDays = $days;
1833
    }
1834
 
1835
    /**
1836
     * Determine if a time string will produce a relative date.
1837
     *
1838
     * @param string $time
1839
     *
1840
     * @return bool true if time match a relative date, false if absolute or invalid time string
1841
     */
1842
    public static function hasRelativeKeywords($time)
1843
    {
1844
        if (!$time || strtotime($time) === false) {
1845
            return false;
1846
        }
1847
 
1848
        $date1 = new DateTime('2000-01-01T00:00:00Z');
1849
        $date1->modify($time);
1850
        $date2 = new DateTime('2001-12-25T00:00:00Z');
1851
        $date2->modify($time);
1852
 
1853
        return $date1 != $date2;
1854
    }
1855
 
1856
    ///////////////////////////////////////////////////////////////////
1857
    /////////////////////// STRING FORMATTING /////////////////////////
1858
    ///////////////////////////////////////////////////////////////////
1859
 
1860
    /**
1861
     * @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
1862
     *             You should rather use UTF-8 language packages on every machine.
1863
     *
1864
     * Set if UTF8 will be used for localized date/time.
1865
     *
1866
     * @param bool $utf8
1867
     */
1868
    public static function setUtf8($utf8)
1869
    {
1870
        static::$utf8 = $utf8;
1871
    }
1872
 
1873
    /**
1874
     * Format the instance with the current locale.  You can set the current
1875
     * locale using setlocale() https://php.net/setlocale.
1876
     *
1877
     * @deprecated It uses OS language package and strftime() which is deprecated since PHP 8.1.
1878
     *             Use ->isoFormat() instead.
1879
     *             Deprecated since 2.55.0
1880
     *
1881
     * @param string $format
1882
     *
1883
     * @return string
1884
     */
1885
    public function formatLocalized($format)
1886
    {
1887
        // Check for Windows to find and replace the %e modifier correctly.
1888
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
1889
            $format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format); // @codeCoverageIgnore
1890
        }
1891
 
1892
        $time = strtotime($this->toDateTimeString());
1893
        $formatted = ($this->localStrictModeEnabled ?? static::isStrictModeEnabled())
1894
            ? strftime($format, $time)
1895
            : @strftime($format, $time);
1896
 
1897
        return static::$utf8
1898
            ? (
1899
                \function_exists('mb_convert_encoding')
1900
                ? mb_convert_encoding($formatted, 'UTF-8', mb_list_encodings())
1901
                : utf8_encode($formatted)
1902
            )
1903
            : $formatted;
1904
    }
1905
 
1906
    /**
1907
     * Returns list of locale formats for ISO formatting.
1908
     *
1909
     * @param string|null $locale current locale used if null
1910
     *
1911
     * @return array
1912
     */
1913
    public function getIsoFormats($locale = null)
1914
    {
1915
        return [
1916
            'LT' => $this->getTranslationMessage('formats.LT', $locale, 'h:mm A'),
1917
            'LTS' => $this->getTranslationMessage('formats.LTS', $locale, 'h:mm:ss A'),
1918
            'L' => $this->getTranslationMessage('formats.L', $locale, 'MM/DD/YYYY'),
1919
            'LL' => $this->getTranslationMessage('formats.LL', $locale, 'MMMM D, YYYY'),
1920
            'LLL' => $this->getTranslationMessage('formats.LLL', $locale, 'MMMM D, YYYY h:mm A'),
1921
            'LLLL' => $this->getTranslationMessage('formats.LLLL', $locale, 'dddd, MMMM D, YYYY h:mm A'),
1922
            'l' => $this->getTranslationMessage('formats.l', $locale),
1923
            'll' => $this->getTranslationMessage('formats.ll', $locale),
1924
            'lll' => $this->getTranslationMessage('formats.lll', $locale),
1925
            'llll' => $this->getTranslationMessage('formats.llll', $locale),
1926
        ];
1927
    }
1928
 
1929
    /**
1930
     * Returns list of calendar formats for ISO formatting.
1931
     *
1932
     * @param string|null $locale current locale used if null
1933
     *
1934
     * @return array
1935
     */
1936
    public function getCalendarFormats($locale = null)
1937
    {
1938
        return [
1939
            'sameDay' => $this->getTranslationMessage('calendar.sameDay', $locale, '[Today at] LT'),
1940
            'nextDay' => $this->getTranslationMessage('calendar.nextDay', $locale, '[Tomorrow at] LT'),
1941
            'nextWeek' => $this->getTranslationMessage('calendar.nextWeek', $locale, 'dddd [at] LT'),
1942
            'lastDay' => $this->getTranslationMessage('calendar.lastDay', $locale, '[Yesterday at] LT'),
1943
            'lastWeek' => $this->getTranslationMessage('calendar.lastWeek', $locale, '[Last] dddd [at] LT'),
1944
            'sameElse' => $this->getTranslationMessage('calendar.sameElse', $locale, 'L'),
1945
        ];
1946
    }
1947
 
1948
    /**
1949
     * Returns list of locale units for ISO formatting.
1950
     *
1951
     * @return array
1952
     */
1953
    public static function getIsoUnits()
1954
    {
1955
        static $units = null;
1956
 
1957
        if ($units === null) {
1958
            $units = [
1959
                'OD' => ['getAltNumber', ['day']],
1960
                'OM' => ['getAltNumber', ['month']],
1961
                'OY' => ['getAltNumber', ['year']],
1962
                'OH' => ['getAltNumber', ['hour']],
1963
                'Oh' => ['getAltNumber', ['h']],
1964
                'Om' => ['getAltNumber', ['minute']],
1965
                'Os' => ['getAltNumber', ['second']],
1966
                'D' => 'day',
1967
                'DD' => ['rawFormat', ['d']],
1968
                'Do' => ['ordinal', ['day', 'D']],
1969
                'd' => 'dayOfWeek',
1970
                'dd' => function (CarbonInterface $date, $originalFormat = null) {
1971
                    return $date->getTranslatedMinDayName($originalFormat);
1972
                },
1973
                'ddd' => function (CarbonInterface $date, $originalFormat = null) {
1974
                    return $date->getTranslatedShortDayName($originalFormat);
1975
                },
1976
                'dddd' => function (CarbonInterface $date, $originalFormat = null) {
1977
                    return $date->getTranslatedDayName($originalFormat);
1978
                },
1979
                'DDD' => 'dayOfYear',
1980
                'DDDD' => ['getPaddedUnit', ['dayOfYear', 3]],
1981
                'DDDo' => ['ordinal', ['dayOfYear', 'DDD']],
1982
                'e' => ['weekday', []],
1983
                'E' => 'dayOfWeekIso',
1984
                'H' => ['rawFormat', ['G']],
1985
                'HH' => ['rawFormat', ['H']],
1986
                'h' => ['rawFormat', ['g']],
1987
                'hh' => ['rawFormat', ['h']],
1988
                'k' => 'noZeroHour',
1989
                'kk' => ['getPaddedUnit', ['noZeroHour']],
1990
                'hmm' => ['rawFormat', ['gi']],
1991
                'hmmss' => ['rawFormat', ['gis']],
1992
                'Hmm' => ['rawFormat', ['Gi']],
1993
                'Hmmss' => ['rawFormat', ['Gis']],
1994
                'm' => 'minute',
1995
                'mm' => ['rawFormat', ['i']],
1996
                'a' => 'meridiem',
1997
                'A' => 'upperMeridiem',
1998
                's' => 'second',
1999
                'ss' => ['getPaddedUnit', ['second']],
2000
                'S' => function (CarbonInterface $date) {
2001
                    return (string) floor($date->micro / 100000);
2002
                },
2003
                'SS' => function (CarbonInterface $date) {
2004
                    return str_pad((string) floor($date->micro / 10000), 2, '0', STR_PAD_LEFT);
2005
                },
2006
                'SSS' => function (CarbonInterface $date) {
2007
                    return str_pad((string) floor($date->micro / 1000), 3, '0', STR_PAD_LEFT);
2008
                },
2009
                'SSSS' => function (CarbonInterface $date) {
2010
                    return str_pad((string) floor($date->micro / 100), 4, '0', STR_PAD_LEFT);
2011
                },
2012
                'SSSSS' => function (CarbonInterface $date) {
2013
                    return str_pad((string) floor($date->micro / 10), 5, '0', STR_PAD_LEFT);
2014
                },
2015
                'SSSSSS' => ['getPaddedUnit', ['micro', 6]],
2016
                'SSSSSSS' => function (CarbonInterface $date) {
2017
                    return str_pad((string) floor($date->micro * 10), 7, '0', STR_PAD_LEFT);
2018
                },
2019
                'SSSSSSSS' => function (CarbonInterface $date) {
2020
                    return str_pad((string) floor($date->micro * 100), 8, '0', STR_PAD_LEFT);
2021
                },
2022
                'SSSSSSSSS' => function (CarbonInterface $date) {
2023
                    return str_pad((string) floor($date->micro * 1000), 9, '0', STR_PAD_LEFT);
2024
                },
2025
                'M' => 'month',
2026
                'MM' => ['rawFormat', ['m']],
2027
                'MMM' => function (CarbonInterface $date, $originalFormat = null) {
2028
                    $month = $date->getTranslatedShortMonthName($originalFormat);
2029
                    $suffix = $date->getTranslationMessage('mmm_suffix');
2030
                    if ($suffix && $month !== $date->monthName) {
2031
                        $month .= $suffix;
2032
                    }
2033
 
2034
                    return $month;
2035
                },
2036
                'MMMM' => function (CarbonInterface $date, $originalFormat = null) {
2037
                    return $date->getTranslatedMonthName($originalFormat);
2038
                },
2039
                'Mo' => ['ordinal', ['month', 'M']],
2040
                'Q' => 'quarter',
2041
                'Qo' => ['ordinal', ['quarter', 'M']],
2042
                'G' => 'isoWeekYear',
2043
                'GG' => ['getPaddedUnit', ['isoWeekYear']],
2044
                'GGG' => ['getPaddedUnit', ['isoWeekYear', 3]],
2045
                'GGGG' => ['getPaddedUnit', ['isoWeekYear', 4]],
2046
                'GGGGG' => ['getPaddedUnit', ['isoWeekYear', 5]],
2047
                'g' => 'weekYear',
2048
                'gg' => ['getPaddedUnit', ['weekYear']],
2049
                'ggg' => ['getPaddedUnit', ['weekYear', 3]],
2050
                'gggg' => ['getPaddedUnit', ['weekYear', 4]],
2051
                'ggggg' => ['getPaddedUnit', ['weekYear', 5]],
2052
                'W' => 'isoWeek',
2053
                'WW' => ['getPaddedUnit', ['isoWeek']],
2054
                'Wo' => ['ordinal', ['isoWeek', 'W']],
2055
                'w' => 'week',
2056
                'ww' => ['getPaddedUnit', ['week']],
2057
                'wo' => ['ordinal', ['week', 'w']],
2058
                'x' => ['valueOf', []],
2059
                'X' => 'timestamp',
2060
                'Y' => 'year',
2061
                'YY' => ['rawFormat', ['y']],
2062
                'YYYY' => ['getPaddedUnit', ['year', 4]],
2063
                'YYYYY' => ['getPaddedUnit', ['year', 5]],
2064
                'YYYYYY' => function (CarbonInterface $date) {
2065
                    return ($date->year < 0 ? '' : '+').$date->getPaddedUnit('year', 6);
2066
                },
2067
                'z' => ['rawFormat', ['T']],
2068
                'zz' => 'tzName',
2069
                'Z' => ['getOffsetString', []],
2070
                'ZZ' => ['getOffsetString', ['']],
2071
            ];
2072
        }
2073
 
2074
        return $units;
2075
    }
2076
 
2077
    /**
2078
     * Returns a unit of the instance padded with 0 by default or any other string if specified.
2079
     *
2080
     * @param string $unit      Carbon unit name
2081
     * @param int    $length    Length of the output (2 by default)
2082
     * @param string $padString String to use for padding ("0" by default)
2083
     * @param int    $padType   Side(s) to pad (STR_PAD_LEFT by default)
2084
     *
2085
     * @return string
2086
     */
2087
    public function getPaddedUnit($unit, $length = 2, $padString = '0', $padType = STR_PAD_LEFT)
2088
    {
2089
        return ($this->$unit < 0 ? '-' : '').str_pad((string) abs($this->$unit), $length, $padString, $padType);
2090
    }
2091
 
2092
    /**
2093
     * Return a property with its ordinal.
2094
     *
2095
     * @param string      $key
2096
     * @param string|null $period
2097
     *
2098
     * @return string
2099
     */
2100
    public function ordinal(string $key, ?string $period = null): string
2101
    {
2102
        $number = $this->$key;
2103
        $result = $this->translate('ordinal', [
2104
            ':number' => $number,
2105
            ':period' => (string) $period,
2106
        ]);
2107
 
2108
        return (string) ($result === 'ordinal' ? $number : $result);
2109
    }
2110
 
2111
    /**
2112
     * Return the meridiem of the current time in the current locale.
2113
     *
2114
     * @param bool $isLower if true, returns lowercase variant if available in the current locale.
2115
     *
2116
     * @return string
2117
     */
2118
    public function meridiem(bool $isLower = false): string
2119
    {
2120
        $hour = $this->hour;
2121
        $index = $hour < 12 ? 0 : 1;
2122
 
2123
        if ($isLower) {
2124
            $key = 'meridiem.'.($index + 2);
2125
            $result = $this->translate($key);
2126
 
2127
            if ($result !== $key) {
2128
                return $result;
2129
            }
2130
        }
2131
 
2132
        $key = "meridiem.$index";
2133
        $result = $this->translate($key);
2134
        if ($result === $key) {
2135
            $result = $this->translate('meridiem', [
2136
                ':hour' => $this->hour,
2137
                ':minute' => $this->minute,
2138
                ':isLower' => $isLower,
2139
            ]);
2140
 
2141
            if ($result === 'meridiem') {
2142
                return $isLower ? $this->latinMeridiem : $this->latinUpperMeridiem;
2143
            }
2144
        } elseif ($isLower) {
2145
            $result = mb_strtolower($result);
2146
        }
2147
 
2148
        return $result;
2149
    }
2150
 
2151
    /**
2152
     * Returns the alternative number for a given date property if available in the current locale.
2153
     *
2154
     * @param string $key date property
2155
     *
2156
     * @return string
2157
     */
2158
    public function getAltNumber(string $key): string
2159
    {
2160
        return $this->translateNumber(\strlen($key) > 1 ? $this->$key : $this->rawFormat('h'));
2161
    }
2162
 
2163
    /**
2164
     * Format in the current language using ISO replacement patterns.
2165
     *
2166
     * @param string      $format
2167
     * @param string|null $originalFormat provide context if a chunk has been passed alone
2168
     *
2169
     * @return string
2170
     */
2171
    public function isoFormat(string $format, ?string $originalFormat = null): string
2172
    {
2173
        $result = '';
2174
        $length = mb_strlen($format);
2175
        $originalFormat = $originalFormat ?: $format;
2176
        $inEscaped = false;
2177
        $formats = null;
2178
        $units = null;
2179
 
2180
        for ($i = 0; $i < $length; $i++) {
2181
            $char = mb_substr($format, $i, 1);
2182
 
2183
            if ($char === '\\') {
2184
                $result .= mb_substr($format, ++$i, 1);
2185
 
2186
                continue;
2187
            }
2188
 
2189
            if ($char === '[' && !$inEscaped) {
2190
                $inEscaped = true;
2191
 
2192
                continue;
2193
            }
2194
 
2195
            if ($char === ']' && $inEscaped) {
2196
                $inEscaped = false;
2197
 
2198
                continue;
2199
            }
2200
 
2201
            if ($inEscaped) {
2202
                $result .= $char;
2203
 
2204
                continue;
2205
            }
2206
 
2207
            $input = mb_substr($format, $i);
2208
 
2209
            if (preg_match('/^(LTS|LT|l{1,4}|L{1,4})/', $input, $match)) {
2210
                if ($formats === null) {
2211
                    $formats = $this->getIsoFormats();
2212
                }
2213
 
2214
                $code = $match[0];
2215
                $sequence = $formats[$code] ?? preg_replace_callback(
2216
                    '/MMMM|MM|DD|dddd/',
2217
                    function ($code) {
2218
                        return mb_substr($code[0], 1);
2219
                    },
2220
                    $formats[strtoupper($code)] ?? ''
2221
                );
2222
                $rest = mb_substr($format, $i + mb_strlen($code));
2223
                $format = mb_substr($format, 0, $i).$sequence.$rest;
2224
                $length = mb_strlen($format);
2225
                $input = $sequence.$rest;
2226
            }
2227
 
2228
            if (preg_match('/^'.CarbonInterface::ISO_FORMAT_REGEXP.'/', $input, $match)) {
2229
                $code = $match[0];
2230
 
2231
                if ($units === null) {
2232
                    $units = static::getIsoUnits();
2233
                }
2234
 
2235
                $sequence = $units[$code] ?? '';
2236
 
2237
                if ($sequence instanceof Closure) {
2238
                    $sequence = $sequence($this, $originalFormat);
2239
                } elseif (\is_array($sequence)) {
2240
                    try {
2241
                        $sequence = $this->{$sequence[0]}(...$sequence[1]);
2242
                    } catch (ReflectionException | InvalidArgumentException | BadMethodCallException $e) {
2243
                        $sequence = '';
2244
                    }
2245
                } elseif (\is_string($sequence)) {
2246
                    $sequence = $this->$sequence ?? $code;
2247
                }
2248
 
2249
                $format = mb_substr($format, 0, $i).$sequence.mb_substr($format, $i + mb_strlen($code));
2250
                $i += mb_strlen((string) $sequence) - 1;
2251
                $length = mb_strlen($format);
2252
                $char = $sequence;
2253
            }
2254
 
2255
            $result .= $char;
2256
        }
2257
 
2258
        return $result;
2259
    }
2260
 
2261
    /**
2262
     * List of replacements from date() format to isoFormat().
2263
     *
2264
     * @return array
2265
     */
2266
    public static function getFormatsToIsoReplacements()
2267
    {
2268
        static $replacements = null;
2269
 
2270
        if ($replacements === null) {
2271
            $replacements = [
2272
                'd' => true,
2273
                'D' => 'ddd',
2274
                'j' => true,
2275
                'l' => 'dddd',
2276
                'N' => true,
2277
                'S' => function ($date) {
2278
                    $day = $date->rawFormat('j');
2279
 
2280
                    return str_replace((string) $day, '', $date->isoFormat('Do'));
2281
                },
2282
                'w' => true,
2283
                'z' => true,
2284
                'W' => true,
2285
                'F' => 'MMMM',
2286
                'm' => true,
2287
                'M' => 'MMM',
2288
                'n' => true,
2289
                't' => true,
2290
                'L' => true,
2291
                'o' => true,
2292
                'Y' => true,
2293
                'y' => true,
2294
                'a' => 'a',
2295
                'A' => 'A',
2296
                'B' => true,
2297
                'g' => true,
2298
                'G' => true,
2299
                'h' => true,
2300
                'H' => true,
2301
                'i' => true,
2302
                's' => true,
2303
                'u' => true,
2304
                'v' => true,
2305
                'E' => true,
2306
                'I' => true,
2307
                'O' => true,
2308
                'P' => true,
2309
                'Z' => true,
2310
                'c' => true,
2311
                'r' => true,
2312
                'U' => true,
2313
            ];
2314
        }
2315
 
2316
        return $replacements;
2317
    }
2318
 
2319
    /**
2320
     * Format as ->format() do (using date replacements patterns from https://php.net/manual/en/function.date.php)
2321
     * but translate words whenever possible (months, day names, etc.) using the current locale.
2322
     *
2323
     * @param string $format
2324
     *
2325
     * @return string
2326
     */
2327
    public function translatedFormat(string $format): string
2328
    {
2329
        $replacements = static::getFormatsToIsoReplacements();
2330
        $context = '';
2331
        $isoFormat = '';
2332
        $length = mb_strlen($format);
2333
 
2334
        for ($i = 0; $i < $length; $i++) {
2335
            $char = mb_substr($format, $i, 1);
2336
 
2337
            if ($char === '\\') {
2338
                $replacement = mb_substr($format, $i, 2);
2339
                $isoFormat .= $replacement;
2340
                $i++;
2341
 
2342
                continue;
2343
            }
2344
 
2345
            if (!isset($replacements[$char])) {
2346
                $replacement = preg_match('/^[A-Za-z]$/', $char) ? "\\$char" : $char;
2347
                $isoFormat .= $replacement;
2348
                $context .= $replacement;
2349
 
2350
                continue;
2351
            }
2352
 
2353
            $replacement = $replacements[$char];
2354
 
2355
            if ($replacement === true) {
2356
                static $contextReplacements = null;
2357
 
2358
                if ($contextReplacements === null) {
2359
                    $contextReplacements = [
2360
                        'm' => 'MM',
2361
                        'd' => 'DD',
2362
                        't' => 'D',
2363
                        'j' => 'D',
2364
                        'N' => 'e',
2365
                        'w' => 'e',
2366
                        'n' => 'M',
2367
                        'o' => 'YYYY',
2368
                        'Y' => 'YYYY',
2369
                        'y' => 'YY',
2370
                        'g' => 'h',
2371
                        'G' => 'H',
2372
                        'h' => 'hh',
2373
                        'H' => 'HH',
2374
                        'i' => 'mm',
2375
                        's' => 'ss',
2376
                    ];
2377
                }
2378
 
2379
                $isoFormat .= '['.$this->rawFormat($char).']';
2380
                $context .= $contextReplacements[$char] ?? ' ';
2381
 
2382
                continue;
2383
            }
2384
 
2385
            if ($replacement instanceof Closure) {
2386
                $replacement = '['.$replacement($this).']';
2387
                $isoFormat .= $replacement;
2388
                $context .= $replacement;
2389
 
2390
                continue;
2391
            }
2392
 
2393
            $isoFormat .= $replacement;
2394
            $context .= $replacement;
2395
        }
2396
 
2397
        return $this->isoFormat($isoFormat, $context);
2398
    }
2399
 
2400
    /**
2401
     * Returns the offset hour and minute formatted with +/- and a given separator (":" by default).
2402
     * For example, if the time zone is 9 hours 30 minutes, you'll get "+09:30", with "@@" as first
2403
     * argument, "+09@@30", with "" as first argument, "+0930". Negative offset will return something
2404
     * like "-12:00".
2405
     *
2406
     * @param string $separator string to place between hours and minutes (":" by default)
2407
     *
2408
     * @return string
2409
     */
2410
    public function getOffsetString($separator = ':')
2411
    {
2412
        $second = $this->getOffset();
2413
        $symbol = $second < 0 ? '-' : '+';
2414
        $minute = abs($second) / static::SECONDS_PER_MINUTE;
2415
        $hour = str_pad((string) floor($minute / static::MINUTES_PER_HOUR), 2, '0', STR_PAD_LEFT);
2416
        $minute = str_pad((string) (((int) $minute) % static::MINUTES_PER_HOUR), 2, '0', STR_PAD_LEFT);
2417
 
2418
        return "$symbol$hour$separator$minute";
2419
    }
2420
 
2421
    protected static function executeStaticCallable($macro, ...$parameters)
2422
    {
2423
        return static::bindMacroContext(null, function () use (&$macro, &$parameters) {
2424
            if ($macro instanceof Closure) {
2425
                $boundMacro = @Closure::bind($macro, null, static::class);
2426
 
2427
                return ($boundMacro ?: $macro)(...$parameters);
2428
            }
2429
 
2430
            return $macro(...$parameters);
2431
        });
2432
    }
2433
 
2434
    /**
2435
     * Dynamically handle calls to the class.
2436
     *
2437
     * @param string $method     magic method name called
2438
     * @param array  $parameters parameters list
2439
     *
2440
     * @throws BadMethodCallException
2441
     *
2442
     * @return mixed
2443
     */
2444
    public static function __callStatic($method, $parameters)
2445
    {
2446
        if (!static::hasMacro($method)) {
2447
            foreach (static::getGenericMacros() as $callback) {
2448
                try {
2449
                    return static::executeStaticCallable($callback, $method, ...$parameters);
2450
                } catch (BadMethodCallException $exception) {
2451
                    continue;
2452
                }
2453
            }
2454
            if (static::isStrictModeEnabled()) {
2455
                throw new UnknownMethodException(sprintf('%s::%s', static::class, $method));
2456
            }
2457
 
2458
            return null;
2459
        }
2460
 
2461
        return static::executeStaticCallable(static::$globalMacros[$method], ...$parameters);
2462
    }
2463
 
2464
    /**
2465
     * Set specified unit to new given value.
2466
     *
2467
     * @param string $unit  year, month, day, hour, minute, second or microsecond
2468
     * @param int    $value new value for given unit
2469
     *
2470
     * @return static
2471
     */
2472
    public function setUnit($unit, $value = null)
2473
    {
2474
        $unit = static::singularUnit($unit);
2475
        $dateUnits = ['year', 'month', 'day'];
2476
        if (\in_array($unit, $dateUnits)) {
2477
            return $this->setDate(...array_map(function ($name) use ($unit, $value) {
2478
                return (int) ($name === $unit ? $value : $this->$name);
2479
            }, $dateUnits));
2480
        }
2481
 
2482
        $units = ['hour', 'minute', 'second', 'micro'];
2483
        if ($unit === 'millisecond' || $unit === 'milli') {
2484
            $value *= 1000;
2485
            $unit = 'micro';
2486
        } elseif ($unit === 'microsecond') {
2487
            $unit = 'micro';
2488
        }
2489
 
2490
        return $this->setTime(...array_map(function ($name) use ($unit, $value) {
2491
            return (int) ($name === $unit ? $value : $this->$name);
2492
        }, $units));
2493
    }
2494
 
2495
    /**
2496
     * Returns standardized singular of a given singular/plural unit name (in English).
2497
     *
2498
     * @param string $unit
2499
     *
2500
     * @return string
2501
     */
2502
    public static function singularUnit(string $unit): string
2503
    {
2504
        $unit = rtrim(mb_strtolower($unit), 's');
2505
 
2506
        if ($unit === 'centurie') {
2507
            return 'century';
2508
        }
2509
 
2510
        if ($unit === 'millennia') {
2511
            return 'millennium';
2512
        }
2513
 
2514
        return $unit;
2515
    }
2516
 
2517
    /**
2518
     * Returns standardized plural of a given singular/plural unit name (in English).
2519
     *
2520
     * @param string $unit
2521
     *
2522
     * @return string
2523
     */
2524
    public static function pluralUnit(string $unit): string
2525
    {
2526
        $unit = rtrim(strtolower($unit), 's');
2527
 
2528
        if ($unit === 'century') {
2529
            return 'centuries';
2530
        }
2531
 
2532
        if ($unit === 'millennium' || $unit === 'millennia') {
2533
            return 'millennia';
2534
        }
2535
 
2536
        return "{$unit}s";
2537
    }
2538
 
2539
    protected function executeCallable($macro, ...$parameters)
2540
    {
2541
        if ($macro instanceof Closure) {
2542
            $boundMacro = @$macro->bindTo($this, static::class) ?: @$macro->bindTo(null, static::class);
2543
 
2544
            return ($boundMacro ?: $macro)(...$parameters);
2545
        }
2546
 
2547
        return $macro(...$parameters);
2548
    }
2549
 
2550
    protected function executeCallableWithContext($macro, ...$parameters)
2551
    {
2552
        return static::bindMacroContext($this, function () use (&$macro, &$parameters) {
2553
            return $this->executeCallable($macro, ...$parameters);
2554
        });
2555
    }
2556
 
2557
    protected static function getGenericMacros()
2558
    {
2559
        foreach (static::$globalGenericMacros as $list) {
2560
            foreach ($list as $macro) {
2561
                yield $macro;
2562
            }
2563
        }
2564
    }
2565
 
2566
    /**
2567
     * Dynamically handle calls to the class.
2568
     *
2569
     * @param string $method     magic method name called
2570
     * @param array  $parameters parameters list
2571
     *
2572
     * @throws UnknownMethodException|BadMethodCallException|ReflectionException|Throwable
2573
     *
2574
     * @return mixed
2575
     */
2576
    public function __call($method, $parameters)
2577
    {
2578
        $diffSizes = [
2579
            // @mode diffForHumans
2580
            'short' => true,
2581
            // @mode diffForHumans
2582
            'long' => false,
2583
        ];
2584
        $diffSyntaxModes = [
2585
            // @call diffForHumans
2586
            'Absolute' => CarbonInterface::DIFF_ABSOLUTE,
2587
            // @call diffForHumans
2588
            'Relative' => CarbonInterface::DIFF_RELATIVE_AUTO,
2589
            // @call diffForHumans
2590
            'RelativeToNow' => CarbonInterface::DIFF_RELATIVE_TO_NOW,
2591
            // @call diffForHumans
2592
            'RelativeToOther' => CarbonInterface::DIFF_RELATIVE_TO_OTHER,
2593
        ];
2594
        $sizePattern = implode('|', array_keys($diffSizes));
2595
        $syntaxPattern = implode('|', array_keys($diffSyntaxModes));
2596
 
2597
        if (preg_match("/^(?<size>$sizePattern)(?<syntax>$syntaxPattern)DiffForHumans$/", $method, $match)) {
2598
            $dates = array_filter($parameters, function ($parameter) {
2599
                return $parameter instanceof DateTimeInterface;
2600
            });
2601
            $other = null;
2602
 
2603
            if (\count($dates)) {
2604
                $key = key($dates);
2605
                $other = current($dates);
2606
                array_splice($parameters, $key, 1);
2607
            }
2608
 
2609
            return $this->diffForHumans($other, $diffSyntaxModes[$match['syntax']], $diffSizes[$match['size']], ...$parameters);
2610
        }
2611
 
2612
        $roundedValue = $this->callRoundMethod($method, $parameters);
2613
 
2614
        if ($roundedValue !== null) {
2615
            return $roundedValue;
2616
        }
2617
 
2618
        $unit = rtrim($method, 's');
2619
 
2620
        if (str_starts_with($unit, 'is')) {
2621
            $word = substr($unit, 2);
2622
 
2623
            if (\in_array($word, static::$days, true)) {
2624
                return $this->isDayOfWeek($word);
2625
            }
2626
 
2627
            switch ($word) {
2628
                // @call is Check if the current instance has UTC timezone. (Both isUtc and isUTC cases are valid.)
2629
                case 'Utc':
2630
                case 'UTC':
2631
                    return $this->utc;
2632
                // @call is Check if the current instance has non-UTC timezone.
2633
                case 'Local':
2634
                    return $this->local;
2635
                // @call is Check if the current instance is a valid date.
2636
                case 'Valid':
2637
                    return $this->year !== 0;
2638
                // @call is Check if the current instance is in a daylight saving time.
2639
                case 'DST':
2640
                    return $this->dst;
2641
            }
2642
        }
2643
 
2644
        $action = substr($unit, 0, 3);
2645
        $overflow = null;
2646
 
2647
        if ($action === 'set') {
2648
            $unit = strtolower(substr($unit, 3));
2649
        }
2650
 
2651
        if (\in_array($unit, static::$units, true)) {
2652
            return $this->setUnit($unit, ...$parameters);
2653
        }
2654
 
2655
        if ($action === 'add' || $action === 'sub') {
2656
            $unit = substr($unit, 3);
2657
 
2658
            if (str_starts_with($unit, 'Real')) {
2659
                $unit = static::singularUnit(substr($unit, 4));
2660
 
2661
                return $this->{"{$action}RealUnit"}($unit, ...$parameters);
2662
            }
2663
 
2664
            if (preg_match('/^(Month|Quarter|Year|Decade|Century|Centurie|Millennium|Millennia)s?(No|With|Without|WithNo)Overflow$/', $unit, $match)) {
2665
                $unit = $match[1];
2666
                $overflow = $match[2] === 'With';
2667
            }
2668
 
2669
            $unit = static::singularUnit($unit);
2670
        }
2671
 
2672
        if (static::isModifiableUnit($unit)) {
2673
            return $this->{"{$action}Unit"}($unit, $this->getMagicParameter($parameters, 0, 'value', 1), $overflow);
2674
        }
2675
 
2676
        $sixFirstLetters = substr($unit, 0, 6);
2677
        $factor = -1;
2678
 
2679
        if ($sixFirstLetters === 'isLast') {
2680
            $sixFirstLetters = 'isNext';
2681
            $factor = 1;
2682
        }
2683
 
2684
        if ($sixFirstLetters === 'isNext') {
2685
            $lowerUnit = strtolower(substr($unit, 6));
2686
 
2687
            if (static::isModifiableUnit($lowerUnit)) {
2688
                return $this->copy()->addUnit($lowerUnit, $factor, false)->isSameUnit($lowerUnit, ...$parameters);
2689
            }
2690
        }
2691
 
2692
        if ($sixFirstLetters === 'isSame') {
2693
            try {
2694
                return $this->isSameUnit(strtolower(substr($unit, 6)), ...$parameters);
2695
            } catch (BadComparisonUnitException $exception) {
2696
                // Try next
2697
            }
2698
        }
2699
 
2700
        if (str_starts_with($unit, 'isCurrent')) {
2701
            try {
2702
                return $this->isCurrentUnit(strtolower(substr($unit, 9)));
2703
            } catch (BadComparisonUnitException | BadMethodCallException $exception) {
2704
                // Try next
2705
            }
2706
        }
2707
 
2708
        if (str_ends_with($method, 'Until')) {
2709
            try {
2710
                $unit = static::singularUnit(substr($method, 0, -5));
2711
 
2712
                return $this->range(
2713
                    $this->getMagicParameter($parameters, 0, 'endDate', $this),
2714
                    $this->getMagicParameter($parameters, 1, 'factor', 1),
2715
                    $unit
2716
                );
2717
            } catch (InvalidArgumentException $exception) {
2718
                // Try macros
2719
            }
2720
        }
2721
 
2722
        return static::bindMacroContext($this, function () use (&$method, &$parameters) {
2723
            $macro = $this->getLocalMacro($method);
2724
 
2725
            if (!$macro) {
2726
                foreach ([$this->localGenericMacros ?: [], static::getGenericMacros()] as $list) {
2727
                    foreach ($list as $callback) {
2728
                        try {
2729
                            return $this->executeCallable($callback, $method, ...$parameters);
2730
                        } catch (BadMethodCallException $exception) {
2731
                            continue;
2732
                        }
2733
                    }
2734
                }
2735
 
2736
                if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) {
2737
                    throw new UnknownMethodException($method);
2738
                }
2739
 
2740
                return null;
2741
            }
2742
 
2743
            return $this->executeCallable($macro, ...$parameters);
2744
        });
2745
    }
2746
}