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