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