PluginProbe ʕ •ᴥ•ʔ
MailPoet – Newsletters, Email Marketing, and Automation / 5.35.1
MailPoet – Newsletters, Email Marketing, and Automation v5.35.1
5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 4.44.0 4.44.1 4.45.0 4.46.0 4.47.0 4.48.0 4.48.1 4.48.2 4.49.0 4.49.1 4.5.0 4.5.1 4.5.2 4.50.0 4.50.1 4.51.0 4.51.1 4.51.2 4.52.0 4.53.0 4.54.0 4.55.0 4.56.0 4.57.0 4.58.0 4.58.1 4.58.2 4.6.0 4.6.1 4.6.2 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 5.0.0 5.0.1 5.0.2 5.1.0 5.1.1 5.10.0 5.10.1 5.11.0 5.12.0 5.12.1 5.12.10 5.12.11 5.12.12 5.12.13 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13.0 5.13.1 5.13.2 5.14.0 5.14.1 5.14.2 5.14.3 5.15.0 5.15.1 5.16.0 5.16.1 5.16.2 5.16.3 5.16.4 5.17.0 5.17.1 5.17.2 5.17.3 5.17.4 5.17.5 5.17.6 5.18.0 5.19.0 5.2.0 5.2.1 5.2.2 5.2.3 5.20.0 5.21.0 5.21.1 5.21.2 5.21.3 5.22.0 5.22.1 5.22.2 5.22.3 5.22.4 5.23.0 5.23.1 5.23.2 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.3.7 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.6.3 5.6.4 5.7.0 5.7.1 5.8.0 5.8.1 5.9.0 3.0.0-beta.15 3.7.1 3.0.0-beta.16 3.7.2 3.0.0-beta.17 3.7.3 3.0.0-beta.18 3.7.4 3.0.0-beta.19 3.7.5 3.0.0-beta.2 3.7.6 3.0.0-beta.20 3.7.8 3.0.0-beta.21 3.70.0 3.0.0-beta.22 3.71.0 3.0.0-beta.23 3.71.1 3.0.0-beta.23.1 3.71.2 3.0.0-beta.23.2 3.71.3 3.0.0-beta.24 3.72.0 3.0.0-beta.25 3.73.0 3.0.0-beta.26 3.73.1 3.0.0-beta.27 3.73.2 3.0.0-beta.28 3.74.0 3.0.0-beta.29 3.74.1 3.0.0-beta.3 3.74.2 3.0.0-beta.30 3.74.3 3.0.0-beta.31 3.75.0 3.0.0-beta.32 3.75.1 3.0.0-beta.33 3.76.0 3.0.0-beta.33.1 3.77.0 3.0.0-beta.34.0.0 3.77.1 3.0.0-beta.36.0.0 3.78.0 3.0.0-beta.36.0.1 3.79.0 3.0.0-beta.36.2.0 3.8 3.0.0-beta.36.3.0 3.8.1 3.0.0-beta.36.3.1 3.8.2 3.0.0-beta.37.0.0 3.8.3 3.0.0-beta.4 3.8.4 3.0.0-beta.5 3.8.5 3.0.0-beta.6 3.8.6 3.0.0-beta.7 3.80.0 3.0.0-beta.7.1 3.81.0 3.0.0-beta.8 3.82.0 3.0.0-beta.9 3.83.0 3.0.0-rc.1.0.0 3.84.0 3.0.0-rc.1.0.1 3.84.1 3.0.0-rc.1.0.2 3.85.0 3.0.0-rc.1.0.3 3.85.1 3.0.0-rc.1.0.4 3.86.0 3.0.0-rc.2.0.0 3.87.0 3.0.0-rc.2.0.1 3.87.1 3.0.0-rc.2.0.2 3.87.2 3.0.0-rc.2.0.3 3.88.0 3.0.1 3.88.1 3.0.2 3.88.2 3.0.3 3.89.0 3.0.4 3.89.1 3.0.5 3.89.2 3.0.6 3.89.3 3.0.7 3.89.4 3.0.8 3.9.0 3.0.9 3.9.1 3.1.0 3.90.0 3.10 3.90.1 3.10.1 3.90.2 3.100.0 3.91.0 3.100.1 3.91.1 3.100.2 3.92.0 3.101.0 3.92.1 3.101.1 3.93.0 3.102.0 3.93.1 3.102.1 3.94.0 3.103.0 3.95.0 3.103.1 3.95.1 3.11.0 3.96.0 3.11.1 3.96.1 3.11.2 3.97.0 3.11.3 3.98.0 3.11.4 3.98.1 3.11.5 3.99.0 3.12.0 3.99.1 3.12.1 4.0.0 3.13.0 4.0.1 3.14.0 4.1.0 3.14.1 4.1.1 3.15.0 4.10.0 3.16.0 4.11.0 3.16.1 4.11.1 3.16.2 4.12.0 3.16.3 4.12.1 3.17.0 4.12.2 3.17.1 4.13.0 3.17.2 4.14.0 3.18.0 4.15.0 3.18.1 4.16.0 3.18.2 4.17.0 3.19.0 4.17.1 3.19.1 4.18.0 3.19.2 4.18.1 3.19.3 4.19.0 3.2.0 4.2.0 3.2.1 4.20.0 3.2.2 4.20.1 3.2.3 4.20.2 3.2.4 4.21.0 3.2.5 4.22.0 3.20.0 4.22.1 3.21.0 4.22.2 3.21.1 4.23.0 3.22.0 4.24.0 3.23.0 4.25.0 3.23.1 4.26.0 3.23.2 4.26.1 3.24.0 4.27.0 3.25.0 4.28.0 3.25.1 4.29.0 3.26.0 4.3.0 3.26.1 4.3.1 3.27.0 4.30.0 3.28.0 4.31.0 3.29.0 4.31.1 3.3.0 4.32.0 3.3.1 4.33.0 3.3.2 4.34.0 3.3.3 4.35.0 3.3.4 4.35.1 3.3.5 4.36.0 3.3.6 4.37.0 3.30.0 4.38.0 3.31.0 4.39.0 3.31.1 4.4.0 3.32.0 4.40.0 3.32.1 4.41.0 3.32.2 4.41.1 3.33.0 4.41.2 3.34.0 4.41.3 3.34.1 4.42.0 3.34.2 4.42.1 3.34.3 3.34.4 3.35.0 3.35.1 3.35.3 3.35.4 3.36.0 3.37.0 3.37.1 3.37.2 3.37.3 3.38.0 3.38.1 3.39.0 3.39.1 3.39.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.40.0 3.40.1 3.41.0 3.41.1 3.41.2 3.42.0 3.42.1 3.42.2 3.42.3 3.43.0 3.43.1 3.44.0 3.45.0 3.45.1 3.46.0 3.46.1 3.46.10 3.46.11 3.46.12 3.46.13 3.46.14 3.46.2 3.46.3 3.46.4 3.46.5 3.46.6 3.46.7 3.46.8 3.46.9 3.47.0 3.47.1 3.47.10 3.47.11 3.47.2 3.47.3 3.47.5 3.47.6 3.47.7 3.47.9 3.48.0 3.48.1 3.49.0 3.49.1 3.5.0 3.5.1 3.50.0 3.51.0 3.51.1 3.51.2 3.52.0 3.53.0 3.54.0 3.54.1 3.54.2 3.54.3 3.55.0 3.55.1 3.56.0 3.56.1 3.56.2 3.57.0 3.57.1 3.58.0 3.59.0 3.59.1 3.59.2 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.60.0 3.60.1 3.60.10 3.60.11 3.60.12 3.60.2 3.60.3 3.60.4 3.60.6 3.60.7 3.60.8 3.60.9 3.61.0 3.62.0 3.62.1 3.63.0 3.64.0 3.64.1 3.64.2 3.64.3 3.65.0 trunk 3.65.1 3.0.0 3.66.0 3.0.0-beta.1 3.67.0 3.0.0-beta.10 3.67.1 3.0.0-beta.11 3.68.0 3.0.0-beta.12 3.69.0 3.0.0-beta.13 3.69.1 3.0.0-beta.14 3.7.0
mailpoet / vendor-prefixed / nesbot / carbon / src / Carbon / Traits / Difference.php
mailpoet / vendor-prefixed / nesbot / carbon / src / Carbon / Traits Last commit date
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 8 months ago DeprecatedProperties.php 4 years ago Difference.php 2 years ago IntervalRounding.php 2 years ago IntervalStep.php 4 years ago Localization.php 8 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 8 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
Difference.php
426 lines
1 <?php
2 namespace MailPoetVendor\Carbon\Traits;
3 if (!defined('ABSPATH')) exit;
4 use MailPoetVendor\Carbon\Carbon;
5 use MailPoetVendor\Carbon\CarbonImmutable;
6 use MailPoetVendor\Carbon\CarbonInterface;
7 use MailPoetVendor\Carbon\CarbonInterval;
8 use MailPoetVendor\Carbon\CarbonPeriod;
9 use MailPoetVendor\Carbon\Translator;
10 use Closure;
11 use DateInterval;
12 use DateTimeInterface;
13 use ReturnTypeWillChange;
14 trait Difference
15 {
16 protected static function fixNegativeMicroseconds(CarbonInterval $diff)
17 {
18 if ($diff->s !== 0 || $diff->i !== 0 || $diff->h !== 0 || $diff->d !== 0 || $diff->m !== 0 || $diff->y !== 0) {
19 $diff->f = (\round($diff->f * 1000000) + 1000000) / 1000000;
20 $diff->s--;
21 if ($diff->s < 0) {
22 $diff->s += 60;
23 $diff->i--;
24 if ($diff->i < 0) {
25 $diff->i += 60;
26 $diff->h--;
27 if ($diff->h < 0) {
28 $diff->h += 24;
29 $diff->d--;
30 if ($diff->d < 0) {
31 $diff->d += 30;
32 $diff->m--;
33 if ($diff->m < 0) {
34 $diff->m += 12;
35 $diff->y--;
36 }
37 }
38 }
39 }
40 }
41 return;
42 }
43 $diff->f *= -1;
44 $diff->invert();
45 }
46 protected static function fixDiffInterval(DateInterval $diff, $absolute, array $skip = [])
47 {
48 $diff = CarbonInterval::instance($diff, $skip);
49 // Work-around for https://bugs.php.net/bug.php?id=77145
50 // @codeCoverageIgnoreStart
51 if ($diff->f > 0 && $diff->y === -1 && $diff->m === 11 && $diff->d >= 27 && $diff->h === 23 && $diff->i === 59 && $diff->s === 59) {
52 $diff->y = 0;
53 $diff->m = 0;
54 $diff->d = 0;
55 $diff->h = 0;
56 $diff->i = 0;
57 $diff->s = 0;
58 $diff->f = (1000000 - \round($diff->f * 1000000)) / 1000000;
59 $diff->invert();
60 } elseif ($diff->f < 0) {
61 static::fixNegativeMicroseconds($diff);
62 }
63 // @codeCoverageIgnoreEnd
64 if ($absolute && $diff->invert) {
65 $diff->invert();
66 }
67 return $diff;
68 }
69 #[\ReturnTypeWillChange]
70 public function diff($date = null, $absolute = \false)
71 {
72 $other = $this->resolveCarbon($date);
73 // Work-around for https://bugs.php.net/bug.php?id=81458
74 // It was initially introduced for https://bugs.php.net/bug.php?id=80998
75 // The very specific case of 80998 was fixed in PHP 8.1beta3, but it introduced 81458
76 // So we still need to keep this for now
77 // @codeCoverageIgnoreStart
78 if (\version_compare(\PHP_VERSION, '8.1.0-dev', '>=') && $other->tz !== $this->tz) {
79 $other = $other->avoidMutation()->tz($this->tz);
80 }
81 // @codeCoverageIgnoreEnd
82 return parent::diff($other, (bool) $absolute);
83 }
84 public function diffAsCarbonInterval($date = null, $absolute = \true, array $skip = [])
85 {
86 return static::fixDiffInterval($this->diff($this->resolveCarbon($date), $absolute), $absolute, $skip);
87 }
88 public function diffInYears($date = null, $absolute = \true)
89 {
90 return (int) $this->diff($this->resolveCarbon($date), $absolute)->format('%r%y');
91 }
92 public function diffInQuarters($date = null, $absolute = \true)
93 {
94 return (int) ($this->diffInMonths($date, $absolute) / static::MONTHS_PER_QUARTER);
95 }
96 public function diffInMonths($date = null, $absolute = \true)
97 {
98 $date = $this->resolveCarbon($date)->avoidMutation()->tz($this->tz);
99 [$yearStart, $monthStart, $dayStart] = \explode('-', $this->format('Y-m-dHisu'));
100 [$yearEnd, $monthEnd, $dayEnd] = \explode('-', $date->format('Y-m-dHisu'));
101 $diff = ((int) $yearEnd - (int) $yearStart) * static::MONTHS_PER_YEAR + (int) $monthEnd - (int) $monthStart;
102 if ($diff > 0) {
103 $diff -= $dayStart > $dayEnd ? 1 : 0;
104 } elseif ($diff < 0) {
105 $diff += $dayStart < $dayEnd ? 1 : 0;
106 }
107 return $absolute ? \abs($diff) : $diff;
108 }
109 public function diffInWeeks($date = null, $absolute = \true)
110 {
111 return (int) ($this->diffInDays($date, $absolute) / static::DAYS_PER_WEEK);
112 }
113 public function diffInDays($date = null, $absolute = \true)
114 {
115 return $this->getIntervalDayDiff($this->diff($this->resolveCarbon($date), $absolute));
116 }
117 public function diffInDaysFiltered(Closure $callback, $date = null, $absolute = \true)
118 {
119 return $this->diffFiltered(CarbonInterval::day(), $callback, $date, $absolute);
120 }
121 public function diffInHoursFiltered(Closure $callback, $date = null, $absolute = \true)
122 {
123 return $this->diffFiltered(CarbonInterval::hour(), $callback, $date, $absolute);
124 }
125 public function diffFiltered(CarbonInterval $ci, Closure $callback, $date = null, $absolute = \true)
126 {
127 $start = $this;
128 $end = $this->resolveCarbon($date);
129 $inverse = \false;
130 if ($end < $start) {
131 $start = $end;
132 $end = $this;
133 $inverse = \true;
134 }
135 $options = CarbonPeriod::EXCLUDE_END_DATE | ($this->isMutable() ? 0 : CarbonPeriod::IMMUTABLE);
136 $diff = $ci->toPeriod($start, $end, $options)->filter($callback)->count();
137 return $inverse && !$absolute ? -$diff : $diff;
138 }
139 public function diffInWeekdays($date = null, $absolute = \true)
140 {
141 return $this->diffInDaysFiltered(static function (CarbonInterface $date) {
142 return $date->isWeekday();
143 }, $this->resolveCarbon($date)->avoidMutation()->modify($this->format('H:i:s.u')), $absolute);
144 }
145 public function diffInWeekendDays($date = null, $absolute = \true)
146 {
147 return $this->diffInDaysFiltered(static function (CarbonInterface $date) {
148 return $date->isWeekend();
149 }, $this->resolveCarbon($date)->avoidMutation()->modify($this->format('H:i:s.u')), $absolute);
150 }
151 public function diffInHours($date = null, $absolute = \true)
152 {
153 return (int) ($this->diffInSeconds($date, $absolute) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR);
154 }
155 public function diffInRealHours($date = null, $absolute = \true)
156 {
157 return (int) ($this->diffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE / static::MINUTES_PER_HOUR);
158 }
159 public function diffInMinutes($date = null, $absolute = \true)
160 {
161 return (int) ($this->diffInSeconds($date, $absolute) / static::SECONDS_PER_MINUTE);
162 }
163 public function diffInRealMinutes($date = null, $absolute = \true)
164 {
165 return (int) ($this->diffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE);
166 }
167 public function diffInSeconds($date = null, $absolute = \true)
168 {
169 $diff = $this->diff($date);
170 if ($diff->days === 0) {
171 $diff = static::fixDiffInterval($diff, $absolute);
172 }
173 $value = ((($diff->m || $diff->y ? $diff->days : $diff->d) * static::HOURS_PER_DAY + $diff->h) * static::MINUTES_PER_HOUR + $diff->i) * static::SECONDS_PER_MINUTE + $diff->s;
174 return $absolute || !$diff->invert ? $value : -$value;
175 }
176 public function diffInMicroseconds($date = null, $absolute = \true)
177 {
178 $diff = $this->diff($date);
179 $value = (int) \round((((($diff->m || $diff->y ? $diff->days : $diff->d) * static::HOURS_PER_DAY + $diff->h) * static::MINUTES_PER_HOUR + $diff->i) * static::SECONDS_PER_MINUTE + ($diff->f + $diff->s)) * static::MICROSECONDS_PER_SECOND);
180 return $absolute || !$diff->invert ? $value : -$value;
181 }
182 public function diffInMilliseconds($date = null, $absolute = \true)
183 {
184 return (int) ($this->diffInMicroseconds($date, $absolute) / static::MICROSECONDS_PER_MILLISECOND);
185 }
186 public function diffInRealSeconds($date = null, $absolute = \true)
187 {
188 $date = $this->resolveCarbon($date);
189 $value = $date->getTimestamp() - $this->getTimestamp();
190 return $absolute ? \abs($value) : $value;
191 }
192 public function diffInRealMicroseconds($date = null, $absolute = \true)
193 {
194 $date = $this->resolveCarbon($date);
195 $value = ($date->timestamp - $this->timestamp) * static::MICROSECONDS_PER_SECOND + $date->micro - $this->micro;
196 return $absolute ? \abs($value) : $value;
197 }
198 public function diffInRealMilliseconds($date = null, $absolute = \true)
199 {
200 return (int) ($this->diffInRealMicroseconds($date, $absolute) / static::MICROSECONDS_PER_MILLISECOND);
201 }
202 public function floatDiffInSeconds($date = null, $absolute = \true)
203 {
204 return (float) ($this->diffInMicroseconds($date, $absolute) / static::MICROSECONDS_PER_SECOND);
205 }
206 public function floatDiffInMinutes($date = null, $absolute = \true)
207 {
208 return $this->floatDiffInSeconds($date, $absolute) / static::SECONDS_PER_MINUTE;
209 }
210 public function floatDiffInHours($date = null, $absolute = \true)
211 {
212 return $this->floatDiffInMinutes($date, $absolute) / static::MINUTES_PER_HOUR;
213 }
214 public function floatDiffInDays($date = null, $absolute = \true)
215 {
216 $hoursDiff = $this->floatDiffInHours($date, $absolute);
217 $interval = $this->diff($date, $absolute);
218 if ($interval->y === 0 && $interval->m === 0 && $interval->d === 0) {
219 return $hoursDiff / static::HOURS_PER_DAY;
220 }
221 $daysDiff = $this->getIntervalDayDiff($interval);
222 return $daysDiff + \fmod($hoursDiff, static::HOURS_PER_DAY) / static::HOURS_PER_DAY;
223 }
224 public function floatDiffInWeeks($date = null, $absolute = \true)
225 {
226 return $this->floatDiffInDays($date, $absolute) / static::DAYS_PER_WEEK;
227 }
228 public function floatDiffInMonths($date = null, $absolute = \true)
229 {
230 $start = $this;
231 $end = $this->resolveCarbon($date);
232 $ascending = $start <= $end;
233 $sign = $absolute || $ascending ? 1 : -1;
234 if (!$ascending) {
235 [$start, $end] = [$end, $start];
236 }
237 $monthsDiff = $start->diffInMonths($end);
238 $floorEnd = $start->avoidMutation()->addMonths($monthsDiff);
239 if ($floorEnd >= $end) {
240 return $sign * $monthsDiff;
241 }
242 $startOfMonthAfterFloorEnd = $floorEnd->avoidMutation()->addMonth()->startOfMonth();
243 if ($startOfMonthAfterFloorEnd > $end) {
244 return $sign * ($monthsDiff + $floorEnd->floatDiffInDays($end) / $floorEnd->daysInMonth);
245 }
246 return $sign * ($monthsDiff + $floorEnd->floatDiffInDays($startOfMonthAfterFloorEnd) / $floorEnd->daysInMonth + $startOfMonthAfterFloorEnd->floatDiffInDays($end) / $end->daysInMonth);
247 }
248 public function floatDiffInYears($date = null, $absolute = \true)
249 {
250 $start = $this;
251 $end = $this->resolveCarbon($date);
252 $ascending = $start <= $end;
253 $sign = $absolute || $ascending ? 1 : -1;
254 if (!$ascending) {
255 [$start, $end] = [$end, $start];
256 }
257 $yearsDiff = $start->diffInYears($end);
258 $floorEnd = $start->avoidMutation()->addYears($yearsDiff);
259 if ($floorEnd >= $end) {
260 return $sign * $yearsDiff;
261 }
262 $startOfYearAfterFloorEnd = $floorEnd->avoidMutation()->addYear()->startOfYear();
263 if ($startOfYearAfterFloorEnd > $end) {
264 return $sign * ($yearsDiff + $floorEnd->floatDiffInDays($end) / $floorEnd->daysInYear);
265 }
266 return $sign * ($yearsDiff + $floorEnd->floatDiffInDays($startOfYearAfterFloorEnd) / $floorEnd->daysInYear + $startOfYearAfterFloorEnd->floatDiffInDays($end) / $end->daysInYear);
267 }
268 public function floatDiffInRealSeconds($date = null, $absolute = \true)
269 {
270 return $this->diffInRealMicroseconds($date, $absolute) / static::MICROSECONDS_PER_SECOND;
271 }
272 public function floatDiffInRealMinutes($date = null, $absolute = \true)
273 {
274 return $this->floatDiffInRealSeconds($date, $absolute) / static::SECONDS_PER_MINUTE;
275 }
276 public function floatDiffInRealHours($date = null, $absolute = \true)
277 {
278 return $this->floatDiffInRealMinutes($date, $absolute) / static::MINUTES_PER_HOUR;
279 }
280 public function floatDiffInRealDays($date = null, $absolute = \true)
281 {
282 $date = $this->resolveUTC($date);
283 $utc = $this->avoidMutation()->utc();
284 $hoursDiff = $utc->floatDiffInRealHours($date, $absolute);
285 return ($hoursDiff < 0 ? -1 : 1) * $utc->diffInDays($date) + \fmod($hoursDiff, static::HOURS_PER_DAY) / static::HOURS_PER_DAY;
286 }
287 public function floatDiffInRealWeeks($date = null, $absolute = \true)
288 {
289 return $this->floatDiffInRealDays($date, $absolute) / static::DAYS_PER_WEEK;
290 }
291 public function floatDiffInRealMonths($date = null, $absolute = \true)
292 {
293 $start = $this;
294 $end = $this->resolveCarbon($date);
295 $ascending = $start <= $end;
296 $sign = $absolute || $ascending ? 1 : -1;
297 if (!$ascending) {
298 [$start, $end] = [$end, $start];
299 }
300 $monthsDiff = $start->diffInMonths($end);
301 $floorEnd = $start->avoidMutation()->addMonths($monthsDiff);
302 if ($floorEnd >= $end) {
303 return $sign * $monthsDiff;
304 }
305 $startOfMonthAfterFloorEnd = $floorEnd->avoidMutation()->addMonth()->startOfMonth();
306 if ($startOfMonthAfterFloorEnd > $end) {
307 return $sign * ($monthsDiff + $floorEnd->floatDiffInRealDays($end) / $floorEnd->daysInMonth);
308 }
309 return $sign * ($monthsDiff + $floorEnd->floatDiffInRealDays($startOfMonthAfterFloorEnd) / $floorEnd->daysInMonth + $startOfMonthAfterFloorEnd->floatDiffInRealDays($end) / $end->daysInMonth);
310 }
311 public function floatDiffInRealYears($date = null, $absolute = \true)
312 {
313 $start = $this;
314 $end = $this->resolveCarbon($date);
315 $ascending = $start <= $end;
316 $sign = $absolute || $ascending ? 1 : -1;
317 if (!$ascending) {
318 [$start, $end] = [$end, $start];
319 }
320 $yearsDiff = $start->diffInYears($end);
321 $floorEnd = $start->avoidMutation()->addYears($yearsDiff);
322 if ($floorEnd >= $end) {
323 return $sign * $yearsDiff;
324 }
325 $startOfYearAfterFloorEnd = $floorEnd->avoidMutation()->addYear()->startOfYear();
326 if ($startOfYearAfterFloorEnd > $end) {
327 return $sign * ($yearsDiff + $floorEnd->floatDiffInRealDays($end) / $floorEnd->daysInYear);
328 }
329 return $sign * ($yearsDiff + $floorEnd->floatDiffInRealDays($startOfYearAfterFloorEnd) / $floorEnd->daysInYear + $startOfYearAfterFloorEnd->floatDiffInRealDays($end) / $end->daysInYear);
330 }
331 public function secondsSinceMidnight()
332 {
333 return $this->diffInSeconds($this->avoidMutation()->startOfDay());
334 }
335 public function secondsUntilEndOfDay()
336 {
337 return $this->diffInSeconds($this->avoidMutation()->endOfDay());
338 }
339 public function diffForHumans($other = null, $syntax = null, $short = \false, $parts = 1, $options = null)
340 {
341 if (\is_array($other)) {
342 $other['syntax'] = \array_key_exists('syntax', $other) ? $other['syntax'] : $syntax;
343 $syntax = $other;
344 $other = $syntax['other'] ?? null;
345 }
346 $intSyntax =& $syntax;
347 if (\is_array($syntax)) {
348 $syntax['syntax'] = $syntax['syntax'] ?? null;
349 $intSyntax =& $syntax['syntax'];
350 }
351 $intSyntax = (int) ($intSyntax ?? static::DIFF_RELATIVE_AUTO);
352 $intSyntax = $intSyntax === static::DIFF_RELATIVE_AUTO && $other === null ? static::DIFF_RELATIVE_TO_NOW : $intSyntax;
353 $parts = \min(7, \max(1, (int) $parts));
354 $skip = \is_array($syntax) ? $syntax['skip'] ?? [] : [];
355 return $this->diffAsCarbonInterval($other, \false, (array) $skip)->setLocalTranslator($this->getLocalTranslator())->forHumans($syntax, (bool) $short, $parts, $options ?? $this->localHumanDiffOptions ?? static::getHumanDiffOptions());
356 }
357 public function from($other = null, $syntax = null, $short = \false, $parts = 1, $options = null)
358 {
359 return $this->diffForHumans($other, $syntax, $short, $parts, $options);
360 }
361 public function since($other = null, $syntax = null, $short = \false, $parts = 1, $options = null)
362 {
363 return $this->diffForHumans($other, $syntax, $short, $parts, $options);
364 }
365 public function to($other = null, $syntax = null, $short = \false, $parts = 1, $options = null)
366 {
367 if (!$syntax && !$other) {
368 $syntax = CarbonInterface::DIFF_RELATIVE_TO_NOW;
369 }
370 return $this->resolveCarbon($other)->diffForHumans($this, $syntax, $short, $parts, $options);
371 }
372 public function until($other = null, $syntax = null, $short = \false, $parts = 1, $options = null)
373 {
374 return $this->to($other, $syntax, $short, $parts, $options);
375 }
376 public function fromNow($syntax = null, $short = \false, $parts = 1, $options = null)
377 {
378 $other = null;
379 if ($syntax instanceof DateTimeInterface) {
380 [$other, $syntax, $short, $parts, $options] = \array_pad(\func_get_args(), 5, null);
381 }
382 return $this->from($other, $syntax, $short, $parts, $options);
383 }
384 public function toNow($syntax = null, $short = \false, $parts = 1, $options = null)
385 {
386 return $this->to(null, $syntax, $short, $parts, $options);
387 }
388 public function ago($syntax = null, $short = \false, $parts = 1, $options = null)
389 {
390 $other = null;
391 if ($syntax instanceof DateTimeInterface) {
392 [$other, $syntax, $short, $parts, $options] = \array_pad(\func_get_args(), 5, null);
393 }
394 return $this->from($other, $syntax, $short, $parts, $options);
395 }
396 public function timespan($other = null, $timezone = null)
397 {
398 if (!$other instanceof DateTimeInterface) {
399 $other = static::parse($other, $timezone);
400 }
401 return $this->diffForHumans($other, ['join' => ', ', 'syntax' => CarbonInterface::DIFF_ABSOLUTE, 'options' => CarbonInterface::NO_ZERO_DIFF, 'parts' => -1]);
402 }
403 public function calendar($referenceTime = null, array $formats = [])
404 {
405 $current = $this->avoidMutation()->startOfDay();
406 $other = $this->resolveCarbon($referenceTime)->avoidMutation()->setTimezone($this->getTimezone())->startOfDay();
407 $diff = $other->diffInDays($current, \false);
408 $format = $diff < -6 ? 'sameElse' : ($diff < -1 ? 'lastWeek' : ($diff < 0 ? 'lastDay' : ($diff < 1 ? 'sameDay' : ($diff < 2 ? 'nextDay' : ($diff < 7 ? 'nextWeek' : 'sameElse')))));
409 $format = \array_merge($this->getCalendarFormats(), $formats)[$format];
410 if ($format instanceof Closure) {
411 $format = $format($current, $other) ?? '';
412 }
413 return $this->isoFormat((string) $format);
414 }
415 private function getIntervalDayDiff(DateInterval $interval) : int
416 {
417 $daysDiff = (int) $interval->format('%a');
418 $sign = $interval->format('%r') === '-' ? -1 : 1;
419 if (\is_int($interval->days) && $interval->y === 0 && $interval->m === 0 && \version_compare(\PHP_VERSION, '8.1.0-dev', '<') && \abs($interval->d - $daysDiff) === 1) {
420 $daysDiff = \abs($interval->d);
421 // @codeCoverageIgnore
422 }
423 return $daysDiff * $sign;
424 }
425 }
426