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
namespace Carbon\Traits;
12

13
use BadMethodCallException;
14
use Carbon\Carbon;
15
use Carbon\CarbonInterface;
16
use Carbon\CarbonPeriod;
17
use Carbon\CarbonTimeZone;
18
use Carbon\Exceptions\BadComparisonUnitException;
19
use Carbon\Exceptions\ImmutableException;
20
use Carbon\Exceptions\InvalidTimeZoneException;
21
use Carbon\Exceptions\InvalidTypeException;
22
use Carbon\Exceptions\UnknownGetterException;
23
use Carbon\Exceptions\UnknownMethodException;
24
use Carbon\Exceptions\UnknownSetterException;
25
use Carbon\Exceptions\UnknownUnitException;
26
use Closure;
27
use DateInterval;
28
use DatePeriod;
29
use DateTime;
30
use DateTimeInterface;
31
use DateTimeZone;
32
use InvalidArgumentException;
33
use ReflectionException;
34
use Throwable;
35

36
/**
37
 * A simple API extension for DateTime.
38
 *
39
 * <autodoc generated by `composer phpdoc`>
40
 *
41
 * @property      int              $year
42
 * @property      int              $yearIso
43
 * @property      int              $month
44
 * @property      int              $day
45
 * @property      int              $hour
46
 * @property      int              $minute
47
 * @property      int              $second
48
 * @property      int              $micro
49
 * @property      int              $microsecond
50
 * @property      int|float|string $timestamp                                                                         seconds since the Unix Epoch
51
 * @property      string           $englishDayOfWeek                                                                  the day of week in English
52
 * @property      string           $shortEnglishDayOfWeek                                                             the abbreviated day of week in English
53
 * @property      string           $englishMonth                                                                      the month in English
54
 * @property      string           $shortEnglishMonth                                                                 the abbreviated month in English
55
 * @property      string           $localeDayOfWeek                                                                   the day of week in current locale LC_TIME
56
 * @property      string           $shortLocaleDayOfWeek                                                              the abbreviated day of week in current locale LC_TIME
57
 * @property      string           $localeMonth                                                                       the month in current locale LC_TIME
58
 * @property      string           $shortLocaleMonth                                                                  the abbreviated month in current locale LC_TIME
59
 * @property      int              $milliseconds
60
 * @property      int              $millisecond
61
 * @property      int              $milli
62
 * @property      int              $week                                                                              1 through 53
63
 * @property      int              $isoWeek                                                                           1 through 53
64
 * @property      int              $weekYear                                                                          year according to week format
65
 * @property      int              $isoWeekYear                                                                       year according to ISO week format
66
 * @property      int              $dayOfYear                                                                         1 through 366
67
 * @property      int              $age                                                                               does a diffInYears() with default parameters
68
 * @property      int              $offset                                                                            the timezone offset in seconds from UTC
69
 * @property      int              $offsetMinutes                                                                     the timezone offset in minutes from UTC
70
 * @property      int              $offsetHours                                                                       the timezone offset in hours from UTC
71
 * @property      CarbonTimeZone   $timezone                                                                          the current timezone
72
 * @property      CarbonTimeZone   $tz                                                                                alias of $timezone
73
 * @property-read int              $dayOfWeek                                                                         0 (for Sunday) through 6 (for Saturday)
74
 * @property-read int              $dayOfWeekIso                                                                      1 (for Monday) through 7 (for Sunday)
75
 * @property-read int              $weekOfYear                                                                        ISO-8601 week number of year, weeks starting on Monday
76
 * @property-read int              $daysInMonth                                                                       number of days in the given month
77
 * @property-read string           $latinMeridiem                                                                     "am"/"pm" (Ante meridiem or Post meridiem latin lowercase mark)
78
 * @property-read string           $latinUpperMeridiem                                                                "AM"/"PM" (Ante meridiem or Post meridiem latin uppercase mark)
79
 * @property-read string           $timezoneAbbreviatedName                                                           the current timezone abbreviated name
80
 * @property-read string           $tzAbbrName                                                                        alias of $timezoneAbbreviatedName
81
 * @property-read string           $dayName                                                                           long name of weekday translated according to Carbon locale, in english if no translation available for current language
82
 * @property-read string           $shortDayName                                                                      short name of weekday translated according to Carbon locale, in english if no translation available for current language
83
 * @property-read string           $minDayName                                                                        very short name of weekday translated according to Carbon locale, in english if no translation available for current language
84
 * @property-read string           $monthName                                                                         long name of month translated according to Carbon locale, in english if no translation available for current language
85
 * @property-read string           $shortMonthName                                                                    short name of month translated according to Carbon locale, in english if no translation available for current language
86
 * @property-read string           $meridiem                                                                          lowercase meridiem mark translated according to Carbon locale, in latin if no translation available for current language
87
 * @property-read string           $upperMeridiem                                                                     uppercase meridiem mark translated according to Carbon locale, in latin if no translation available for current language
88
 * @property-read int              $noZeroHour                                                                        current hour from 1 to 24
89
 * @property-read int              $weeksInYear                                                                       51 through 53
90
 * @property-read int              $isoWeeksInYear                                                                    51 through 53
91
 * @property-read int              $weekOfMonth                                                                       1 through 5
92
 * @property-read int              $weekNumberInMonth                                                                 1 through 5
93
 * @property-read int              $firstWeekDay                                                                      0 through 6
94
 * @property-read int              $lastWeekDay                                                                       0 through 6
95
 * @property-read int              $daysInYear                                                                        365 or 366
96
 * @property-read int              $quarter                                                                           the quarter of this instance, 1 - 4
97
 * @property-read int              $decade                                                                            the decade of this instance
98
 * @property-read int              $century                                                                           the century of this instance
99
 * @property-read int              $millennium                                                                        the millennium of this instance
100
 * @property-read bool             $dst                                                                               daylight savings time indicator, true if DST, false otherwise
101
 * @property-read bool             $local                                                                             checks if the timezone is local, true if local, false otherwise
102
 * @property-read bool             $utc                                                                               checks if the timezone is UTC, true if UTC, false otherwise
103
 * @property-read string           $timezoneName                                                                      the current timezone name
104
 * @property-read string           $tzName                                                                            alias of $timezoneName
105
 * @property-read string           $locale                                                                            locale of the current instance
106
 *
107
 * @method        bool             isUtc()                                                                            Check if the current instance has UTC timezone. (Both isUtc and isUTC cases are valid.)
108
 * @method        bool             isLocal()                                                                          Check if the current instance has non-UTC timezone.
109
 * @method        bool             isValid()                                                                          Check if the current instance is a valid date.
110
 * @method        bool             isDST()                                                                            Check if the current instance is in a daylight saving time.
111
 * @method        bool             isSunday()                                                                         Checks if the instance day is sunday.
112
 * @method        bool             isMonday()                                                                         Checks if the instance day is monday.
113
 * @method        bool             isTuesday()                                                                        Checks if the instance day is tuesday.
114
 * @method        bool             isWednesday()                                                                      Checks if the instance day is wednesday.
115
 * @method        bool             isThursday()                                                                       Checks if the instance day is thursday.
116
 * @method        bool             isFriday()                                                                         Checks if the instance day is friday.
117
 * @method        bool             isSaturday()                                                                       Checks if the instance day is saturday.
118
 * @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).
119
 * @method        bool             isCurrentYear()                                                                    Checks if the instance is in the same year as the current moment.
120
 * @method        bool             isNextYear()                                                                       Checks if the instance is in the same year as the current moment next year.
121
 * @method        bool             isLastYear()                                                                       Checks if the instance is in the same year as the current moment last year.
122
 * @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).
123
 * @method        bool             isCurrentWeek()                                                                    Checks if the instance is in the same week as the current moment.
124
 * @method        bool             isNextWeek()                                                                       Checks if the instance is in the same week as the current moment next week.
125
 * @method        bool             isLastWeek()                                                                       Checks if the instance is in the same week as the current moment last week.
126
 * @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).
127
 * @method        bool             isCurrentDay()                                                                     Checks if the instance is in the same day as the current moment.
128
 * @method        bool             isNextDay()                                                                        Checks if the instance is in the same day as the current moment next day.
129
 * @method        bool             isLastDay()                                                                        Checks if the instance is in the same day as the current moment last day.
130
 * @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).
131
 * @method        bool             isCurrentHour()                                                                    Checks if the instance is in the same hour as the current moment.
132
 * @method        bool             isNextHour()                                                                       Checks if the instance is in the same hour as the current moment next hour.
133
 * @method        bool             isLastHour()                                                                       Checks if the instance is in the same hour as the current moment last hour.
134
 * @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).
135
 * @method        bool             isCurrentMinute()                                                                  Checks if the instance is in the same minute as the current moment.
136
 * @method        bool             isNextMinute()                                                                     Checks if the instance is in the same minute as the current moment next minute.
137
 * @method        bool             isLastMinute()                                                                     Checks if the instance is in the same minute as the current moment last minute.
138
 * @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).
139
 * @method        bool             isCurrentSecond()                                                                  Checks if the instance is in the same second as the current moment.
140
 * @method        bool             isNextSecond()                                                                     Checks if the instance is in the same second as the current moment next second.
141
 * @method        bool             isLastSecond()                                                                     Checks if the instance is in the same second as the current moment last second.
142
 * @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).
143
 * @method        bool             isCurrentMicro()                                                                   Checks if the instance is in the same microsecond as the current moment.
144
 * @method        bool             isNextMicro()                                                                      Checks if the instance is in the same microsecond as the current moment next microsecond.
145
 * @method        bool             isLastMicro()                                                                      Checks if the instance is in the same microsecond as the current moment last microsecond.
146
 * @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).
147
 * @method        bool             isCurrentMicrosecond()                                                             Checks if the instance is in the same microsecond as the current moment.
148
 * @method        bool             isNextMicrosecond()                                                                Checks if the instance is in the same microsecond as the current moment next microsecond.
149
 * @method        bool             isLastMicrosecond()                                                                Checks if the instance is in the same microsecond as the current moment last microsecond.
150
 * @method        bool             isCurrentMonth()                                                                   Checks if the instance is in the same month as the current moment.
151
 * @method        bool             isNextMonth()                                                                      Checks if the instance is in the same month as the current moment next month.
152
 * @method        bool             isLastMonth()                                                                      Checks if the instance is in the same month as the current moment last month.
153
 * @method        bool             isCurrentQuarter()                                                                 Checks if the instance is in the same quarter as the current moment.
154
 * @method        bool             isNextQuarter()                                                                    Checks if the instance is in the same quarter as the current moment next quarter.
155
 * @method        bool             isLastQuarter()                                                                    Checks if the instance is in the same quarter as the current moment last quarter.
156
 * @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).
157
 * @method        bool             isCurrentDecade()                                                                  Checks if the instance is in the same decade as the current moment.
158
 * @method        bool             isNextDecade()                                                                     Checks if the instance is in the same decade as the current moment next decade.
159
 * @method        bool             isLastDecade()                                                                     Checks if the instance is in the same decade as the current moment last decade.
160
 * @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).
161
 * @method        bool             isCurrentCentury()                                                                 Checks if the instance is in the same century as the current moment.
162
 * @method        bool             isNextCentury()                                                                    Checks if the instance is in the same century as the current moment next century.
163
 * @method        bool             isLastCentury()                                                                    Checks if the instance is in the same century as the current moment last century.
164
 * @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).
165
 * @method        bool             isCurrentMillennium()                                                              Checks if the instance is in the same millennium as the current moment.
166
 * @method        bool             isNextMillennium()                                                                 Checks if the instance is in the same millennium as the current moment next millennium.
167
 * @method        bool             isLastMillennium()                                                                 Checks if the instance is in the same millennium as the current moment last millennium.
168
 * @method        CarbonInterface  years(int $value)                                                                  Set current instance year to the given value.
169
 * @method        CarbonInterface  year(int $value)                                                                   Set current instance year to the given value.
170
 * @method        CarbonInterface  setYears(int $value)                                                               Set current instance year to the given value.
171
 * @method        CarbonInterface  setYear(int $value)                                                                Set current instance year to the given value.
172
 * @method        CarbonInterface  months(int $value)                                                                 Set current instance month to the given value.
173
 * @method        CarbonInterface  month(int $value)                                                                  Set current instance month to the given value.
174
 * @method        CarbonInterface  setMonths(int $value)                                                              Set current instance month to the given value.
175
 * @method        CarbonInterface  setMonth(int $value)                                                               Set current instance month to the given value.
176
 * @method        CarbonInterface  days(int $value)                                                                   Set current instance day to the given value.
177
 * @method        CarbonInterface  day(int $value)                                                                    Set current instance day to the given value.
178
 * @method        CarbonInterface  setDays(int $value)                                                                Set current instance day to the given value.
179
 * @method        CarbonInterface  setDay(int $value)                                                                 Set current instance day to the given value.
180
 * @method        CarbonInterface  hours(int $value)                                                                  Set current instance hour to the given value.
181
 * @method        CarbonInterface  hour(int $value)                                                                   Set current instance hour to the given value.
182
 * @method        CarbonInterface  setHours(int $value)                                                               Set current instance hour to the given value.
183
 * @method        CarbonInterface  setHour(int $value)                                                                Set current instance hour to the given value.
184
 * @method        CarbonInterface  minutes(int $value)                                                                Set current instance minute to the given value.
185
 * @method        CarbonInterface  minute(int $value)                                                                 Set current instance minute to the given value.
186
 * @method        CarbonInterface  setMinutes(int $value)                                                             Set current instance minute to the given value.
187
 * @method        CarbonInterface  setMinute(int $value)                                                              Set current instance minute to the given value.
188
 * @method        CarbonInterface  seconds(int $value)                                                                Set current instance second to the given value.
189
 * @method        CarbonInterface  second(int $value)                                                                 Set current instance second to the given value.
190
 * @method        CarbonInterface  setSeconds(int $value)                                                             Set current instance second to the given value.
191
 * @method        CarbonInterface  setSecond(int $value)                                                              Set current instance second to the given value.
192
 * @method        CarbonInterface  millis(int $value)                                                                 Set current instance millisecond to the given value.
193
 * @method        CarbonInterface  milli(int $value)                                                                  Set current instance millisecond to the given value.
194
 * @method        CarbonInterface  setMillis(int $value)                                                              Set current instance millisecond to the given value.
195
 * @method        CarbonInterface  setMilli(int $value)                                                               Set current instance millisecond to the given value.
196
 * @method        CarbonInterface  milliseconds(int $value)                                                           Set current instance millisecond to the given value.
197
 * @method        CarbonInterface  millisecond(int $value)                                                            Set current instance millisecond to the given value.
198
 * @method        CarbonInterface  setMilliseconds(int $value)                                                        Set current instance millisecond to the given value.
199
 * @method        CarbonInterface  setMillisecond(int $value)                                                         Set current instance millisecond to the given value.
200
 * @method        CarbonInterface  micros(int $value)                                                                 Set current instance microsecond to the given value.
201
 * @method        CarbonInterface  micro(int $value)                                                                  Set current instance microsecond to the given value.
202
 * @method        CarbonInterface  setMicros(int $value)                                                              Set current instance microsecond to the given value.
203
 * @method        CarbonInterface  setMicro(int $value)                                                               Set current instance microsecond to the given value.
204
 * @method        CarbonInterface  microseconds(int $value)                                                           Set current instance microsecond to the given value.
205
 * @method        CarbonInterface  microsecond(int $value)                                                            Set current instance microsecond to the given value.
206
 * @method        CarbonInterface  setMicroseconds(int $value)                                                        Set current instance microsecond to the given value.
207
 * @method        CarbonInterface  setMicrosecond(int $value)                                                         Set current instance microsecond to the given value.
208
 * @method        CarbonInterface  addYears(int $value = 1)                                                           Add years (the $value count passed in) to the instance (using date interval).
209
 * @method        CarbonInterface  addYear()                                                                          Add one year to the instance (using date interval).
210
 * @method        CarbonInterface  subYears(int $value = 1)                                                           Sub years (the $value count passed in) to the instance (using date interval).
211
 * @method        CarbonInterface  subYear()                                                                          Sub one year to the instance (using date interval).
212
 * @method        CarbonInterface  addYearsWithOverflow(int $value = 1)                                               Add years (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
213
 * @method        CarbonInterface  addYearWithOverflow()                                                              Add one year to the instance (using date interval) with overflow explicitly allowed.
214
 * @method        CarbonInterface  subYearsWithOverflow(int $value = 1)                                               Sub years (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
215
 * @method        CarbonInterface  subYearWithOverflow()                                                              Sub one year to the instance (using date interval) with overflow explicitly allowed.
216
 * @method        CarbonInterface  addYearsWithoutOverflow(int $value = 1)                                            Add years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
217
 * @method        CarbonInterface  addYearWithoutOverflow()                                                           Add one year to the instance (using date interval) with overflow explicitly forbidden.
218
 * @method        CarbonInterface  subYearsWithoutOverflow(int $value = 1)                                            Sub years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
219
 * @method        CarbonInterface  subYearWithoutOverflow()                                                           Sub one year to the instance (using date interval) with overflow explicitly forbidden.
220
 * @method        CarbonInterface  addYearsWithNoOverflow(int $value = 1)                                             Add years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
221
 * @method        CarbonInterface  addYearWithNoOverflow()                                                            Add one year to the instance (using date interval) with overflow explicitly forbidden.
222
 * @method        CarbonInterface  subYearsWithNoOverflow(int $value = 1)                                             Sub years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
223
 * @method        CarbonInterface  subYearWithNoOverflow()                                                            Sub one year to the instance (using date interval) with overflow explicitly forbidden.
224
 * @method        CarbonInterface  addYearsNoOverflow(int $value = 1)                                                 Add years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
225
 * @method        CarbonInterface  addYearNoOverflow()                                                                Add one year to the instance (using date interval) with overflow explicitly forbidden.
226
 * @method        CarbonInterface  subYearsNoOverflow(int $value = 1)                                                 Sub years (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
227
 * @method        CarbonInterface  subYearNoOverflow()                                                                Sub one year to the instance (using date interval) with overflow explicitly forbidden.
228
 * @method        CarbonInterface  addMonths(int $value = 1)                                                          Add months (the $value count passed in) to the instance (using date interval).
229
 * @method        CarbonInterface  addMonth()                                                                         Add one month to the instance (using date interval).
230
 * @method        CarbonInterface  subMonths(int $value = 1)                                                          Sub months (the $value count passed in) to the instance (using date interval).
231
 * @method        CarbonInterface  subMonth()                                                                         Sub one month to the instance (using date interval).
232
 * @method        CarbonInterface  addMonthsWithOverflow(int $value = 1)                                              Add months (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
233
 * @method        CarbonInterface  addMonthWithOverflow()                                                             Add one month to the instance (using date interval) with overflow explicitly allowed.
234
 * @method        CarbonInterface  subMonthsWithOverflow(int $value = 1)                                              Sub months (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
235
 * @method        CarbonInterface  subMonthWithOverflow()                                                             Sub one month to the instance (using date interval) with overflow explicitly allowed.
236
 * @method        CarbonInterface  addMonthsWithoutOverflow(int $value = 1)                                           Add months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
237
 * @method        CarbonInterface  addMonthWithoutOverflow()                                                          Add one month to the instance (using date interval) with overflow explicitly forbidden.
238
 * @method        CarbonInterface  subMonthsWithoutOverflow(int $value = 1)                                           Sub months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
239
 * @method        CarbonInterface  subMonthWithoutOverflow()                                                          Sub one month to the instance (using date interval) with overflow explicitly forbidden.
240
 * @method        CarbonInterface  addMonthsWithNoOverflow(int $value = 1)                                            Add months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
241
 * @method        CarbonInterface  addMonthWithNoOverflow()                                                           Add one month to the instance (using date interval) with overflow explicitly forbidden.
242
 * @method        CarbonInterface  subMonthsWithNoOverflow(int $value = 1)                                            Sub months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
243
 * @method        CarbonInterface  subMonthWithNoOverflow()                                                           Sub one month to the instance (using date interval) with overflow explicitly forbidden.
244
 * @method        CarbonInterface  addMonthsNoOverflow(int $value = 1)                                                Add months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
245
 * @method        CarbonInterface  addMonthNoOverflow()                                                               Add one month to the instance (using date interval) with overflow explicitly forbidden.
246
 * @method        CarbonInterface  subMonthsNoOverflow(int $value = 1)                                                Sub months (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
247
 * @method        CarbonInterface  subMonthNoOverflow()                                                               Sub one month to the instance (using date interval) with overflow explicitly forbidden.
248
 * @method        CarbonInterface  addDays(int $value = 1)                                                            Add days (the $value count passed in) to the instance (using date interval).
249
 * @method        CarbonInterface  addDay()                                                                           Add one day to the instance (using date interval).
250
 * @method        CarbonInterface  subDays(int $value = 1)                                                            Sub days (the $value count passed in) to the instance (using date interval).
251
 * @method        CarbonInterface  subDay()                                                                           Sub one day to the instance (using date interval).
252
 * @method        CarbonInterface  addHours(int $value = 1)                                                           Add hours (the $value count passed in) to the instance (using date interval).
253
 * @method        CarbonInterface  addHour()                                                                          Add one hour to the instance (using date interval).
254
 * @method        CarbonInterface  subHours(int $value = 1)                                                           Sub hours (the $value count passed in) to the instance (using date interval).
255
 * @method        CarbonInterface  subHour()                                                                          Sub one hour to the instance (using date interval).
256
 * @method        CarbonInterface  addMinutes(int $value = 1)                                                         Add minutes (the $value count passed in) to the instance (using date interval).
257
 * @method        CarbonInterface  addMinute()                                                                        Add one minute to the instance (using date interval).
258
 * @method        CarbonInterface  subMinutes(int $value = 1)                                                         Sub minutes (the $value count passed in) to the instance (using date interval).
259
 * @method        CarbonInterface  subMinute()                                                                        Sub one minute to the instance (using date interval).
260
 * @method        CarbonInterface  addSeconds(int $value = 1)                                                         Add seconds (the $value count passed in) to the instance (using date interval).
261
 * @method        CarbonInterface  addSecond()                                                                        Add one second to the instance (using date interval).
262
 * @method        CarbonInterface  subSeconds(int $value = 1)                                                         Sub seconds (the $value count passed in) to the instance (using date interval).
263
 * @method        CarbonInterface  subSecond()                                                                        Sub one second to the instance (using date interval).
264
 * @method        CarbonInterface  addMillis(int $value = 1)                                                          Add milliseconds (the $value count passed in) to the instance (using date interval).
265
 * @method        CarbonInterface  addMilli()                                                                         Add one millisecond to the instance (using date interval).
266
 * @method        CarbonInterface  subMillis(int $value = 1)                                                          Sub milliseconds (the $value count passed in) to the instance (using date interval).
267
 * @method        CarbonInterface  subMilli()                                                                         Sub one millisecond to the instance (using date interval).
268
 * @method        CarbonInterface  addMilliseconds(int $value = 1)                                                    Add milliseconds (the $value count passed in) to the instance (using date interval).
269
 * @method        CarbonInterface  addMillisecond()                                                                   Add one millisecond to the instance (using date interval).
270
 * @method        CarbonInterface  subMilliseconds(int $value = 1)                                                    Sub milliseconds (the $value count passed in) to the instance (using date interval).
271
 * @method        CarbonInterface  subMillisecond()                                                                   Sub one millisecond to the instance (using date interval).
272
 * @method        CarbonInterface  addMicros(int $value = 1)                                                          Add microseconds (the $value count passed in) to the instance (using date interval).
273
 * @method        CarbonInterface  addMicro()                                                                         Add one microsecond to the instance (using date interval).
274
 * @method        CarbonInterface  subMicros(int $value = 1)                                                          Sub microseconds (the $value count passed in) to the instance (using date interval).
275
 * @method        CarbonInterface  subMicro()                                                                         Sub one microsecond to the instance (using date interval).
276
 * @method        CarbonInterface  addMicroseconds(int $value = 1)                                                    Add microseconds (the $value count passed in) to the instance (using date interval).
277
 * @method        CarbonInterface  addMicrosecond()                                                                   Add one microsecond to the instance (using date interval).
278
 * @method        CarbonInterface  subMicroseconds(int $value = 1)                                                    Sub microseconds (the $value count passed in) to the instance (using date interval).
279
 * @method        CarbonInterface  subMicrosecond()                                                                   Sub one microsecond to the instance (using date interval).
280
 * @method        CarbonInterface  addMillennia(int $value = 1)                                                       Add millennia (the $value count passed in) to the instance (using date interval).
281
 * @method        CarbonInterface  addMillennium()                                                                    Add one millennium to the instance (using date interval).
282
 * @method        CarbonInterface  subMillennia(int $value = 1)                                                       Sub millennia (the $value count passed in) to the instance (using date interval).
283
 * @method        CarbonInterface  subMillennium()                                                                    Sub one millennium to the instance (using date interval).
284
 * @method        CarbonInterface  addMillenniaWithOverflow(int $value = 1)                                           Add millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
285
 * @method        CarbonInterface  addMillenniumWithOverflow()                                                        Add one millennium to the instance (using date interval) with overflow explicitly allowed.
286
 * @method        CarbonInterface  subMillenniaWithOverflow(int $value = 1)                                           Sub millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
287
 * @method        CarbonInterface  subMillenniumWithOverflow()                                                        Sub one millennium to the instance (using date interval) with overflow explicitly allowed.
288
 * @method        CarbonInterface  addMillenniaWithoutOverflow(int $value = 1)                                        Add millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
289
 * @method        CarbonInterface  addMillenniumWithoutOverflow()                                                     Add one millennium to the instance (using date interval) with overflow explicitly forbidden.
290
 * @method        CarbonInterface  subMillenniaWithoutOverflow(int $value = 1)                                        Sub millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
291
 * @method        CarbonInterface  subMillenniumWithoutOverflow()                                                     Sub one millennium to the instance (using date interval) with overflow explicitly forbidden.
292
 * @method        CarbonInterface  addMillenniaWithNoOverflow(int $value = 1)                                         Add millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
293
 * @method        CarbonInterface  addMillenniumWithNoOverflow()                                                      Add one millennium to the instance (using date interval) with overflow explicitly forbidden.
294
 * @method        CarbonInterface  subMillenniaWithNoOverflow(int $value = 1)                                         Sub millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
295
 * @method        CarbonInterface  subMillenniumWithNoOverflow()                                                      Sub one millennium to the instance (using date interval) with overflow explicitly forbidden.
296
 * @method        CarbonInterface  addMillenniaNoOverflow(int $value = 1)                                             Add millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
297
 * @method        CarbonInterface  addMillenniumNoOverflow()                                                          Add one millennium to the instance (using date interval) with overflow explicitly forbidden.
298
 * @method        CarbonInterface  subMillenniaNoOverflow(int $value = 1)                                             Sub millennia (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
299
 * @method        CarbonInterface  subMillenniumNoOverflow()                                                          Sub one millennium to the instance (using date interval) with overflow explicitly forbidden.
300
 * @method        CarbonInterface  addCenturies(int $value = 1)                                                       Add centuries (the $value count passed in) to the instance (using date interval).
301
 * @method        CarbonInterface  addCentury()                                                                       Add one century to the instance (using date interval).
302
 * @method        CarbonInterface  subCenturies(int $value = 1)                                                       Sub centuries (the $value count passed in) to the instance (using date interval).
303
 * @method        CarbonInterface  subCentury()                                                                       Sub one century to the instance (using date interval).
304
 * @method        CarbonInterface  addCenturiesWithOverflow(int $value = 1)                                           Add centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
305
 * @method        CarbonInterface  addCenturyWithOverflow()                                                           Add one century to the instance (using date interval) with overflow explicitly allowed.
306
 * @method        CarbonInterface  subCenturiesWithOverflow(int $value = 1)                                           Sub centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
307
 * @method        CarbonInterface  subCenturyWithOverflow()                                                           Sub one century to the instance (using date interval) with overflow explicitly allowed.
308
 * @method        CarbonInterface  addCenturiesWithoutOverflow(int $value = 1)                                        Add centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
309
 * @method        CarbonInterface  addCenturyWithoutOverflow()                                                        Add one century to the instance (using date interval) with overflow explicitly forbidden.
310
 * @method        CarbonInterface  subCenturiesWithoutOverflow(int $value = 1)                                        Sub centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
311
 * @method        CarbonInterface  subCenturyWithoutOverflow()                                                        Sub one century to the instance (using date interval) with overflow explicitly forbidden.
312
 * @method        CarbonInterface  addCenturiesWithNoOverflow(int $value = 1)                                         Add centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
313
 * @method        CarbonInterface  addCenturyWithNoOverflow()                                                         Add one century to the instance (using date interval) with overflow explicitly forbidden.
314
 * @method        CarbonInterface  subCenturiesWithNoOverflow(int $value = 1)                                         Sub centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
315
 * @method        CarbonInterface  subCenturyWithNoOverflow()                                                         Sub one century to the instance (using date interval) with overflow explicitly forbidden.
316
 * @method        CarbonInterface  addCenturiesNoOverflow(int $value = 1)                                             Add centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
317
 * @method        CarbonInterface  addCenturyNoOverflow()                                                             Add one century to the instance (using date interval) with overflow explicitly forbidden.
318
 * @method        CarbonInterface  subCenturiesNoOverflow(int $value = 1)                                             Sub centuries (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
319
 * @method        CarbonInterface  subCenturyNoOverflow()                                                             Sub one century to the instance (using date interval) with overflow explicitly forbidden.
320
 * @method        CarbonInterface  addDecades(int $value = 1)                                                         Add decades (the $value count passed in) to the instance (using date interval).
321
 * @method        CarbonInterface  addDecade()                                                                        Add one decade to the instance (using date interval).
322
 * @method        CarbonInterface  subDecades(int $value = 1)                                                         Sub decades (the $value count passed in) to the instance (using date interval).
323
 * @method        CarbonInterface  subDecade()                                                                        Sub one decade to the instance (using date interval).
324
 * @method        CarbonInterface  addDecadesWithOverflow(int $value = 1)                                             Add decades (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
325
 * @method        CarbonInterface  addDecadeWithOverflow()                                                            Add one decade to the instance (using date interval) with overflow explicitly allowed.
326
 * @method        CarbonInterface  subDecadesWithOverflow(int $value = 1)                                             Sub decades (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
327
 * @method        CarbonInterface  subDecadeWithOverflow()                                                            Sub one decade to the instance (using date interval) with overflow explicitly allowed.
328
 * @method        CarbonInterface  addDecadesWithoutOverflow(int $value = 1)                                          Add decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
329
 * @method        CarbonInterface  addDecadeWithoutOverflow()                                                         Add one decade to the instance (using date interval) with overflow explicitly forbidden.
330
 * @method        CarbonInterface  subDecadesWithoutOverflow(int $value = 1)                                          Sub decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
331
 * @method        CarbonInterface  subDecadeWithoutOverflow()                                                         Sub one decade to the instance (using date interval) with overflow explicitly forbidden.
332
 * @method        CarbonInterface  addDecadesWithNoOverflow(int $value = 1)                                           Add decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
333
 * @method        CarbonInterface  addDecadeWithNoOverflow()                                                          Add one decade to the instance (using date interval) with overflow explicitly forbidden.
334
 * @method        CarbonInterface  subDecadesWithNoOverflow(int $value = 1)                                           Sub decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
335
 * @method        CarbonInterface  subDecadeWithNoOverflow()                                                          Sub one decade to the instance (using date interval) with overflow explicitly forbidden.
336
 * @method        CarbonInterface  addDecadesNoOverflow(int $value = 1)                                               Add decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
337
 * @method        CarbonInterface  addDecadeNoOverflow()                                                              Add one decade to the instance (using date interval) with overflow explicitly forbidden.
338
 * @method        CarbonInterface  subDecadesNoOverflow(int $value = 1)                                               Sub decades (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
339
 * @method        CarbonInterface  subDecadeNoOverflow()                                                              Sub one decade to the instance (using date interval) with overflow explicitly forbidden.
340
 * @method        CarbonInterface  addQuarters(int $value = 1)                                                        Add quarters (the $value count passed in) to the instance (using date interval).
341
 * @method        CarbonInterface  addQuarter()                                                                       Add one quarter to the instance (using date interval).
342
 * @method        CarbonInterface  subQuarters(int $value = 1)                                                        Sub quarters (the $value count passed in) to the instance (using date interval).
343
 * @method        CarbonInterface  subQuarter()                                                                       Sub one quarter to the instance (using date interval).
344
 * @method        CarbonInterface  addQuartersWithOverflow(int $value = 1)                                            Add quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
345
 * @method        CarbonInterface  addQuarterWithOverflow()                                                           Add one quarter to the instance (using date interval) with overflow explicitly allowed.
346
 * @method        CarbonInterface  subQuartersWithOverflow(int $value = 1)                                            Sub quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly allowed.
347
 * @method        CarbonInterface  subQuarterWithOverflow()                                                           Sub one quarter to the instance (using date interval) with overflow explicitly allowed.
348
 * @method        CarbonInterface  addQuartersWithoutOverflow(int $value = 1)                                         Add quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
349
 * @method        CarbonInterface  addQuarterWithoutOverflow()                                                        Add one quarter to the instance (using date interval) with overflow explicitly forbidden.
350
 * @method        CarbonInterface  subQuartersWithoutOverflow(int $value = 1)                                         Sub quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
351
 * @method        CarbonInterface  subQuarterWithoutOverflow()                                                        Sub one quarter to the instance (using date interval) with overflow explicitly forbidden.
352
 * @method        CarbonInterface  addQuartersWithNoOverflow(int $value = 1)                                          Add quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
353
 * @method        CarbonInterface  addQuarterWithNoOverflow()                                                         Add one quarter to the instance (using date interval) with overflow explicitly forbidden.
354
 * @method        CarbonInterface  subQuartersWithNoOverflow(int $value = 1)                                          Sub quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
355
 * @method        CarbonInterface  subQuarterWithNoOverflow()                                                         Sub one quarter to the instance (using date interval) with overflow explicitly forbidden.
356
 * @method        CarbonInterface  addQuartersNoOverflow(int $value = 1)                                              Add quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
357
 * @method        CarbonInterface  addQuarterNoOverflow()                                                             Add one quarter to the instance (using date interval) with overflow explicitly forbidden.
358
 * @method        CarbonInterface  subQuartersNoOverflow(int $value = 1)                                              Sub quarters (the $value count passed in) to the instance (using date interval) with overflow explicitly forbidden.
359
 * @method        CarbonInterface  subQuarterNoOverflow()                                                             Sub one quarter to the instance (using date interval) with overflow explicitly forbidden.
360
 * @method        CarbonInterface  addWeeks(int $value = 1)                                                           Add weeks (the $value count passed in) to the instance (using date interval).
361
 * @method        CarbonInterface  addWeek()                                                                          Add one week to the instance (using date interval).
362
 * @method        CarbonInterface  subWeeks(int $value = 1)                                                           Sub weeks (the $value count passed in) to the instance (using date interval).
363
 * @method        CarbonInterface  subWeek()                                                                          Sub one week to the instance (using date interval).
364
 * @method        CarbonInterface  addWeekdays(int $value = 1)                                                        Add weekdays (the $value count passed in) to the instance (using date interval).
365
 * @method        CarbonInterface  addWeekday()                                                                       Add one weekday to the instance (using date interval).
366
 * @method        CarbonInterface  subWeekdays(int $value = 1)                                                        Sub weekdays (the $value count passed in) to the instance (using date interval).
367
 * @method        CarbonInterface  subWeekday()                                                                       Sub one weekday to the instance (using date interval).
368
 * @method        CarbonInterface  addRealMicros(int $value = 1)                                                      Add microseconds (the $value count passed in) to the instance (using timestamp).
369
 * @method        CarbonInterface  addRealMicro()                                                                     Add one microsecond to the instance (using timestamp).
370
 * @method        CarbonInterface  subRealMicros(int $value = 1)                                                      Sub microseconds (the $value count passed in) to the instance (using timestamp).
371
 * @method        CarbonInterface  subRealMicro()                                                                     Sub one microsecond to the instance (using timestamp).
372
 * @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.
373
 * @method        CarbonInterface  addRealMicroseconds(int $value = 1)                                                Add microseconds (the $value count passed in) to the instance (using timestamp).
374
 * @method        CarbonInterface  addRealMicrosecond()                                                               Add one microsecond to the instance (using timestamp).
375
 * @method        CarbonInterface  subRealMicroseconds(int $value = 1)                                                Sub microseconds (the $value count passed in) to the instance (using timestamp).
376
 * @method        CarbonInterface  subRealMicrosecond()                                                               Sub one microsecond to the instance (using timestamp).
377
 * @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.
378
 * @method        CarbonInterface  addRealMillis(int $value = 1)                                                      Add milliseconds (the $value count passed in) to the instance (using timestamp).
379
 * @method        CarbonInterface  addRealMilli()                                                                     Add one millisecond to the instance (using timestamp).
380
 * @method        CarbonInterface  subRealMillis(int $value = 1)                                                      Sub milliseconds (the $value count passed in) to the instance (using timestamp).
381
 * @method        CarbonInterface  subRealMilli()                                                                     Sub one millisecond to the instance (using timestamp).
382
 * @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.
383
 * @method        CarbonInterface  addRealMilliseconds(int $value = 1)                                                Add milliseconds (the $value count passed in) to the instance (using timestamp).
384
 * @method        CarbonInterface  addRealMillisecond()                                                               Add one millisecond to the instance (using timestamp).
385
 * @method        CarbonInterface  subRealMilliseconds(int $value = 1)                                                Sub milliseconds (the $value count passed in) to the instance (using timestamp).
386
 * @method        CarbonInterface  subRealMillisecond()                                                               Sub one millisecond to the instance (using timestamp).
387
 * @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.
388
 * @method        CarbonInterface  addRealSeconds(int $value = 1)                                                     Add seconds (the $value count passed in) to the instance (using timestamp).
389
 * @method        CarbonInterface  addRealSecond()                                                                    Add one second to the instance (using timestamp).
390
 * @method        CarbonInterface  subRealSeconds(int $value = 1)                                                     Sub seconds (the $value count passed in) to the instance (using timestamp).
391
 * @method        CarbonInterface  subRealSecond()                                                                    Sub one second to the instance (using timestamp).
392
 * @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.
393
 * @method        CarbonInterface  addRealMinutes(int $value = 1)                                                     Add minutes (the $value count passed in) to the instance (using timestamp).
394
 * @method        CarbonInterface  addRealMinute()                                                                    Add one minute to the instance (using timestamp).
395
 * @method        CarbonInterface  subRealMinutes(int $value = 1)                                                     Sub minutes (the $value count passed in) to the instance (using timestamp).
396
 * @method        CarbonInterface  subRealMinute()                                                                    Sub one minute to the instance (using timestamp).
397
 * @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.
398
 * @method        CarbonInterface  addRealHours(int $value = 1)                                                       Add hours (the $value count passed in) to the instance (using timestamp).
399
 * @method        CarbonInterface  addRealHour()                                                                      Add one hour to the instance (using timestamp).
400
 * @method        CarbonInterface  subRealHours(int $value = 1)                                                       Sub hours (the $value count passed in) to the instance (using timestamp).
401
 * @method        CarbonInterface  subRealHour()                                                                      Sub one hour to the instance (using timestamp).
402
 * @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.
403
 * @method        CarbonInterface  addRealDays(int $value = 1)                                                        Add days (the $value count passed in) to the instance (using timestamp).
404
 * @method        CarbonInterface  addRealDay()                                                                       Add one day to the instance (using timestamp).
405
 * @method        CarbonInterface  subRealDays(int $value = 1)                                                        Sub days (the $value count passed in) to the instance (using timestamp).
406
 * @method        CarbonInterface  subRealDay()                                                                       Sub one day to the instance (using timestamp).
407
 * @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.
408
 * @method        CarbonInterface  addRealWeeks(int $value = 1)                                                       Add weeks (the $value count passed in) to the instance (using timestamp).
409
 * @method        CarbonInterface  addRealWeek()                                                                      Add one week to the instance (using timestamp).
410
 * @method        CarbonInterface  subRealWeeks(int $value = 1)                                                       Sub weeks (the $value count passed in) to the instance (using timestamp).
411
 * @method        CarbonInterface  subRealWeek()                                                                      Sub one week to the instance (using timestamp).
412
 * @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.
413
 * @method        CarbonInterface  addRealMonths(int $value = 1)                                                      Add months (the $value count passed in) to the instance (using timestamp).
414
 * @method        CarbonInterface  addRealMonth()                                                                     Add one month to the instance (using timestamp).
415
 * @method        CarbonInterface  subRealMonths(int $value = 1)                                                      Sub months (the $value count passed in) to the instance (using timestamp).
416
 * @method        CarbonInterface  subRealMonth()                                                                     Sub one month to the instance (using timestamp).
417
 * @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.
418
 * @method        CarbonInterface  addRealQuarters(int $value = 1)                                                    Add quarters (the $value count passed in) to the instance (using timestamp).
419
 * @method        CarbonInterface  addRealQuarter()                                                                   Add one quarter to the instance (using timestamp).
420
 * @method        CarbonInterface  subRealQuarters(int $value = 1)                                                    Sub quarters (the $value count passed in) to the instance (using timestamp).
421
 * @method        CarbonInterface  subRealQuarter()                                                                   Sub one quarter to the instance (using timestamp).
422
 * @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.
423
 * @method        CarbonInterface  addRealYears(int $value = 1)                                                       Add years (the $value count passed in) to the instance (using timestamp).
424
 * @method        CarbonInterface  addRealYear()                                                                      Add one year to the instance (using timestamp).
425
 * @method        CarbonInterface  subRealYears(int $value = 1)                                                       Sub years (the $value count passed in) to the instance (using timestamp).
426
 * @method        CarbonInterface  subRealYear()                                                                      Sub one year to the instance (using timestamp).
427
 * @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.
428
 * @method        CarbonInterface  addRealDecades(int $value = 1)                                                     Add decades (the $value count passed in) to the instance (using timestamp).
429
 * @method        CarbonInterface  addRealDecade()                                                                    Add one decade to the instance (using timestamp).
430
 * @method        CarbonInterface  subRealDecades(int $value = 1)                                                     Sub decades (the $value count passed in) to the instance (using timestamp).
431
 * @method        CarbonInterface  subRealDecade()                                                                    Sub one decade to the instance (using timestamp).
432
 * @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.
433
 * @method        CarbonInterface  addRealCenturies(int $value = 1)                                                   Add centuries (the $value count passed in) to the instance (using timestamp).
434
 * @method        CarbonInterface  addRealCentury()                                                                   Add one century to the instance (using timestamp).
435
 * @method        CarbonInterface  subRealCenturies(int $value = 1)                                                   Sub centuries (the $value count passed in) to the instance (using timestamp).
436
 * @method        CarbonInterface  subRealCentury()                                                                   Sub one century to the instance (using timestamp).
437
 * @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.
438
 * @method        CarbonInterface  addRealMillennia(int $value = 1)                                                   Add millennia (the $value count passed in) to the instance (using timestamp).
439
 * @method        CarbonInterface  addRealMillennium()                                                                Add one millennium to the instance (using timestamp).
440
 * @method        CarbonInterface  subRealMillennia(int $value = 1)                                                   Sub millennia (the $value count passed in) to the instance (using timestamp).
441
 * @method        CarbonInterface  subRealMillennium()                                                                Sub one millennium to the instance (using timestamp).
442
 * @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.
443
 * @method        CarbonInterface  roundYear(float $precision = 1, string $function = "round")                        Round the current instance year with given precision using the given function.
444
 * @method        CarbonInterface  roundYears(float $precision = 1, string $function = "round")                       Round the current instance year with given precision using the given function.
445
 * @method        CarbonInterface  floorYear(float $precision = 1)                                                    Truncate the current instance year with given precision.
446
 * @method        CarbonInterface  floorYears(float $precision = 1)                                                   Truncate the current instance year with given precision.
447
 * @method        CarbonInterface  ceilYear(float $precision = 1)                                                     Ceil the current instance year with given precision.
448
 * @method        CarbonInterface  ceilYears(float $precision = 1)                                                    Ceil the current instance year with given precision.
449
 * @method        CarbonInterface  roundMonth(float $precision = 1, string $function = "round")                       Round the current instance month with given precision using the given function.
450
 * @method        CarbonInterface  roundMonths(float $precision = 1, string $function = "round")                      Round the current instance month with given precision using the given function.
451
 * @method        CarbonInterface  floorMonth(float $precision = 1)                                                   Truncate the current instance month with given precision.
452
 * @method        CarbonInterface  floorMonths(float $precision = 1)                                                  Truncate the current instance month with given precision.
453
 * @method        CarbonInterface  ceilMonth(float $precision = 1)                                                    Ceil the current instance month with given precision.
454
 * @method        CarbonInterface  ceilMonths(float $precision = 1)                                                   Ceil the current instance month with given precision.
455
 * @method        CarbonInterface  roundDay(float $precision = 1, string $function = "round")                         Round the current instance day with given precision using the given function.
456
 * @method        CarbonInterface  roundDays(float $precision = 1, string $function = "round")                        Round the current instance day with given precision using the given function.
457
 * @method        CarbonInterface  floorDay(float $precision = 1)                                                     Truncate the current instance day with given precision.
458
 * @method        CarbonInterface  floorDays(float $precision = 1)                                                    Truncate the current instance day with given precision.
459
 * @method        CarbonInterface  ceilDay(float $precision = 1)                                                      Ceil the current instance day with given precision.
460
 * @method        CarbonInterface  ceilDays(float $precision = 1)                                                     Ceil the current instance day with given precision.
461
 * @method        CarbonInterface  roundHour(float $precision = 1, string $function = "round")                        Round the current instance hour with given precision using the given function.
462
 * @method        CarbonInterface  roundHours(float $precision = 1, string $function = "round")                       Round the current instance hour with given precision using the given function.
463
 * @method        CarbonInterface  floorHour(float $precision = 1)                                                    Truncate the current instance hour with given precision.
464
 * @method        CarbonInterface  floorHours(float $precision = 1)                                                   Truncate the current instance hour with given precision.
465
 * @method        CarbonInterface  ceilHour(float $precision = 1)                                                     Ceil the current instance hour with given precision.
466
 * @method        CarbonInterface  ceilHours(float $precision = 1)                                                    Ceil the current instance hour with given precision.
467
 * @method        CarbonInterface  roundMinute(float $precision = 1, string $function = "round")                      Round the current instance minute with given precision using the given function.
468
 * @method        CarbonInterface  roundMinutes(float $precision = 1, string $function = "round")                     Round the current instance minute with given precision using the given function.
469
 * @method        CarbonInterface  floorMinute(float $precision = 1)                                                  Truncate the current instance minute with given precision.
470
 * @method        CarbonInterface  floorMinutes(float $precision = 1)                                                 Truncate the current instance minute with given precision.
471
 * @method        CarbonInterface  ceilMinute(float $precision = 1)                                                   Ceil the current instance minute with given precision.
472
 * @method        CarbonInterface  ceilMinutes(float $precision = 1)                                                  Ceil the current instance minute with given precision.
473
 * @method        CarbonInterface  roundSecond(float $precision = 1, string $function = "round")                      Round the current instance second with given precision using the given function.
474
 * @method        CarbonInterface  roundSeconds(float $precision = 1, string $function = "round")                     Round the current instance second with given precision using the given function.
475
 * @method        CarbonInterface  floorSecond(float $precision = 1)                                                  Truncate the current instance second with given precision.
476
 * @method        CarbonInterface  floorSeconds(float $precision = 1)                                                 Truncate the current instance second with given precision.
477
 * @method        CarbonInterface  ceilSecond(float $precision = 1)                                                   Ceil the current instance second with given precision.
478
 * @method        CarbonInterface  ceilSeconds(float $precision = 1)                                                  Ceil the current instance second with given precision.
479
 * @method        CarbonInterface  roundMillennium(float $precision = 1, string $function = "round")                  Round the current instance millennium with given precision using the given function.
480
 * @method        CarbonInterface  roundMillennia(float $precision = 1, string $function = "round")                   Round the current instance millennium with given precision using the given function.
481
 * @method        CarbonInterface  floorMillennium(float $precision = 1)                                              Truncate the current instance millennium with given precision.
482
 * @method        CarbonInterface  floorMillennia(float $precision = 1)                                               Truncate the current instance millennium with given precision.
483
 * @method        CarbonInterface  ceilMillennium(float $precision = 1)                                               Ceil the current instance millennium with given precision.
484
 * @method        CarbonInterface  ceilMillennia(float $precision = 1)                                                Ceil the current instance millennium with given precision.
485
 * @method        CarbonInterface  roundCentury(float $precision = 1, string $function = "round")                     Round the current instance century with given precision using the given function.
486
 * @method        CarbonInterface  roundCenturies(float $precision = 1, string $function = "round")                   Round the current instance century with given precision using the given function.
487
 * @method        CarbonInterface  floorCentury(float $precision = 1)                                                 Truncate the current instance century with given precision.
488
 * @method        CarbonInterface  floorCenturies(float $precision = 1)                                               Truncate the current instance century with given precision.
489
 * @method        CarbonInterface  ceilCentury(float $precision = 1)                                                  Ceil the current instance century with given precision.
490
 * @method        CarbonInterface  ceilCenturies(float $precision = 1)                                                Ceil the current instance century with given precision.
491
 * @method        CarbonInterface  roundDecade(float $precision = 1, string $function = "round")                      Round the current instance decade with given precision using the given function.
492
 * @method        CarbonInterface  roundDecades(float $precision = 1, string $function = "round")                     Round the current instance decade with given precision using the given function.
493
 * @method        CarbonInterface  floorDecade(float $precision = 1)                                                  Truncate the current instance decade with given precision.
494
 * @method        CarbonInterface  floorDecades(float $precision = 1)                                                 Truncate the current instance decade with given precision.
495
 * @method        CarbonInterface  ceilDecade(float $precision = 1)                                                   Ceil the current instance decade with given precision.
496
 * @method        CarbonInterface  ceilDecades(float $precision = 1)                                                  Ceil the current instance decade with given precision.
497
 * @method        CarbonInterface  roundQuarter(float $precision = 1, string $function = "round")                     Round the current instance quarter with given precision using the given function.
498
 * @method        CarbonInterface  roundQuarters(float $precision = 1, string $function = "round")                    Round the current instance quarter with given precision using the given function.
499
 * @method        CarbonInterface  floorQuarter(float $precision = 1)                                                 Truncate the current instance quarter with given precision.
500
 * @method        CarbonInterface  floorQuarters(float $precision = 1)                                                Truncate the current instance quarter with given precision.
501
 * @method        CarbonInterface  ceilQuarter(float $precision = 1)                                                  Ceil the current instance quarter with given precision.
502
 * @method        CarbonInterface  ceilQuarters(float $precision = 1)                                                 Ceil the current instance quarter with given precision.
503
 * @method        CarbonInterface  roundMillisecond(float $precision = 1, string $function = "round")                 Round the current instance millisecond with given precision using the given function.
504
 * @method        CarbonInterface  roundMilliseconds(float $precision = 1, string $function = "round")                Round the current instance millisecond with given precision using the given function.
505
 * @method        CarbonInterface  floorMillisecond(float $precision = 1)                                             Truncate the current instance millisecond with given precision.
506
 * @method        CarbonInterface  floorMilliseconds(float $precision = 1)                                            Truncate the current instance millisecond with given precision.
507
 * @method        CarbonInterface  ceilMillisecond(float $precision = 1)                                              Ceil the current instance millisecond with given precision.
508
 * @method        CarbonInterface  ceilMilliseconds(float $precision = 1)                                             Ceil the current instance millisecond with given precision.
509
 * @method        CarbonInterface  roundMicrosecond(float $precision = 1, string $function = "round")                 Round the current instance microsecond with given precision using the given function.
510
 * @method        CarbonInterface  roundMicroseconds(float $precision = 1, string $function = "round")                Round the current instance microsecond with given precision using the given function.
511
 * @method        CarbonInterface  floorMicrosecond(float $precision = 1)                                             Truncate the current instance microsecond with given precision.
512
 * @method        CarbonInterface  floorMicroseconds(float $precision = 1)                                            Truncate the current instance microsecond with given precision.
513
 * @method        CarbonInterface  ceilMicrosecond(float $precision = 1)                                              Ceil the current instance microsecond with given precision.
514
 * @method        CarbonInterface  ceilMicroseconds(float $precision = 1)                                             Ceil the current instance microsecond with given precision.
515
 * @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.)
516
 * @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.)
517
 * @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.)
518
 * @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.)
519
 * @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.)
520
 * @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.)
521
 * @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.)
522
 * @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.)
523
 *
524
 * </autodoc>
525
 */
