Boundaries.php
4 years ago
Cast.php
4 years ago
Comparison.php
2 years ago
Converter.php
2 years ago
Creator.php
2 years ago
Date.php
9 months ago
DeprecatedProperties.php
4 years ago
Difference.php
2 years ago
IntervalRounding.php
2 years ago
IntervalStep.php
4 years ago
Localization.php
9 months ago
Macro.php
4 years ago
MagicParameter.php
2 years ago
Mixin.php
2 years ago
Modifiers.php
4 years ago
Mutability.php
4 years ago
ObjectInitialisation.php
4 years ago
Options.php
2 years ago
Rounding.php
2 years ago
Serialization.php
2 years ago
Test.php
9 months ago
Timestamp.php
1 year ago
ToStringFormat.php
3 years ago
Units.php
2 years ago
Week.php
4 years ago
index.php
3 years ago
Boundaries.php
121 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Carbon\Traits; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Carbon\Exceptions\UnknownUnitException; |
| 5 | trait Boundaries |
| 6 | { |
| 7 | public function startOfDay() |
| 8 | { |
| 9 | return $this->setTime(0, 0, 0, 0); |
| 10 | } |
| 11 | public function endOfDay() |
| 12 | { |
| 13 | return $this->setTime(static::HOURS_PER_DAY - 1, static::MINUTES_PER_HOUR - 1, static::SECONDS_PER_MINUTE - 1, static::MICROSECONDS_PER_SECOND - 1); |
| 14 | } |
| 15 | public function startOfMonth() |
| 16 | { |
| 17 | return $this->setDate($this->year, $this->month, 1)->startOfDay(); |
| 18 | } |
| 19 | public function endOfMonth() |
| 20 | { |
| 21 | return $this->setDate($this->year, $this->month, $this->daysInMonth)->endOfDay(); |
| 22 | } |
| 23 | public function startOfQuarter() |
| 24 | { |
| 25 | $month = ($this->quarter - 1) * static::MONTHS_PER_QUARTER + 1; |
| 26 | return $this->setDate($this->year, $month, 1)->startOfDay(); |
| 27 | } |
| 28 | public function endOfQuarter() |
| 29 | { |
| 30 | return $this->startOfQuarter()->addMonths(static::MONTHS_PER_QUARTER - 1)->endOfMonth(); |
| 31 | } |
| 32 | public function startOfYear() |
| 33 | { |
| 34 | return $this->setDate($this->year, 1, 1)->startOfDay(); |
| 35 | } |
| 36 | public function endOfYear() |
| 37 | { |
| 38 | return $this->setDate($this->year, 12, 31)->endOfDay(); |
| 39 | } |
| 40 | public function startOfDecade() |
| 41 | { |
| 42 | $year = $this->year - $this->year % static::YEARS_PER_DECADE; |
| 43 | return $this->setDate($year, 1, 1)->startOfDay(); |
| 44 | } |
| 45 | public function endOfDecade() |
| 46 | { |
| 47 | $year = $this->year - $this->year % static::YEARS_PER_DECADE + static::YEARS_PER_DECADE - 1; |
| 48 | return $this->setDate($year, 12, 31)->endOfDay(); |
| 49 | } |
| 50 | public function startOfCentury() |
| 51 | { |
| 52 | $year = $this->year - ($this->year - 1) % static::YEARS_PER_CENTURY; |
| 53 | return $this->setDate($year, 1, 1)->startOfDay(); |
| 54 | } |
| 55 | public function endOfCentury() |
| 56 | { |
| 57 | $year = $this->year - 1 - ($this->year - 1) % static::YEARS_PER_CENTURY + static::YEARS_PER_CENTURY; |
| 58 | return $this->setDate($year, 12, 31)->endOfDay(); |
| 59 | } |
| 60 | public function startOfMillennium() |
| 61 | { |
| 62 | $year = $this->year - ($this->year - 1) % static::YEARS_PER_MILLENNIUM; |
| 63 | return $this->setDate($year, 1, 1)->startOfDay(); |
| 64 | } |
| 65 | public function endOfMillennium() |
| 66 | { |
| 67 | $year = $this->year - 1 - ($this->year - 1) % static::YEARS_PER_MILLENNIUM + static::YEARS_PER_MILLENNIUM; |
| 68 | return $this->setDate($year, 12, 31)->endOfDay(); |
| 69 | } |
| 70 | public function startOfWeek($weekStartsAt = null) |
| 71 | { |
| 72 | return $this->subDays((7 + $this->dayOfWeek - ($weekStartsAt ?? $this->firstWeekDay)) % 7)->startOfDay(); |
| 73 | } |
| 74 | public function endOfWeek($weekEndsAt = null) |
| 75 | { |
| 76 | return $this->addDays((7 - $this->dayOfWeek + ($weekEndsAt ?? $this->lastWeekDay)) % 7)->endOfDay(); |
| 77 | } |
| 78 | public function startOfHour() |
| 79 | { |
| 80 | return $this->setTime($this->hour, 0, 0, 0); |
| 81 | } |
| 82 | public function endOfHour() |
| 83 | { |
| 84 | return $this->setTime($this->hour, static::MINUTES_PER_HOUR - 1, static::SECONDS_PER_MINUTE - 1, static::MICROSECONDS_PER_SECOND - 1); |
| 85 | } |
| 86 | public function startOfMinute() |
| 87 | { |
| 88 | return $this->setTime($this->hour, $this->minute, 0, 0); |
| 89 | } |
| 90 | public function endOfMinute() |
| 91 | { |
| 92 | return $this->setTime($this->hour, $this->minute, static::SECONDS_PER_MINUTE - 1, static::MICROSECONDS_PER_SECOND - 1); |
| 93 | } |
| 94 | public function startOfSecond() |
| 95 | { |
| 96 | return $this->setTime($this->hour, $this->minute, $this->second, 0); |
| 97 | } |
| 98 | public function endOfSecond() |
| 99 | { |
| 100 | return $this->setTime($this->hour, $this->minute, $this->second, static::MICROSECONDS_PER_SECOND - 1); |
| 101 | } |
| 102 | public function startOf($unit, ...$params) |
| 103 | { |
| 104 | $ucfUnit = \ucfirst(static::singularUnit($unit)); |
| 105 | $method = "startOf{$ucfUnit}"; |
| 106 | if (!\method_exists($this, $method)) { |
| 107 | throw new UnknownUnitException($unit); |
| 108 | } |
| 109 | return $this->{$method}(...$params); |
| 110 | } |
| 111 | public function endOf($unit, ...$params) |
| 112 | { |
| 113 | $ucfUnit = \ucfirst(static::singularUnit($unit)); |
| 114 | $method = "endOf{$ucfUnit}"; |
| 115 | if (!\method_exists($this, $method)) { |
| 116 | throw new UnknownUnitException($unit); |
| 117 | } |
| 118 | return $this->{$method}(...$params); |
| 119 | } |
| 120 | } |
| 121 |