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
IntervalStep.php
40 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 Closure; |
| 8 | use DateTimeImmutable; |
| 9 | use DateTimeInterface; |
| 10 | trait IntervalStep |
| 11 | { |
| 12 | protected $step; |
| 13 | public function getStep() : ?Closure |
| 14 | { |
| 15 | return $this->step; |
| 16 | } |
| 17 | public function setStep(?Closure $step) : void |
| 18 | { |
| 19 | $this->step = $step; |
| 20 | } |
| 21 | public function convertDate(DateTimeInterface $dateTime, bool $negated = \false) : CarbonInterface |
| 22 | { |
| 23 | $carbonDate = $dateTime instanceof CarbonInterface ? $dateTime : $this->resolveCarbon($dateTime); |
| 24 | if ($this->step) { |
| 25 | return $carbonDate->setDateTimeFrom(($this->step)($carbonDate->avoidMutation(), $negated)); |
| 26 | } |
| 27 | if ($negated) { |
| 28 | return $carbonDate->rawSub($this); |
| 29 | } |
| 30 | return $carbonDate->rawAdd($this); |
| 31 | } |
| 32 | private function resolveCarbon(DateTimeInterface $dateTime) |
| 33 | { |
| 34 | if ($dateTime instanceof DateTimeImmutable) { |
| 35 | return CarbonImmutable::instance($dateTime); |
| 36 | } |
| 37 | return Carbon::instance($dateTime); |
| 38 | } |
| 39 | } |
| 40 |