526
trait Date
527
{
528
    use Boundaries;
529
    use Comparison;
530
    use Converter;
531
    use Creator;
532
    use Difference;
533
    use Macro;
534
    use Modifiers;
535
    use Mutability;
536
    use ObjectInitialisation;
537
    use Options;
538
    use Rounding;
539
    use Serialization;
540
    use Test;
541
    use Timestamp;
542
    use Units;
543
    use Week;
544

545
    /**
546
     * Names of days of the week.
547
     *
548
     * @var array
549
     */
550
    protected static $days = [
551
        // @call isDayOfWeek
552
        CarbonInterface::SUNDAY => 'Sunday',
553
        // @call isDayOfWeek
554
        CarbonInterface::MONDAY => 'Monday',
555
        // @call isDayOfWeek
556
        CarbonInterface::TUESDAY => 'Tuesday',
557
        // @call isDayOfWeek
558
        CarbonInterface::WEDNESDAY => 'Wednesday',
559
        // @call isDayOfWeek
560
        CarbonInterface::THURSDAY => 'Thursday',
561
        // @call isDayOfWeek
562
        CarbonInterface::FRIDAY => 'Friday',
563
        // @call isDayOfWeek
564
        CarbonInterface::SATURDAY => 'Saturday',
565
    ];
566

567
    /**
568
     * Will UTF8 encoding be used to print localized date/time ?
569
     *
570
     * @var bool
571
     */
572
    protected static $utf8 = false;
573

574
    /**
575
     * List of unit and magic methods associated as doc-comments.
576
     *
577
     * @var array
578
     */
579
    protected static $units = [
580
        // @call setUnit
581
        // @call addUnit
582
        'year',
583
        // @call setUnit
584
        // @call addUnit
585
        'month',
586
        // @call setUnit
587
        // @call addUnit
588
        'day',
589
        // @call setUnit
590
        // @call addUnit
591
        'hour',
592
        // @call setUnit
593
        // @call addUnit
594
        'minute',
595
        // @call setUnit
596
        // @call addUnit
597
        'second',
598
        // @call setUnit
599
        // @call addUnit
600
        'milli',
601
        // @call setUnit
602
        // @call addUnit
603
        'millisecond',
604
        // @call setUnit
605
        // @call addUnit
606
        'micro',
607
        // @call setUnit
608
        // @call addUnit
609
        'microsecond',
610
    ];
611

612
    /**
613
     * Creates a DateTimeZone from a string, DateTimeZone or integer offset.
614
     *
615
     * @param DateTimeZone|string|int|null $object     original value to get CarbonTimeZone from it.
616
     * @param DateTimeZone|string|int|null $objectDump dump of the object for error messages.
617
     *
618
     * @throws InvalidTimeZoneException
619
     *
620
     * @return CarbonTimeZone|false
621
     */
622 1
    protected static function safeCreateDateTimeZone($object, $objectDump = null)
623
    {
624 1
        return CarbonTimeZone::instance($object, $objectDump);
625
    }
626

627
    /**
628
     * Get the TimeZone associated with the Carbon instance (as CarbonTimeZone).
629
     *
630
     * @return CarbonTimeZone
631
     *
632
     * @link http://php.net/manual/en/datetime.gettimezone.php
633
     */
634 1
    public function getTimezone()
635
    {
636 1
        return CarbonTimeZone::instance(parent::getTimezone());
637
    }
638

639
    /**
640
     * List of minimum and maximums for each unit.
641
     *
642
     * @return array
643
     */
644 1
    protected static function getRangesByUnit()
645
    {
646
        return [
647
            // @call roundUnit
648 1
            'year' => [1, 9999],
649
            // @call roundUnit
650 1
            'month' => [1, static::MONTHS_PER_YEAR],
651
            // @call roundUnit
652
            'day' => [1, 31],
653
            // @call roundUnit
654 1
            'hour' => [0, static::HOURS_PER_DAY - 1],
655
            // @call roundUnit
656 1
            'minute' => [0, static::MINUTES_PER_HOUR - 1],
657
            // @call roundUnit
658 1
            'second' => [0, static::SECONDS_PER_MINUTE - 1],
659
        ];
660
    }
661

662
    /**
663
     * Get a copy of the instance.
664
     *
665
     * @return static
666
     */
667 1
    public function copy()
668
    {
669 1
        return clone $this;
670
    }
671

672
    /**
673
     * @alias copy
674
     *
675
     * Get a copy of the instance.
676
     *
677
     * @return static
678
     */
679 1
    public function clone()
680
    {
681 1
        return clone $this;
682
    }
683

684
    /**
685
     * Returns a present instance in the same timezone.
686
     *
687
     * @return static
688
     */
689 1
    public function nowWithSameTz()
690
    {
691 1
        return static::now($this->getTimezone());
692
    }
693

694
    /**
695
     * Throws an exception if the given object is not a DateTime and does not implement DateTimeInterface.
696
     *
697
     * @param mixed        $date
698
     * @param string|array $other
699
     *
700
     * @throws InvalidTypeException
701
     */
702 1
    protected static function expectDateTime($date, $other = [])
703
    {
704 1
        $message = 'Expected ';
705 1
        foreach ((array) $other as $expect) {
706 1
            $message .= "$expect, ";
707
        }
708

709 1
        if (!$date instanceof DateTime && !$date instanceof DateTimeInterface) {
710 1
            throw new InvalidTypeException(
711 1
                $message.'DateTime or DateTimeInterface, '.
712 1
                (\is_object($date) ? \get_class($date) : \gettype($date)).' given'
713
            );
714
        }
715
    }
716

717
    /**
718
     * Return the Carbon instance passed through, a now instance in the same timezone
719
     * if null given or parse the input if string given.
720
     *
721
     * @param Carbon|DateTimeInterface|string|null $date
722
     *
723
     * @return static
724
     */
725 1
    protected function resolveCarbon($date = null)
726
    {
727 1
        if (!$date) {
728 1
            return $this->nowWithSameTz();
729
        }
730

731 1
        if (\is_string($date)) {
732 1
            return static::parse($date, $this->getTimezone());
733
        }
734

735 1
        static::expectDateTime($date, ['null', 'string']);
736

737 1
        return $date instanceof self ? $date : static::instance($date);
738
    }
739

740
    /**
741
     * Return the Carbon instance passed through, a now instance in the same timezone
742
     * if null given or parse the input if string given.
743
     *
744
     * @param Carbon|\Carbon\CarbonPeriod|\Carbon\CarbonInterval|\DateInterval|\DatePeriod|DateTimeInterface|string|null $date
745
     *
746
     * @return static
747
     */
748 1
    public function carbonize($date = null)
749
    {
750 1
        if ($date instanceof DateInterval) {
751 1
            return $this->copy()->add($date);
752
        }
753

754 1
        if ($date instanceof DatePeriod || $date instanceof CarbonPeriod) {
755 1
            $date = $date->getStartDate();
756
        }
757

758 1
        return $this->resolveCarbon($date);
759
    }
760

761
    ///////////////////////////////////////////////////////////////////
762
    ///////////////////////// GETTERS AND SETTERS /////////////////////
763
    ///////////////////////////////////////////////////////////////////
764

765
    /**
766
     * Get a part of the Carbon object
767
     *
768
     * @param string $name
769
     *
770
     * @throws UnknownGetterException
771
     *
772
     * @return string|int|bool|DateTimeZone|null
773
     */
774 1
    public function __get($name)
775
    {
776 1
        return $this->get($name);
777
    }
778

779
    /**
780
     * Get a part of the Carbon object
781
     *
782
     * @param string $name
783
     *
784
     * @throws UnknownGetterException
785
     *
786
     * @return string|int|bool|DateTimeZone|null
787
     */
788 1
    public function get($name)
789
    {
790 1
        static $formats = [
791
            // @property int
792
            'year' => 'Y',
793
            // @property int
794
            'yearIso' => 'o',
795
            // @property int
796
            // @call isSameUnit
797
            'month' => 'n',
798
            // @property int
799
            'day' => 'j',
800
            // @property int
801
            'hour' => 'G',
802
            // @property int
803
            'minute' => 'i',
804
            // @property int
805
            'second' => 's',
806
            // @property int
807
            'micro' => 'u',
808
            // @property int
809
            'microsecond' => 'u',
810
            // @property-read int 0 (for Sunday) through 6 (for Saturday)
811
            'dayOfWeek' => 'w',
812
            // @property-read int 1 (for Monday) through 7 (for Sunday)
813
            'dayOfWeekIso' => 'N',
814
            // @property-read int ISO-8601 week number of year, weeks starting on Monday
815
            'weekOfYear' => 'W',
816
            // @property-read int number of days in the given month
817
            'daysInMonth' => 't',
818
            // @property int|float|string seconds since the Unix Epoch
819
            'timestamp' => 'U',
820
            // @property-read string "am"/"pm" (Ante meridiem or Post meridiem latin lowercase mark)
821
            'latinMeridiem' => 'a',
822
            // @property-read string "AM"/"PM" (Ante meridiem or Post meridiem latin uppercase mark)
823
            'latinUpperMeridiem' => 'A',
824
            // @property string the day of week in English
825
            'englishDayOfWeek' => 'l',
826
            // @property string the abbreviated day of week in English
827
            'shortEnglishDayOfWeek' => 'D',
828
            // @property string the month in English
829
            'englishMonth' => 'F',
830
            // @property string the abbreviated month in English
831
            'shortEnglishMonth' => 'M',
832
            // @property string the day of week in current locale LC_TIME
833
            'localeDayOfWeek' => '%A',
834
            // @property string the abbreviated day of week in current locale LC_TIME
835
            'shortLocaleDayOfWeek' => '%a',
836
            // @property string the month in current locale LC_TIME
837
            'localeMonth' => '%B',
838
            // @property string the abbreviated month in current locale LC_TIME
839
            'shortLocaleMonth' => '%b',
840
            // @property-read string $timezoneAbbreviatedName the current timezone abbreviated name
841
            'timezoneAbbreviatedName' => 'T',
842
            // @property-read string $tzAbbrName alias of $timezoneAbbreviatedName
843
            'tzAbbrName' => 'T',
844
        ];
845

846
        switch (true) {
847 1
            case isset($formats[$name]):
848 1
                $format = $formats[$name];
849 1
                $method = substr($format, 0, 1) === '%' ? 'formatLocalized' : 'rawFormat';
850 1
                $value = $this->$method($format);
851

852 1
                return is_numeric($value) ? (int) $value : $value;
853

854
            // @property-read string long name of weekday translated according to Carbon locale, in english if no translation available for current language
855 1
            case $name === 'dayName':
856 1
                return $this->getTranslatedDayName();
857
            // @property-read string short name of weekday translated according to Carbon locale, in english if no translation available for current language
858 1
            case $name === 'shortDayName':
859 1
                return $this->getTranslatedShortDayName();
860
            // @property-read string very short name of weekday translated according to Carbon locale, in english if no translation available for current language
861 1
            case $name === 'minDayName':
862 1
                return $this->getTranslatedMinDayName();
863
            // @property-read string long name of month translated according to Carbon locale, in english if no translation available for current language
864 1
            case $name === 'monthName':
865 1
                return $this->getTranslatedMonthName();
866
            // @property-read string short name of month translated according to Carbon locale, in english if no translation available for current language
867 1
            case $name === 'shortMonthName':
868 1
                return $this->getTranslatedShortMonthName();
869
            // @property-read string lowercase meridiem mark translated according to Carbon locale, in latin if no translation available for current language
870 1
            case $name === 'meridiem':
871 1
                return $this->meridiem(true);
872
            // @property-read string uppercase meridiem mark translated according to Carbon locale, in latin if no translation available for current language
873 1
            case $name === 'upperMeridiem':
874 1
                return $this->meridiem();
875
            // @property-read int current hour from 1 to 24
876 1
            case $name === 'noZeroHour':
877 1
                return $this->hour ?: 24;
878
            // @property int
879 1
            case $name === 'milliseconds':
880
                // @property int
881 1
            case $name === 'millisecond':
882
            // @property int
883 1
            case $name === 'milli':
884 1
                return (int) floor($this->rawFormat('u') / 1000);
885

886
            // @property int 1 through 53
887 1
            case $name === 'week':
888 1
                return (int) $this->week();
889

890
            // @property int 1 through 53
891 1
            case $name === 'isoWeek':
892 1
                return (int) $this->isoWeek();
893

894
            // @property int year according to week format
895 1
            case $name === 'weekYear':
896 1
                return (int) $this->weekYear();
897

898
            // @property int year according to ISO week format
899 1
            case $name === 'isoWeekYear':
900 1
                return (int) $this->isoWeekYear();
901

902
            // @property-read int 51 through 53
903 1
            case $name === 'weeksInYear':
904 1
                return (int) $this->weeksInYear();
905

906
            // @property-read int 51 through 53
907 1
            case $name === 'isoWeeksInYear':
908 1
                return (int) $this->isoWeeksInYear();
909

910
            // @property-read int 1 through 5
911 1
            case $name === 'weekOfMonth':
912 1
                return (int) ceil($this->day / static::DAYS_PER_WEEK);
913

914
            // @property-read int 1 through 5
915 1
            case $name === 'weekNumberInMonth':
916 1
                return (int) ceil(($this->day + $this->copy()->startOfMonth()->dayOfWeekIso - 1) / static::DAYS_PER_WEEK);
917

918
            // @property-read int 0 through 6
919 1
            case $name === 'firstWeekDay':
920 1
                return $this->localTranslator ? ($this->getTranslationMessage('first_day_of_week') ?? 0) : static::getWeekStartsAt();
921

922
            // @property-read int 0 through 6
923 1
            case $name === 'lastWeekDay':
924 1
                return $this->localTranslator ? (($this->getTranslationMessage('first_day_of_week') ?? 0) + static::DAYS_PER_WEEK - 1) % static::DAYS_PER_WEEK : static::getWeekEndsAt();
925

926
            // @property int 1 through 366
927 1
            case $name === 'dayOfYear':
928 1
                return 1 + \intval($this->rawFormat('z'));
929

930
            // @property-read int 365 or 366
931 1
            case $name === 'daysInYear':
932 1
                return $this->isLeapYear() ? 366 : 365;
933

934
            // @property int does a diffInYears() with default parameters
935 1
            case $name === 'age':
936 1
                return $this->diffInYears();
937

938
            // @property-read int the quarter of this instance, 1 - 4
939
            // @call isSameUnit
940 1
            case $name === 'quarter':
941 1
                return (int) ceil($this->month / static::MONTHS_PER_QUARTER);
942

943
            // @property-read int the decade of this instance
944
            // @call isSameUnit
945 1
            case $name === 'decade':
946 1
                return (int) ceil($this->year / static::YEARS_PER_DECADE);
947

948
            // @property-read int the century of this instance
949
            // @call isSameUnit
950 1
            case $name === 'century':
951 1
                $factor = 1;
952 1
                $year = $this->year;
953 1
                if ($year < 0) {
954 1
                    $year = -$year;
955 1
                    $factor = -1;
956
                }
957

958 1
                return (int) ($factor * ceil($year / static::YEARS_PER_CENTURY));
959

960
            // @property-read int the millennium of this instance
961
            // @call isSameUnit
962 1
            case $name === 'millennium':
963 1
                $factor = 1;
964 1
                $year = $this->year;
965 1
                if ($year < 0) {
966 1
                    $year = -$year;
967 1
                    $factor = -1;
968
                }
969

970 1
                return (int) ($factor * ceil($year / static::YEARS_PER_MILLENNIUM));
971

972
            // @property int the timezone offset in seconds from UTC
973 1
            case $name === 'offset':
974 1
                return $this->getOffset();
975

976
            // @property int the timezone offset in minutes from UTC
977 1
            case $name === 'offsetMinutes':
978 1
                return $this->getOffset() / static::SECONDS_PER_MINUTE;
979

980
            // @property int the timezone offset in hours from UTC
981 1
            case $name === 'offsetHours':
982 1
                return $this->getOffset() / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR;
983

984
            // @property-read bool daylight savings time indicator, true if DST, false otherwise
985 1
            case $name === 'dst':
986 1
                return $this->rawFormat('I') === '1';
987

988
            // @property-read bool checks if the timezone is local, true if local, false otherwise
989 1
            case $name === 'local':
990 1
                return $this->getOffset() === $this->copy()->setTimezone(date_default_timezone_get())->getOffset();
991

992
            // @property-read bool checks if the timezone is UTC, true if UTC, false otherwise
993 1
            case $name === 'utc':
994 1
                return $this->getOffset() === 0;
995

996
            // @property CarbonTimeZone $timezone the current timezone
997
            // @property CarbonTimeZone $tz alias of $timezone
998 1
            case $name === 'timezone' || $name === 'tz':
999 1
                return CarbonTimeZone::instance($this->getTimezone());
1000

1001
            // @property-read string $timezoneName the current timezone name
1002
            // @property-read string $tzName alias of $timezoneName
1003 1
            case $name === 'timezoneName' || $name === 'tzName':
1004 1
                return $this->getTimezone()->getName();
1005

1006
            // @property-read string locale of the current instance
1007 1
            case $name === 'locale':
1008 1
                return $this->getTranslatorLocale();
1009

1010
            default:
1011 1
                $macro = $this->getLocalMacro('get'.ucfirst($name));
1012

1013 1
                if ($macro) {
1014 1
                    return $this->executeCallableWithContext($macro);
1015
                }
1016

1017 1
                throw new UnknownGetterException($name);
1018
        }
1019
    }
1020

1021
    /**
1022
     * Check if an attribute exists on the object
1023
     *
1024
     * @param string $name
1025
     *
1026
     * @return bool
1027
     */
1028 1
    public function __isset($name)
1029
    {
1030
        try {
1031 1
            $this->__get($name);
1032 1
        } catch (UnknownGetterException | ReflectionException $e) {
1033 1
            return false;
1034
        }
1035

1036 1
        return true;
1037
    }
1038

1039
    /**
1040
     * Set a part of the Carbon object
1041
     *
1042
     * @param string                  $name
1043
     * @param string|int|DateTimeZone $value
1044
     *
1045
     * @throws UnknownSetterException|ReflectionException
1046
     *
1047
     * @return void
1048
     */
1049 1
    public function __set($name, $value)
1050
    {
1051 1
        if ($this->constructedObjectId === spl_object_hash($this)) {
1052 1
            $this->set($name, $value);
1053

1054 1
            return;
1055
        }
1056

1057 1
        $this->$name = $value;
1058
    }
1059

1060
    /**
1061
     * Set a part of the Carbon object
1062
     *
1063
     * @param string|array            $name
1064
     * @param string|int|DateTimeZone $value
1065
     *
1066
     * @throws ImmutableException|UnknownSetterException
1067
     *
1068
     * @return $this
1069
     */
1070 1
    public function set($name, $value = null)
1071
    {
1072 1
        if ($this->isImmutable()) {
1073 1
            throw new ImmutableException(sprintf('%s class', static::class));
1074
        }
1075

1076 1
        if (\is_array($name)) {
1077 1
            foreach ($name as $key => $value) {
1078 1
                $this->set($key, $value);
1079
            }
1080

1081 1
            return $this;
1082
        }
1083

1084 1
        switch ($name) {
1085 1
            case 'milliseconds':
1086 1
            case 'millisecond':
1087 1
            case 'milli':
1088 1
            case 'microseconds':
1089 1
            case 'microsecond':
1090 1
            case 'micro':
1091 1
                if (substr($name, 0, 5) === 'milli') {
1092 1
                    $value *= 1000;
1093
                }
1094

1095 1
                while ($value < 0) {
1096 1
                    $this->subSecond();
1097 1
                    $value += static::MICROSECONDS_PER_SECOND;
1098
                }
1099

1100 1
                while ($value >= static::MICROSECONDS_PER_SECOND) {
1101 1
                    $this->addSecond();
1102 1
                    $value -= static::MICROSECONDS_PER_SECOND;
1103
                }
1104

1105 1
                $this->modify($this->rawFormat('H:i:s.').str_pad((string) round($value), 6, '0', STR_PAD_LEFT));
1106

1107 1
                break;
1108

1109 1
            case 'year':
1110 1
            case 'month':
1111 1
            case 'day':
1112 1
            case 'hour':
1113 1
            case 'minute':
1114 1
            case 'second':
1115 1
                [$year, $month, $day, $hour, $minute, $second] = array_map('intval', explode('-', $this->rawFormat('Y-n-j-G-i-s')));
1116 1
                $$name = $value;
1117 1
                $this->setDateTime($year, $month, $day, $hour, $minute, $second);
1118

1119 1
                break;
1120

1121 1
            case 'week':
1122 1
                $this->week($value);
1123

1124 1
                break;
1125

1126 1
            case 'isoWeek':
1127 1
                $this->isoWeek($value);
1128

1129 1
                break;
1130

1131 1
            case 'weekYear':
1132 1
                $this->weekYear($value);
1133

1134 1
                break;
1135

1136 1
            case 'isoWeekYear':
1137 1
                $this->isoWeekYear($value);
1138

1139 1
                break;
1140

1141 1
            case 'dayOfYear':
1142 1
                $this->addDays($value - $this->dayOfYear);
1143

1144 1
                break;
1145

1146 1
            case 'timestamp':
1147 1
                $this->setTimestamp($value);
1148

1149 1
                break;
1150

1151 1
            case 'offset':
1152 1
                $this->setTimezone(static::safeCreateDateTimeZone($value / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR));
1153

1154 1
                break;
1155

1156 1
            case 'offsetMinutes':
1157 1
                $this->setTimezone(static::safeCreateDateTimeZone($value / static::MINUTES_PER_HOUR));
1158

1159 1
                break;
1160

1161 1
            case 'offsetHours':
1162 1
                $this->setTimezone(static::safeCreateDateTimeZone($value));
1163

1164 1
                break;
1165

1166 1
            case 'timezone':
1167 1
            case 'tz':
1168 1
                $this->setTimezone($value);
1169

1170 1
                break;
1171

1172
            default:
1173 1
                $macro = $this->getLocalMacro('set'.ucfirst($name));
1174

1175 1
                if ($macro) {
1176 1
                    $this->executeCallableWithContext($macro, $value);
1177

1178 1
                    break;
1179
                }
1180

1181 1
                if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) {
1182 1
                    throw new UnknownSetterException($name);
1183
                }
1184

1185 1
                $this->$name = $value;
1186
        }
1187

1188 1
        return $this;
1189
    }
1190

1191 1
    protected function getTranslatedFormByRegExp($baseKey, $keySuffix, $context, $subKey, $defaultValue)
1192
    {
1193 1
        $key = $baseKey.$keySuffix;
1194 1
        $standaloneKey = "${key}_standalone";
1195 1
        $baseTranslation = $this->getTranslationMessage($key);
1196

1197 1
        if ($baseTranslation instanceof Closure) {
1198 1
            return $baseTranslation($this, $context, $subKey) ?: $defaultValue;
1199
        }
1200

1201
        if (
1202 1
            $this->getTranslationMessage("$standaloneKey.$subKey") &&
1203 1
            (!$context || ($regExp = $this->getTranslationMessage("${baseKey}_regexp")) && !preg_match($regExp, $context))
1204
        ) {
1205 1
            $key = $standaloneKey;
1206
        }
1207

1208 1
        return $this->getTranslationMessage("$key.$subKey", null, $defaultValue);
1209
    }
1210

1211
    /**
1212
     * Get the translation of the current week day name (with context for languages with multiple forms).
1213
     *
1214
     * @param string|null $context      whole format string
1215
     * @param string      $keySuffix    "", "_short" or "_min"
1216
     * @param string|null $defaultValue default value if translation missing
1217
     *
1218
     * @return string
1219
     */
1220 1
    public function getTranslatedDayName($context = null, $keySuffix = '', $defaultValue = null)
1221
    {
1222 1
        return $this->getTranslatedFormByRegExp('weekdays', $keySuffix, $context, $this->dayOfWeek, $defaultValue ?: $this->englishDayOfWeek);
1223
    }
1224

1225
    /**
1226
     * Get the translation of the current short week day name (with context for languages with multiple forms).
1227
     *
1228
     * @param string|null $context whole format string
1229
     *
1230
     * @return string
1231
     */
1232 1
    public function getTranslatedShortDayName($context = null)
1233
    {
1234 1
        return $this->getTranslatedDayName($context, '_short', $this->shortEnglishDayOfWeek);
1235
    }
1236

1237
    /**
1238
     * Get the translation of the current abbreviated week day name (with context for languages with multiple forms).
1239
     *
1240
     * @param string|null $context whole format string
1241
     *
1242
     * @return string
1243
     */
1244 1
    public function getTranslatedMinDayName($context = null)
1245
    {
1246 1
        return $this->getTranslatedDayName($context, '_min', $this->shortEnglishDayOfWeek);
1247
    }
1248

1249
    /**
1250
     * Get the translation of the current month day name (with context for languages with multiple forms).
1251
     *
1252
     * @param string|null $context      whole format string
1253
     * @param string      $keySuffix    "" or "_short"
1254
     * @param string|null $defaultValue default value if translation missing
1255
     *
1256
     * @return string
1257
     */
1258 1
    public function getTranslatedMonthName($context = null, $keySuffix = '', $defaultValue = null)
1259
    {
1260 1
        return $this->getTranslatedFormByRegExp('months', $keySuffix, $context, $this->month - 1, $defaultValue ?: $this->englishMonth);
1261
    }
1262

1263
    /**
1264
     * Get the translation of the current short month day name (with context for languages with multiple forms).
1265
     *
1266
     * @param string|null $context whole format string
1267
     *
1268
     * @return string
1269
     */
1270 1
    public function getTranslatedShortMonthName($context = null)
1271
    {
1272 1
        return $this->getTranslatedMonthName($context, '_short', $this->shortEnglishMonth);
1273
    }
1274

1275
    /**
1276
     * Get/set the day of year.
1277
     *
1278
     * @param int|null $value new value for day of year if using as setter.
1279
     *
1280
     * @return static|int
1281
     */
1282 1
    public function dayOfYear($value = null)
1283
    {
1284 1
        $dayOfYear = $this->dayOfYear;
1285

1286 1
        return \is_null($value) ? $dayOfYear : $this->addDays($value - $dayOfYear);
1287
    }
1288

1289
    /**
1290
     * Get/set the weekday from 0 (Sunday) to 6 (Saturday).
1291
     *
1292
     * @param int|null $value new value for weekday if using as setter.
1293
     *
1294
     * @return static|int
1295
     */
1296 1
    public function weekday($value = null)
1297
    {
1298 1
        $dayOfWeek = ($this->dayOfWeek + 7 - \intval($this->getTranslationMessage('first_day_of_week') ?? 0)) % 7;
1299

1300 1
        return \is_null($value) ? $dayOfWeek : $this->addDays($value - $dayOfWeek);
1301
    }
1302

1303
    /**
1304
     * Get/set the ISO weekday from 1 (Monday) to 7 (Sunday).
1305
     *
1306
     * @param int|null $value new value for weekday if using as setter.
1307
     *
1308
     * @return static|int
1309
     */
1310 1
    public function isoWeekday($value = null)
1311
    {
1312 1
        $dayOfWeekIso = $this->dayOfWeekIso;
1313

1314 1
        return \is_null($value) ? $dayOfWeekIso : $this->addDays($value - $dayOfWeekIso);
1315
    }
1316

1317
    /**
1318
     * Set any unit to a new value without overflowing current other unit given.
1319
     *
1320
     * @param string $valueUnit    unit name to modify
1321
     * @param int    $value        new value for the input unit
1322
     * @param string $overflowUnit unit name to not overflow
1323
     *
1324
     * @return static
1325
     */
1326 1
    public function setUnitNoOverflow($valueUnit, $value, $overflowUnit)
1327
    {
1328
        try {
1329 1
            $original = $this->copy();
1330
            /** @var static $date */
1331 1
            $date = $this->$valueUnit($value);
1332 1
            $end = $original->copy()->endOf($overflowUnit);
1333 1
            $start = $original->copy()->startOf($overflowUnit);
1334 1
            if ($date < $start) {
1335 1
                $date = $date->setDateTimeFrom($start);
1336 1
            } elseif ($date > $end) {
1337 1
                $date = $date->setDateTimeFrom($end);
1338
            }
1339

1340 1
            return $date;
1341 1
        } catch (BadMethodCallException | ReflectionException $exception) {
1342 1
            throw new UnknownUnitException($valueUnit, 0, $exception);
1343
        }
1344
    }
1345

1346
    /**
1347
     * Add any unit to a new value without overflowing current other unit given.
1348
     *
1349
     * @param string $valueUnit    unit name to modify
1350
     * @param int    $value        amount to add to the input unit
1351
     * @param string $overflowUnit unit name to not overflow
1352
     *
1353
     * @return static
1354
     */
1355 1
    public function addUnitNoOverflow($valueUnit, $value, $overflowUnit)
1356
    {
1357 1
        return $this->setUnitNoOverflow($valueUnit, $this->$valueUnit + $value, $overflowUnit);
1358
    }
1359

1360
    /**
1361
     * Subtract any unit to a new value without overflowing current other unit given.
1362
     *
1363
     * @param string $valueUnit    unit name to modify
1364
     * @param int    $value        amount to subtract to the input unit
1365
     * @param string $overflowUnit unit name to not overflow
1366
     *
1367
     * @return static
1368
     */
1369 1
    public function subUnitNoOverflow($valueUnit, $value, $overflowUnit)
1370
    {
1371 1
        return $this->setUnitNoOverflow($valueUnit, $this->$valueUnit - $value, $overflowUnit);
1372
    }
1373

1374
    /**
1375
     * Returns the minutes offset to UTC if no arguments passed, else set the timezone with given minutes shift passed.
1376
     *
1377
     * @param int|null $offset
1378
     *
1379
     * @return int|static
1380
     */
1381 1
    public function utcOffset(int $offset = null)
1382
    {
1383 1
        if (\func_num_args() < 1) {
1384 1
            return $this->offsetMinutes;
1385
        }
1386

1387 1
        return $this->setTimezone(static::safeCreateDateTimeZone($offset / static::MINUTES_PER_HOUR));
1388
    }
1389

1390
    /**
1391
     * Set the date with gregorian year, month and day numbers.
1392
     *
1393
     * @see https://php.net/manual/en/datetime.setdate.php
1394
     *
1395
     * @param int $year
1396
     * @param int $month
1397
     * @param int $day
1398
     *
1399
     * @return static
1400
     */
1401 1
    public function setDate($year, $month, $day)
1402
    {
1403 1
        return parent::setDate((int) $year, (int) $month, (int) $day);
1404
    }
1405

1406
    /**
1407
     * Set a date according to the ISO 8601 standard - using weeks and day offsets rather than specific dates.
1408
     *
1409
     * @see https://php.net/manual/en/datetime.setisodate.php
1410
     *
1411
     * @param int $year
1412
     * @param int $week
1413
     * @param int $day
1414
     *
1415
     * @return static
1416
     */
1417 1
    public function setISODate($year, $week, $day = 1)
1418
    {
1419 1
        return parent::setISODate((int) $year, (int) $week, (int) $day);
1420
    }
1421

1422
    /**
1423
     * Set the date and time all together.
1424
     *
1425
     * @param int $year
1426
     * @param int $month
1427
     * @param int $day
1428
     * @param int $hour
1429
     * @param int $minute
1430
     * @param int $second
1431
     * @param int $microseconds
1432
     *
1433
     * @return static
1434
     */
1435 1
    public function setDateTime($year, $month, $day, $hour, $minute, $second = 0, $microseconds = 0)
1436
    {
1437 1
        return $this->setDate($year, $month, $day)->setTime((int) $hour, (int) $minute, (int) $second, (int) $microseconds);
1438
    }
1439

1440
    /**
1441
     * Resets the current time of the DateTime object to a different time.
1442
     *
1443
     * @see https://php.net/manual/en/datetime.settime.php
1444
     *
1445
     * @param int $hour
1446
     * @param int $minute
1447
     * @param int $second
1448
     * @param int $microseconds
1449
     *
1450
     * @return static
1451
     */
1452 1
    public function setTime($hour, $minute, $second = 0, $microseconds = 0)
1453
    {
1454 1
        return parent::setTime((int) $hour, (int) $minute, (int) $second, (int) $microseconds);
1455
    }
1456

1457
    /**
1458
     * Set the instance's timestamp.
1459
     *
1460
     * Timestamp input can be given as int, float or a string containing one or more numbers.
1461
     *
1462
     * @param float|int|string $unixTimestamp
1463
     *
1464
     * @return static
1465
     */
1466 1
    public function setTimestamp($unixTimestamp)
1467
    {
1468 1
        [$timestamp, $microseconds] = self::getIntegerAndDecimalParts($unixTimestamp);
1469

1470 1
        return parent::setTimestamp((int) $timestamp)->setMicroseconds((int) $microseconds);
1471
    }
1472

1473
    /**
1474
     * Set the time by time string.
1475
     *
1476
     * @param string $time
1477
     *
1478
     * @return static
1479
     */
1480 1
    public function setTimeFromTimeString($time)
1481
    {
1482 1
        if (strpos($time, ':') === false) {
1483 1
            $time .= ':0';
1484
        }
1485

1486 1
        return $this->modify($time);
1487
    }
1488

1489
    /**
1490
     * @alias setTimezone
1491
     *
1492
     * @param DateTimeZone|string $value
1493
     *
1494
     * @return static
1495
     */
1496 1
    public function timezone($value)
1497
    {
1498 1
        return $this->setTimezone($value);
1499
    }
1500

1501
    /**
1502
     * Set the timezone or returns the timezone name if no arguments passed.
1503
     *
1504
     * @param DateTimeZone|string $value
1505
     *
1506
     * @return static|string
1507
     */
1508 1
    public function tz($value = null)
1509
    {
1510 1
        if (\func_num_args() < 1) {
1511 1
            return $this->tzName;
1512
        }
1513

1514 1
        return $this->setTimezone($value);
1515
    }
1516

1517
    /**
1518
     * Set the instance's timezone from a string or object.
1519
     *
1520
     * @param DateTimeZone|string $value
1521
     *
1522
     * @return static
1523
     */
1524 1
    public function setTimezone($value)
1525
    {
1526 1
        return parent::setTimezone(static::safeCreateDateTimeZone($value));
1527
    }
1528

1529
    /**
1530
     * Set the instance's timezone from a string or object and add/subtract the offset difference.
1531
     *
1532
     * @param DateTimeZone|string $value
1533
     *
1534
     * @return static
1535
     */
1536 1
    public function shiftTimezone($value)
1537
    {
1538 1
        $offset = $this->offset;
1539 1
        $date = $this->setTimezone($value);
1540

1541 1
        return $date->addRealMicroseconds(($offset - $date->offset) * static::MICROSECONDS_PER_SECOND);
1542
    }
1543

1544
    /**
1545
     * Set the instance's timezone to UTC.
1546
     *
1547
     * @return static
1548
     */
1549 1
    public function utc()
1550
    {
1551 1
        return $this->setTimezone('UTC');
1552
    }
1553

1554
    /**
1555
     * Set the year, month, and date for this instance to that of the passed instance.
1556
     *
1557
     * @param Carbon|DateTimeInterface $date now if null
1558
     *
1559
     * @return static
1560
     */
1561 1
    public function setDateFrom($date = null)
1562
    {
1563 1
        $date = $this->resolveCarbon($date);
1564

1565 1
        return $this->setDate($date->year, $date->month, $date->day);
1566
    }
1567

1568
    /**
1569
     * Set the hour, minute, second and microseconds for this instance to that of the passed instance.
1570
     *
1571
     * @param Carbon|DateTimeInterface $date now if null
1572
     *
1573
     * @return static
1574
     */
1575 1
    public function setTimeFrom($date = null)
1576
    {
1577 1
        $date = $this->resolveCarbon($date);
1578

1579 1
        return $this->setTime($date->hour, $date->minute, $date->second, $date->microsecond);
1580
    }
1581

1582
    /**
1583
     * Set the date and time for this instance to that of the passed instance.
1584
     *
1585
     * @param Carbon|DateTimeInterface $date
1586
     *
1587
     * @return static
1588
     */
1589 1
    public function setDateTimeFrom($date = null)
1590
    {
1591 1
        $date = $this->resolveCarbon($date);
1592

1593 1
        return $this->modify($date->rawFormat('Y-m-d H:i:s.u'));
1594
    }
1595

1596
    /**
1597
     * Get the days of the week
1598
     *
1599
     * @return array
1600
     */
1601 1
    public static function getDays()
1602
    {
1603 1
        return static::$days;
1604
    }
1605

1606
    ///////////////////////////////////////////////////////////////////
1607
    /////////////////////// WEEK SPECIAL DAYS /////////////////////////
1608
    ///////////////////////////////////////////////////////////////////
1609

1610 1
    private static function getFirstDayOfWeek(): int
1611
    {
1612 1
        return (int) static::getTranslationMessageWith(
1613 1
            static::getTranslator(),
1614 1
            'first_day_of_week'
1615
        );
1616
    }
1617

1618
    /**
1619
     * Get the first day of week
1620
     *
1621
     * @return int
1622
     */
1623 1
    public static function getWeekStartsAt()
1624
    {
1625 1
        if (static::$weekStartsAt === static::WEEK_DAY_AUTO) {
1626 1
            return static::getFirstDayOfWeek();
1627
        }
1628

1629 1
        return static::$weekStartsAt;
1630
    }
1631

1632
    /**
1633
     * @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
1634
     *             Use $weekEndsAt optional parameter instead when using endOfWeek method. You can also use the
1635
     *             'first_day_of_week' locale setting to change the start of week according to current locale
1636
     *             selected and implicitly the end of week.
1637
     *
1638
     * Set the first day of week
1639
     *
1640
     * @param int|string $day week start day (or 'auto' to get the first day of week from Carbon::getLocale() culture).
1641
     *
1642
     * @return void
1643
     */
1644 1
    public static function setWeekStartsAt($day)
1645
    {
1646 1
        static::$weekStartsAt = $day === static::WEEK_DAY_AUTO ? $day : max(0, (7 + $day) % 7);
1647
    }
1648

1649
    /**
1650
     * Get the last day of week
1651
     *
1652
     * @return int
1653
     */
1654 1
    public static function getWeekEndsAt()
1655
    {
1656 1
        if (static::$weekStartsAt === static::WEEK_DAY_AUTO) {
1657 1
            return (int) (static::DAYS_PER_WEEK - 1 + static::getFirstDayOfWeek()) % static::DAYS_PER_WEEK;
1658
        }
1659

1660 1
        return static::$weekEndsAt;
1661
    }
1662

1663
    /**
1664
     * @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
1665
     *             Use $weekStartsAt optional parameter instead when using startOfWeek, floorWeek, ceilWeek
1666
     *             or roundWeek method. You can also use the 'first_day_of_week' locale setting to change the
1667
     *             start of week according to current locale selected and implicitly the end of week.
1668
     *
1669
     * Set the last day of week
1670
     *
1671
     * @param int|string $day week end day (or 'auto' to get the day before the first day of week
1672
     *                        from Carbon::getLocale() culture).
1673
     *
1674
     * @return void
1675
     */
1676 1
    public static function setWeekEndsAt($day)
1677
    {
1678 1
        static::$weekEndsAt = $day === static::WEEK_DAY_AUTO ? $day : max(0, (7 + $day) % 7);
1679
    }
1680

1681
    /**
1682
     * Get weekend days
1683
     *
1684
     * @return array
1685
     */
1686 1
    public static function getWeekendDays()
1687
    {
1688 1
        return static::$weekendDays;
1689
    }
1690

1691
    /**
1692
     * @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
1693
     *             You should rather consider week-end is always saturday and sunday, and if you have some custom
1694
     *             week-end days to handle, give to those days an other name and create a macro for them:
1695
     *
1696
     *             ```
1697
     *             Carbon::macro('isDayOff', function ($date) {
1698
     *                 return $date->isSunday() || $date->isMonday();
1699
     *             });
1700
     *             Carbon::macro('isNotDayOff', function ($date) {
1701
     *                 return !$date->isDayOff();
1702
     *             });
1703
     *             if ($someDate->isDayOff()) ...
1704
     *             if ($someDate->isNotDayOff()) ...
1705
     *             // Add 5 not-off days
1706
     *             $count = 5;
1707
     *             while ($someDate->isDayOff() || ($count-- > 0)) {
1708
     *                 $someDate->addDay();
1709
     *             }
1710
     *             ```
1711
     *
1712
     * Set weekend days
1713
     *
1714
     * @param array $days
1715
     *
1716
     * @return void
1717
     */
1718 1
    public static function setWeekendDays($days)
1719
    {
1720 1
        static::$weekendDays = $days;
1721
    }
1722

1723
    /**
1724
     * Determine if a time string will produce a relative date.
1725
     *
1726
     * @param string $time
1727
     *
1728
     * @return bool true if time match a relative date, false if absolute or invalid time string
1729
     */
1730 1
    public static function hasRelativeKeywords($time)
1731
    {
1732 1
        if (!$time || strtotime($time) === false) {
1733 1
            return false;
1734
        }
1735

1736 1
        $date1 = new DateTime('2000-01-01T00:00:00Z');
1737 1
        $date1->modify($time);
1738 1
        $date2 = new DateTime('2001-12-25T00:00:00Z');
1739 1
        $date2->modify($time);
1740

1741 1
        return $date1 != $date2;
1742
    }
1743

1744
    ///////////////////////////////////////////////////////////////////
1745
    /////////////////////// STRING FORMATTING /////////////////////////
1746
    ///////////////////////////////////////////////////////////////////
1747

1748
    /**
1749
     * @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
1750
     *             You should rather use UTF-8 language packages on every machine.
1751
     *
1752
     * Set if UTF8 will be used for localized date/time.
1753
     *
1754
     * @param bool $utf8
1755
     */
1756 1
    public static function setUtf8($utf8)
1757
    {
1758 1
        static::$utf8 = $utf8;
1759
    }
1760

1761
    /**
1762
     * Format the instance with the current locale.  You can set the current
1763
     * locale using setlocale() http://php.net/setlocale.
1764
     *
1765
     * @param string $format
1766
     *
1767
     * @return string
1768
     */
1769 1
    public function formatLocalized($format)
1770
    {
1771
        // Check for Windows to find and replace the %e modifier correctly.
1772 1
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
1773
            $format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format); // @codeCoverageIgnore
1774
        }
1775

1776 1
        $formatted = strftime($format, strtotime($this->toDateTimeString()));
1777

1778 1
        return static::$utf8 ? utf8_encode($formatted) : $formatted;
1779
    }
1780

1781
    /**
1782
     * Returns list of locale formats for ISO formatting.
1783
     *
1784
     * @param string|null $locale current locale used if null
1785
     *
1786
     * @return array
1787
     */
1788 1
    public function getIsoFormats($locale = null)
1789
    {
1790
        return [
1791 1
            'LT' => $this->getTranslationMessage('formats.LT', $locale, 'h:mm A'),
1792 1
            'LTS' => $this->getTranslationMessage('formats.LTS', $locale, 'h:mm:ss A'),
1793 1
            'L' => $this->getTranslationMessage('formats.L', $locale, 'MM/DD/YYYY'),
1794 1
            'LL' => $this->getTranslationMessage('formats.LL', $locale, 'MMMM D, YYYY'),
1795 1
            'LLL' => $this->getTranslationMessage('formats.LLL', $locale, 'MMMM D, YYYY h:mm A'),
1796 1
            'LLLL' => $this->getTranslationMessage('formats.LLLL', $locale, 'dddd, MMMM D, YYYY h:mm A'),
1797
        ];
1798
    }
1799

1800
    /**
1801
     * Returns list of calendar formats for ISO formatting.
1802
     *
1803
     * @param string|null $locale current locale used if null
1804
     *
1805
     * @return array
1806
     */
1807 1
    public function getCalendarFormats($locale = null)
1808
    {
1809
        return [
1810 1
            'sameDay' => $this->getTranslationMessage('calendar.sameDay', $locale, '[Today at] LT'),
1811 1
            'nextDay' => $this->getTranslationMessage('calendar.nextDay', $locale, '[Tomorrow at] LT'),
1812 1
            'nextWeek' => $this->getTranslationMessage('calendar.nextWeek', $locale, 'dddd [at] LT'),
1813 1
            'lastDay' => $this->getTranslationMessage('calendar.lastDay', $locale, '[Yesterday at] LT'),
1814 1
            'lastWeek' => $this->getTranslationMessage('calendar.lastWeek', $locale, '[Last] dddd [at] LT'),
1815 1
            'sameElse' => $this->getTranslationMessage('calendar.sameElse', $locale, 'L'),
1816
        ];
1817
    }
1818

1819
    /**
1820
     * Returns list of locale units for ISO formatting.
1821
     *
1822
     * @return array
1823
     */
1824 1
    public static function getIsoUnits()
1825
    {
1826 1
        static $units = null;
1827

1828 1
        if ($units === null) {
1829
            $units = [
1830 1
                'OD' => ['getAltNumber', ['day']],
1831
                'OM' => ['getAltNumber', ['month']],
1832
                'OY' => ['getAltNumber', ['year']],
1833
                'OH' => ['getAltNumber', ['hour']],
1834
                'Oh' => ['getAltNumber', ['h']],
1835
                'Om' => ['getAltNumber', ['minute']],
1836
                'Os' => ['getAltNumber', ['second']],
1837 1
                'D' => 'day',
1838
                'DD' => ['rawFormat', ['d']],
1839
                'Do' => ['ordinal', ['day', 'D']],
1840 1
                'd' => 'dayOfWeek',
1841
                'dd' => function (CarbonInterface $date, $originalFormat = null) {
1842 1
                    return $date->getTranslatedMinDayName($originalFormat);
1843 1
                },
1844
                'ddd' => function (CarbonInterface $date, $originalFormat = null) {
1845 1
                    return $date->getTranslatedShortDayName($originalFormat);
1846 1
                },
1847
                'dddd' => function (CarbonInterface $date, $originalFormat = null) {
1848 1
                    return $date->getTranslatedDayName($originalFormat);
1849 1
                },
1850 1
                'DDD' => 'dayOfYear',
1851
                'DDDD' => ['getPaddedUnit', ['dayOfYear', 3]],
1852
                'DDDo' => ['ordinal', ['dayOfYear', 'DDD']],
1853
                'e' => ['weekday', []],
1854 1
                'E' => 'dayOfWeekIso',
1855
                'H' => ['rawFormat', ['G']],
1856
                'HH' => ['rawFormat', ['H']],
1857
                'h' => ['rawFormat', ['g']],
1858
                'hh' => ['rawFormat', ['h']],
1859 1
                'k' => 'noZeroHour',
1860
                'kk' => ['getPaddedUnit', ['noZeroHour']],
1861
                'hmm' => ['rawFormat', ['gi']],
1862
                'hmmss' => ['rawFormat', ['gis']],
1863
                'Hmm' => ['rawFormat', ['Gi']],
1864
                'Hmmss' => ['rawFormat', ['Gis']],
1865 1
                'm' => 'minute',
1866
                'mm' => ['rawFormat', ['i']],
1867 1
                'a' => 'meridiem',
1868 1
                'A' => 'upperMeridiem',
1869 1
                's' => 'second',
1870
                'ss' => ['getPaddedUnit', ['second']],
1871
                'S' => function (CarbonInterface $date) {
1872 1
                    return \strval((string) floor($date->micro / 100000));
1873 1
                },
1874
                'SS' => function (CarbonInterface $date) {
1875 1
                    return str_pad((string) floor($date->micro / 10000), 2, '0', STR_PAD_LEFT);
1876 1
                },
1877
                'SSS' => function (CarbonInterface $date) {
1878 1
                    return str_pad((string) floor($date->micro / 1000), 3, '0', STR_PAD_LEFT);
1879 1
                },
1880
                'SSSS' => function (CarbonInterface $date) {
1881 1
                    return str_pad((string) floor($date->micro / 100), 4, '0', STR_PAD_LEFT);
1882 1
                },
1883
                'SSSSS' => function (CarbonInterface $date) {
1884 1
                    return str_pad((string) floor($date->micro / 10), 5, '0', STR_PAD_LEFT);
1885 1
                },
1886
                'SSSSSS' => ['getPaddedUnit', ['micro', 6]],
1887
                'SSSSSSS' => function (CarbonInterface $date) {
1888 1
                    return str_pad((string) floor($date->micro * 10), 7, '0', STR_PAD_LEFT);
1889 1
                },
1890
                'SSSSSSSS' => function (CarbonInterface $date) {
1891 1
                    return str_pad((string) floor($date->micro * 100), 8, '0', STR_PAD_LEFT);
1892 1
                },
1893
                'SSSSSSSSS' => function (CarbonInterface $date) {
1894 1
                    return str_pad((string) floor($date->micro * 1000), 9, '0', STR_PAD_LEFT);
1895 1
                },
1896 1
                'M' => 'month',
1897
                'MM' => ['rawFormat', ['m']],
1898
                'MMM' => function (CarbonInterface $date, $originalFormat = null) {
1899 1
                    $month = $date->getTranslatedShortMonthName($originalFormat);
1900 1
                    $suffix = $date->getTranslationMessage('mmm_suffix');
1901 1
                    if ($suffix && $month !== $date->monthName) {
1902 1
                        $month .= $suffix;
1903
                    }
1904

1905 1
                    return $month;
1906 1
                },
1907
                'MMMM' => function (CarbonInterface $date, $originalFormat = null) {
1908 1
                    return $date->getTranslatedMonthName($originalFormat);
1909 1
                },
1910
                'Mo' => ['ordinal', ['month', 'M']],
1911 1
                'Q' => 'quarter',
1912
                'Qo' => ['ordinal', ['quarter', 'M']],
1913 1
                'G' => 'isoWeekYear',
1914
                'GG' => ['getPaddedUnit', ['isoWeekYear']],
1915
                'GGG' => ['getPaddedUnit', ['isoWeekYear', 3]],
1916
                'GGGG' => ['getPaddedUnit', ['isoWeekYear', 4]],
1917
                'GGGGG' => ['getPaddedUnit', ['isoWeekYear', 5]],
1918 1
                'g' => 'weekYear',
1919
                'gg' => ['getPaddedUnit', ['weekYear']],
1920
                'ggg' => ['getPaddedUnit', ['weekYear', 3]],
1921
                'gggg' => ['getPaddedUnit', ['weekYear', 4]],
1922
                'ggggg' => ['getPaddedUnit', ['weekYear', 5]],
1923 1
                'W' => 'isoWeek',
1924
                'WW' => ['getPaddedUnit', ['isoWeek']],
1925
                'Wo' => ['ordinal', ['isoWeek', 'W']],
1926 1
                'w' => 'week',
1927
                'ww' => ['getPaddedUnit', ['week']],
1928
                'wo' => ['ordinal', ['week', 'w']],
1929
                'x' => ['valueOf', []],
1930 1
                'X' => 'timestamp',
1931 1
                'Y' => 'year',
1932
                'YY' => ['rawFormat', ['y']],
1933
                'YYYY' => ['getPaddedUnit', ['year', 4]],
1934
                'YYYYY' => ['getPaddedUnit', ['year', 5]],
1935
                'YYYYYY' => function (CarbonInterface $date) {
1936 1
                    return ($date->year < 0 ? '' : '+').$date->getPaddedUnit('year', 6);
1937 1
                },
1938
                'z' => ['rawFormat', ['T']],
1939 1
                'zz' => 'tzName',
1940
                'Z' => ['getOffsetString', []],
1941
                'ZZ' => ['getOffsetString', ['']],
1942
            ];
1943
        }
1944

1945 1
        return $units;
1946
    }
1947

1948
    /**
1949
     * Returns a unit of the instance padded with 0 by default or any other string if specified.
1950
     *
1951
     * @param string $unit      Carbon unit name
1952
     * @param int    $length    Length of the output (2 by default)
1953
     * @param string $padString String to use for padding ("0" by default)
1954
     * @param int    $padType   Side(s) to pad (STR_PAD_LEFT by default)
1955
     *
1956
     * @return string
1957
     */
1958 1
    public function getPaddedUnit($unit, $length = 2, $padString = '0', $padType = STR_PAD_LEFT)
1959
    {
1960 1
        return ($this->$unit < 0 ? '-' : '').str_pad((string) abs($this->$unit), $length, $padString, $padType);
1961
    }
1962

1963
    /**
1964
     * Return a property with its ordinal.
1965
     *
1966
     * @param string      $key
1967
     * @param string|null $period
1968
     *
1969
     * @return string
1970
     */
1971 1
    public function ordinal(string $key, string $period = null): string
1972
    {
1973 1
        $number = $this->$key;
1974 1
        $result = $this->translate('ordinal', [
1975 1
            ':number' => $number,
1976 1
            ':period' => $period,
1977
        ]);
1978

1979 1
        return \strval($result === 'ordinal' ? $number : $result);
1980
    }
1981

1982
    /**
1983
     * Return the meridiem of the current time in the current locale.
1984
     *
1985
     * @param bool $isLower if true, returns lowercase variant if available in the current locale.
1986
     *
1987
     * @return string
1988
     */
1989 1
    public function meridiem(bool $isLower = false): string
1990
    {
1991 1
        $hour = $this->hour;
1992 1
        $index = $hour < 12 ? 0 : 1;
1993

1994 1
        if ($isLower) {
1995 1
            $key = 'meridiem.'.($index + 2);
1996 1
            $result = $this->translate($key);
1997

1998 1
            if ($result !== $key) {
1999 1
                return $result;
2000
            }
2001
        }
2002

2003 1
        $key = "meridiem.$index";
2004 1
        $result = $this->translate($key);
2005 1
        if ($result === $key) {
2006 1
            $result = $this->translate('meridiem', [
2007 1
                ':hour' => $this->hour,
2008 1
                ':minute' => $this->minute,
2009 1
                ':isLower' => $isLower,
2010
            ]);
2011

2012 1
            if ($result === 'meridiem') {
2013 1
                return $isLower ? $this->latinMeridiem : $this->latinUpperMeridiem;
2014
            }
2015 1
        } elseif ($isLower) {
2016 1
            $result = mb_strtolower($result);
2017
        }
2018

2019 1
        return $result;
2020
    }
2021

2022
    /**
2023
     * Returns the alternative number for a given date property if available in the current locale.
2024
     *
2025
     * @param string $key date property
2026
     *
2027
     * @return string
2028
     */
2029 1
    public function getAltNumber(string $key): string
2030
    {
2031 1
        return $this->translateNumber(\strlen($key) > 1 ? $this->$key : $this->rawFormat('h'));
2032
    }
2033

2034
    /**
2035
     * Format in the current language using ISO replacement patterns.
2036
     *
2037
     * @param string      $format
2038
     * @param string|null $originalFormat provide context if a chunk has been passed alone
2039
     *
2040
     * @return string
2041
     */
2042 1
    public function isoFormat(string $format, string $originalFormat = null): string
2043
    {
2044 1
        $result = '';
2045 1
        $length = mb_strlen($format);
2046 1
        $originalFormat = $originalFormat ?: $format;
2047 1
        $inEscaped = false;
2048 1
        $formats = null;
2049 1
        $units = null;
2050

2051 1
        for ($i = 0; $i < $length; $i++) {
2052 1
            $char = mb_substr($format, $i, 1);
2053

2054 1
            if ($char === '\\') {
2055 1
                $result .= mb_substr($format, ++$i, 1);
2056

2057 1
                continue;
2058
            }
2059

2060 1
            if ($char === '[' && !$inEscaped) {
2061 1
                $inEscaped = true;
2062

2063 1
                continue;
2064
            }
2065

2066 1
            if ($char === ']' && $inEscaped) {
2067 1
                $inEscaped = false;
2068

2069 1
                continue;
2070
            }
2071

2072 1
            if ($inEscaped) {
2073 1
                $result .= $char;
2074

2075 1
                continue;
2076
            }
2077

2078 1
            $input = mb_substr($format, $i);
2079

2080 1
            if (preg_match('/^(LTS|LT|[Ll]{1,4})/', $input, $match)) {
2081 1
                if ($formats === null) {
2082 1
                    $formats = $this->getIsoFormats();
2083
                }
2084

2085 1
                $code = $match[0];
2086 1
                $sequence = $formats[$code] ?? preg_replace_callback(
2087 1
                    '/MMMM|MM|DD|dddd/',
2088
                    function ($code) {
2089 1
                        return mb_substr($code[0], 1);
2090 1
                    },
2091 1
                    $formats[strtoupper($code)] ?? ''
2092
                );
2093 1
                $rest = mb_substr($format, $i + mb_strlen($code));
2094 1
                $format = mb_substr($format, 0, $i).$sequence.$rest;
2095 1
                $length = mb_strlen($format);
2096 1
                $input = $sequence.$rest;
2097
            }
2098

2099 1
            if (preg_match('/^'.CarbonInterface::ISO_FORMAT_REGEXP.'/', $input, $match)) {
2100 1
                $code = $match[0];
2101

2102 1
                if ($units === null) {
2103 1
                    $units = static::getIsoUnits();
2104
                }
2105

2106 1
                $sequence = $units[$code] ?? '';
2107

2108 1
                if ($sequence instanceof Closure) {
2109 1
                    $sequence = $sequence($this, $originalFormat);
2110 1
                } elseif (\is_array($sequence)) {
2111
                    try {
2112 1
                        $sequence = $this->{$sequence[0]}(...$sequence[1]);
2113 1
                    } catch (ReflectionException | InvalidArgumentException | BadMethodCallException $e) {
2114 1
                        $sequence = '';
2115
                    }
2116 1
                } elseif (\is_string($sequence)) {
2117 1
                    $sequence = $this->$sequence ?? $code;
2118
                }
2119

2120 1
                $format = mb_substr($format, 0, $i).$sequence.mb_substr($format, $i + mb_strlen($code));
2121 1
                $i += mb_strlen("$sequence") - 1;
2122 1
                $length = mb_strlen($format);
2123 1
                $char = $sequence;
2124
            }
2125

2126 1
            $result .= $char;
2127
        }
2128

2129 1
        return $result;
2130
    }
2131

2132
    /**
2133
     * List of replacements from date() format to isoFormat().
2134
     *
2135
     * @return array
2136
     */
2137 1
    public static function getFormatsToIsoReplacements()
2138
    {
2139 1
        static $replacements = null;
2140

2141 1
        if ($replacements === null) {
2142
            $replacements = [
2143 1
                'd' => true,
2144 1
                'D' => 'ddd',
2145
                'j' => true,
2146 1
                'l' => 'dddd',
2147
                'N' => true,
2148
                'S' => function ($date) {
2149 1
                    $day = $date->rawFormat('j');
2150

2151 1
                    return str_replace("$day", '', $date->isoFormat('Do'));
2152 1
                },
2153
                'w' => true,
2154
                'z' => true,
2155
                'W' => true,
2156 1
                'F' => 'MMMM',
2157
                'm' => true,
2158 1
                'M' => 'MMM',
2159
                'n' => true,
2160
                't' => true,
2161
                'L' => true,
2162
                'o' => true,
2163
                'Y' => true,
2164
                'y' => true,
2165 1
                'a' => 'a',
2166 1
                'A' => 'A',
2167
                'B' => true,
2168
                'g' => true,
2169
                'G' => true,
2170
                'h' => true,
2171
                'H' => true,
2172
                'i' => true,
2173
                's' => true,
2174
                'u' => true,
2175
                'v' => true,
2176
                'E' => true,
2177
                'I' => true,
2178
                'O' => true,
2179
                'P' => true,
2180
                'Z' => true,
2181
                'c' => true,
2182
                'r' => true,
2183
                'U' => true,
2184
            ];
2185
        }
2186

2187 1
        return $replacements;
2188
    }
2189

2190
    /**
2191
     * Format as ->format() do (using date replacements patterns from http://php.net/manual/fr/function.date.php)
2192
     * but translate words whenever possible (months, day names, etc.) using the current locale.
2193
     *
2194
     * @param string $format
2195
     *
2196
     * @return string
2197
     */
2198 1
    public function translatedFormat(string $format): string
2199
    {
2200 1
        $replacements = static::getFormatsToIsoReplacements();
2201 1
        $context = '';
2202 1
        $isoFormat = '';
2203 1
        $length = mb_strlen($format);
2204

2205 1
        for ($i = 0; $i < $length; $i++) {
2206 1
            $char = mb_substr($format, $i, 1);
2207

2208 1
            if ($char === '\\') {
2209 1
                $replacement = mb_substr($format, $i, 2);
2210 1
                $isoFormat .= $replacement;
2211 1
                $i++;
2212

2213 1
                continue;
2214
            }
2215

2216 1
            if (!isset($replacements[$char])) {
2217 1
                $replacement = preg_match('/^[A-Za-z]$/', $char) ? "\\$char" : $char;
2218 1
                $isoFormat .= $replacement;
2219 1
                $context .= $replacement;
2220

2221 1
                continue;
2222
            }
2223

2224 1
            $replacement = $replacements[$char];
2225

2226 1
            if ($replacement === true) {
2227 1
                static $contextReplacements = null;
2228

2229 1
                if ($contextReplacements === null) {
2230
                    $contextReplacements = [
2231 1
                        'm' => 'MM',
2232
                        'd' => 'DD',
2233
                        't' => 'D',
2234
                        'j' => 'D',
2235
                        'N' => 'e',
2236
                        'w' => 'e',
2237
                        'n' => 'M',
2238
                        'o' => 'YYYY',
2239
                        'Y' => 'YYYY',
2240
                        'y' => 'YY',
2241
                        'g' => 'h',
2242
                        'G' => 'H',
2243
                        'h' => 'hh',
2244
                        'H' => 'HH',
2245
                        'i' => 'mm',
2246
                        's' => 'ss',
2247
                    ];
2248
                }
2249

2250 1
                $isoFormat .= '['.$this->rawFormat($char).']';
2251 1
                $context .= $contextReplacements[$char] ?? ' ';
2252

2253 1
                continue;
2254
            }
2255

2256 1
            if ($replacement instanceof Closure) {
2257 1
                $replacement = '['.$replacement($this).']';
2258 1
                $isoFormat .= $replacement;
2259 1
                $context .= $replacement;
2260

2261 1
                continue;
2262
            }
2263

2264 1
            $isoFormat .= $replacement;
2265 1
            $context .= $replacement;
2266
        }
2267

2268 1
        return $this->isoFormat($isoFormat, $context);
2269
    }
2270

2271
    /**
2272
     * Returns the offset hour and minute formatted with +/- and a given separator (":" by default).
2273
     * For example, if the time zone is 9 hours 30 minutes, you'll get "+09:30", with "@@" as first
2274
     * argument, "+09@@30", with "" as first argument, "+0930". Negative offset will return something
2275
     * like "-12:00".
2276
     *
2277
     * @param string $separator string to place between hours and minutes (":" by default)
2278
     *
2279
     * @return string
2280
     */
2281 1
    public function getOffsetString($separator = ':')
2282
    {
2283 1
        $second = $this->getOffset();
2284 1
        $symbol = $second < 0 ? '-' : '+';
2285 1
        $minute = abs($second) / static::SECONDS_PER_MINUTE;
2286 1
        $hour = str_pad((string) floor($minute / static::MINUTES_PER_HOUR), 2, '0', STR_PAD_LEFT);
2287 1
        $minute = str_pad((string) ($minute % static::MINUTES_PER_HOUR), 2, '0', STR_PAD_LEFT);
2288

2289 1
        return "$symbol$hour$separator$minute";
2290
    }
2291

2292 1
    protected static function executeStaticCallable($macro, ...$parameters)
2293
    {
2294
        return static::bindMacroContext(null, function () use (&$macro, &$parameters) {
2295 1
            if ($macro instanceof Closure) {
2296 1
                $boundMacro = @Closure::bind($macro, null, static::class);
2297

2298 1
                return \call_user_func_array($boundMacro ?: $macro, $parameters);
2299
            }
2300

2301 1
            return \call_user_func_array($macro, $parameters);
2302 1
        });
2303
    }
2304

2305
    /**
2306
     * Dynamically handle calls to the class.
2307
     *
2308
     * @param string $method     magic method name called
2309
     * @param array  $parameters parameters list
2310
     *
2311
     * @throws BadMethodCallException
2312
     *
2313
     * @return mixed
2314
     */
2315 1
    public static function __callStatic($method, $parameters)
2316
    {
2317 1
        if (!static::hasMacro($method)) {
2318 1
            foreach (static::getGenericMacros() as $callback) {
2319
                try {
2320 1
                    return static::executeStaticCallable($callback, $method, ...$parameters);
2321 1
                } catch (BadMethodCallException $exception) {
2322 1
                    continue;
2323
                }
2324
            }
2325 1
            if (static::isStrictModeEnabled()) {
2326 1
                throw new UnknownMethodException(sprintf('%s::%s', static::class, $method));
2327
            }
2328

2329 1
            return null;
2330
        }
2331

2332 1
        return static::executeStaticCallable(static::$globalMacros[$method], ...$parameters);
2333
    }
2334

2335
    /**
2336
     * Set specified unit to new given value.
2337
     *
2338
     * @param string $unit  year, month, day, hour, minute, second or microsecond
2339
     * @param int    $value new value for given unit
2340
     *
2341
     * @return static
2342
     */
2343 1
    public function setUnit($unit, $value = null)
2344
    {
2345 1
        $unit = static::singularUnit($unit);
2346 1
        $dateUnits = ['year', 'month', 'day'];
2347 1
        if (\in_array($unit, $dateUnits)) {
2348
            return $this->setDate(...array_map(function ($name) use ($unit, $value) {
2349 1
                return (int) ($name === $unit ? $value : $this->$name);
2350 1
            }, $dateUnits));
2351
        }
2352

2353 1
        $units = ['hour', 'minute', 'second', 'micro'];
2354 1
        if ($unit === 'millisecond' || $unit === 'milli') {
2355 1
            $value *= 1000;
2356 1
            $unit = 'micro';
2357 1
        } elseif ($unit === 'microsecond') {
2358 1
            $unit = 'micro';
2359
        }
2360

2361
        return $this->setTime(...array_map(function ($name) use ($unit, $value) {
2362 1
            return (int) ($name === $unit ? $value : $this->$name);
2363 1
        }, $units));
2364
    }
2365

2366
    /**
2367
     * Returns standardized singular of a given singular/plural unit name (in English).
2368
     *
2369
     * @param string $unit
2370
     *
2371
     * @return string
2372
     */
2373 1
    public static function singularUnit(string $unit): string
2374
    {
2375 1
        $unit = rtrim(mb_strtolower($unit), 's');
2376

2377 1
        if ($unit === 'centurie') {
2378 1
            return 'century';
2379
        }
2380

2381 1
        if ($unit === 'millennia') {
2382 1
            return 'millennium';
2383
        }
2384

2385 1
        return $unit;
2386
    }
2387

2388
    /**
2389
     * Returns standardized plural of a given singular/plural unit name (in English).
2390
     *
2391
     * @param string $unit
2392
     *
2393
     * @return string
2394
     */
2395 1
    public static function pluralUnit(string $unit): string
2396
    {
2397 1
        $unit = rtrim(strtolower($unit), 's');
2398

2399 1
        if ($unit === 'century') {
2400 1
            return 'centuries';
2401
        }
2402

2403 1
        if ($unit === 'millennium' || $unit === 'millennia') {
2404 1
            return 'millennia';
2405
        }
2406

2407 1
        return "${unit}s";
2408
    }
2409

2410 1
    protected function executeCallable($macro, ...$parameters)
2411
    {
2412 1
        if ($macro instanceof Closure) {
2413 1
            $boundMacro = @$macro->bindTo($this, static::class) ?: @$macro->bindTo(null, static::class);
2414

2415 1
            return \call_user_func_array($boundMacro ?: $macro, $parameters);
2416
        }
2417

2418 1
        return \call_user_func_array($macro, $parameters);
2419
    }
2420

2421 1
    protected function executeCallableWithContext($macro, ...$parameters)
2422
    {
2423
        return static::bindMacroContext($this, function () use (&$macro, &$parameters) {
2424 1
            return $this->executeCallable($macro, ...$parameters);
2425 1
        });
2426
    }
2427

2428 1
    protected static function getGenericMacros()
2429
    {
2430 1
        foreach (static::$globalGenericMacros as $list) {
2431 1
            foreach ($list as $macro) {
2432 1
                yield $macro;
2433
            }
2434
        }
2435
    }
2436

2437
    /**
2438
     * Dynamically handle calls to the class.
2439
     *
2440
     * @param string $method     magic method name called
2441
     * @param array  $parameters parameters list
2442
     *
2443
     * @throws UnknownMethodException|BadMethodCallException|ReflectionException|Throwable
2444
     *
2445
     * @return mixed
2446
     */
2447 1
    public function __call($method, $parameters)
2448
    {
2449
        $diffSizes = [
2450
            // @mode diffForHumans
2451 1
            'short' => true,
2452
            // @mode diffForHumans
2453
            'long' => false,
2454
        ];
2455
        $diffSyntaxModes = [
2456
            // @call diffForHumans
2457 1
            'Absolute' => CarbonInterface::DIFF_ABSOLUTE,
2458
            // @call diffForHumans
2459 1
            'Relative' => CarbonInterface::DIFF_RELATIVE_AUTO,
2460
            // @call diffForHumans
2461 1
            'RelativeToNow' => CarbonInterface::DIFF_RELATIVE_TO_NOW,
2462
            // @call diffForHumans
2463 1
            'RelativeToOther' => CarbonInterface::DIFF_RELATIVE_TO_OTHER,
2464
        ];
2465 1
        $sizePattern = implode('|', array_keys($diffSizes));
2466 1
        $syntaxPattern = implode('|', array_keys($diffSyntaxModes));
2467

2468 1
        if (preg_match("/^(?<size>$sizePattern)(?<syntax>$syntaxPattern)DiffForHumans$/", $method, $match)) {
2469
            $dates = array_filter($parameters, function ($parameter) {
2470 1
                return $parameter instanceof DateTimeInterface;
2471 1
            });
2472 1
            $other = null;
2473

2474 1
            if (\count($dates)) {
2475 1
                $key = key($dates);
2476 1
                $other = current($dates);
2477 1
                array_splice($parameters, $key, 1);
2478
            }
2479

2480 1
            return $this->diffForHumans($other, $diffSyntaxModes[$match['syntax']], $diffSizes[$match['size']], ...$parameters);
2481
        }
2482

2483 1
        $roundedValue = $this->callRoundMethod($method, $parameters);
2484

2485 1
        if ($roundedValue !== null) {
2486 1
            return $roundedValue;
2487
        }
2488

2489 1
        $unit = rtrim($method, 's');
2490

2491 1
        if (substr($unit, 0, 2) === 'is') {
2492 1
            $word = substr($unit, 2);
2493

2494 1
            if (\in_array($word, static::$days)) {
2495 1
                return $this->isDayOfWeek($word);
2496
            }
2497

2498 1
            switch ($word) {
2499
                // @call is Check if the current instance has UTC timezone. (Both isUtc and isUTC cases are valid.)
2500 1
                case 'Utc':
2501 1
                case 'UTC':
2502 1
                    return $this->utc;
2503
                // @call is Check if the current instance has non-UTC timezone.
2504 1
                case 'Local':
2505 1
                    return $this->local;
2506
                // @call is Check if the current instance is a valid date.
2507 1
                case 'Valid':
2508 1
                    return $this->year !== 0;
2509
                // @call is Check if the current instance is in a daylight saving time.
2510 1
                case 'DST':
2511 1
                    return $this->dst;
2512
            }
2513
        }
2514

2515 1
        $action = substr($unit, 0, 3);
2516 1
        $overflow = null;
2517

2518 1
        if ($action === 'set') {
2519 1
            $unit = strtolower(substr($unit, 3));
2520
        }
2521

2522 1
        if (\in_array($unit, static::$units)) {
2523 1
            return $this->setUnit($unit, ...$parameters);
2524
        }
2525

2526 1
        if ($action === 'add' || $action === 'sub') {
2527 1
            $unit = substr($unit, 3);
2528

2529 1
            if (substr($unit, 0, 4) === 'Real') {
2530 1
                $unit = static::singularUnit(substr($unit, 4));
2531

2532 1
                return $this->{"${action}RealUnit"}($unit, ...$parameters);
2533
            }
2534

2535 1
            if (preg_match('/^(Month|Quarter|Year|Decade|Century|Centurie|Millennium|Millennia)s?(No|With|Without|WithNo)Overflow$/', $unit, $match)) {
2536 1
                $unit = $match[1];
2537 1
                $overflow = $match[2] === 'With';
2538
            }
2539

2540 1
            $unit = static::singularUnit($unit);
2541
        }
2542

2543 1
        if (static::isModifiableUnit($unit)) {
2544 1
            return $this->{"${action}Unit"}($unit, $parameters[0] ?? 1, $overflow);
2545
        }
2546

2547 1
        $sixFirstLetters = substr($unit, 0, 6);
2548 1
        $factor = -1;
2549

2550 1
        if ($sixFirstLetters === 'isLast') {
2551 1
            $sixFirstLetters = 'isNext';
2552 1
            $factor = 1;
2553
        }
2554

2555 1
        if ($sixFirstLetters === 'isNext') {
2556 1
            $lowerUnit = strtolower(substr($unit, 6));
2557

2558 1
            if (static::isModifiableUnit($lowerUnit)) {
2559 1
                return $this->copy()->addUnit($lowerUnit, $factor, false)->isSameUnit($lowerUnit, ...$parameters);
2560
            }
2561
        }
2562

2563 1
        if ($sixFirstLetters === 'isSame') {
2564
            try {
2565 1
                return $this->isSameUnit(strtolower(substr($unit, 6)), ...$parameters);
2566 1
            } catch (BadComparisonUnitException $exception) {
2567
                // Try next
2568
            }
2569
        }
2570

2571 1
        if (substr($unit, 0, 9) === 'isCurrent') {
2572
            try {
2573 1
                return $this->isCurrentUnit(strtolower(substr($unit, 9)));
2574 1
            } catch (BadComparisonUnitException | BadMethodCallException $exception) {
2575
                // Try next
2576
            }
2577
        }
2578

2579 1
        if (substr($method, -5) === 'Until') {
2580
            try {
2581 1
                $unit = static::singularUnit(substr($method, 0, -5));
2582

2583 1
                return $this->range($parameters[0] ?? $this, $parameters[1] ?? 1, $unit);
2584 1
            } catch (InvalidArgumentException $exception) {
2585
                // Try macros
2586
            }
2587
        }
2588

2589
        return static::bindMacroContext($this, function () use (&$method, &$parameters) {
2590 1
            $macro = $this->getLocalMacro($method);
2591

2592 1
            if (!$macro) {
2593 1
                foreach ([$this->localGenericMacros ?: [], static::getGenericMacros()] as $list) {
2594 1
                    foreach ($list as $callback) {
2595
                        try {
2596 1
                            return $this->executeCallable($callback, $method, ...$parameters);
2597 1
                        } catch (BadMethodCallException $exception) {
2598 1
                            continue;
2599
                        }
2600
                    }
2601
                }
2602

2603 1
                if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) {
2604 1
                    throw new UnknownMethodException($method);
2605
                }
2606

2607 1
                return null;
2608
            }
2609

2610 1
            return $this->executeCallable($macro, ...$parameters);
2611 1
        });
2612
    }
2613
}

Read our documentation on viewing source code .

Loading