Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 399
Zeile 254... Zeile 254...
254
     * @var CarbonInterval
254
     * @var CarbonInterval
255
     */
255
     */
256
    protected $dateInterval;
256
    protected $dateInterval;
Zeile 257... Zeile 257...
257
 
257
 
-
 
258
    /**
-
 
259
     * True once __construct is finished.
-
 
260
     *
-
 
261
     * @var bool
-
 
262
     */
-
 
263
    protected $constructed = false;
-
 
264
 
258
    /**
265
    /**
259
     * Whether current date interval was set by default.
266
     * Whether current date interval was set by default.
260
     *
267
     *
261
     * @var bool
268
     * @var bool
262
     */
269
     */
Zeile 693... Zeile 700...
693
        }
700
        }
Zeile 694... Zeile 701...
694
 
701
 
695
        if ($this->options === null) {
702
        if ($this->options === null) {
696
            $this->setOptions(0);
703
            $this->setOptions(0);
-
 
704
        }
-
 
705
 
697
        }
706
        $this->constructed = true;
Zeile 698... Zeile 707...
698
    }
707
    }
699
 
708
 
700
    /**
709
    /**
Zeile 706... Zeile 715...
706
    {
715
    {
707
        return clone $this;
716
        return clone $this;
708
    }
717
    }
Zeile 709... Zeile 718...
709
 
718
 
-
 
719
    /**
-
 
720
     * Prepare the instance to be set (self if mutable to be mutated,
-
 
721
     * copy if immutable to generate a new instance).
-
 
722
     *
-
 
723
     * @return static
-
 
724
     */
-
 
725
    protected function copyIfImmutable()
-
 
726
    {
-
 
727
        return $this;
-
 
728
    }
-
 
729
 
710
    /**
730
    /**
711
     * Get the getter for a property allowing both `DatePeriod` snakeCase and camelCase names.
731
     * Get the getter for a property allowing both `DatePeriod` snakeCase and camelCase names.
712
     *
732
     *
713
     * @param string $name
733
     * @param string $name
714
     *
734
     *
Zeile 796... Zeile 816...
796
    /**
816
    /**
797
     * Set the iteration item class.
817
     * Set the iteration item class.
798
     *
818
     *
799
     * @param string $dateClass
819
     * @param string $dateClass
800
     *
820
     *
801
     * @return $this
821
     * @return static
802
     */
822
     */
803
    public function setDateClass(string $dateClass)
823
    public function setDateClass(string $dateClass)
804
    {
824
    {
805
        if (!is_a($dateClass, CarbonInterface::class, true)) {
825
        if (!is_a($dateClass, CarbonInterface::class, true)) {
806
            throw new NotACarbonClassException($dateClass);
826
            throw new NotACarbonClassException($dateClass);
807
        }
827
        }
Zeile -... Zeile 828...
-
 
828
 
808
 
829
        $self = $this->copyIfImmutable();
Zeile 809... Zeile 830...
809
        $this->dateClass = $dateClass;
830
        $self->dateClass = $dateClass;
810
 
831
 
811
        if (is_a($dateClass, Carbon::class, true)) {
832
        if (is_a($dateClass, Carbon::class, true)) {
812
            $this->toggleOptions(static::IMMUTABLE, false);
833
            $self->options = $self->options & ~static::IMMUTABLE;
813
        } elseif (is_a($dateClass, CarbonImmutable::class, true)) {
834
        } elseif (is_a($dateClass, CarbonImmutable::class, true)) {
Zeile 814... Zeile 835...
814
            $this->toggleOptions(static::IMMUTABLE, true);
835
            $self->options = $self->options | static::IMMUTABLE;
815
        }
836
        }
Zeile 816... Zeile 837...
816
 
837
 
817
        return $this;
838
        return $self;
818
    }
839
    }
Zeile 832... Zeile 853...
832
     *
853
     *
833
     * @param DateInterval|string $interval
854
     * @param DateInterval|string $interval
834
     *
855
     *
835
     * @throws InvalidIntervalException
856
     * @throws InvalidIntervalException
836
     *
857
     *
837
     * @return $this
858
     * @return static
838
     */
859
     */
839
    public function setDateInterval($interval)
860
    public function setDateInterval($interval)
840
    {
861
    {
841
        if (!$interval = CarbonInterval::make($interval)) {
862
        if (!$interval = CarbonInterval::make($interval)) {
842
            throw new InvalidIntervalException('Invalid interval.');
863
            throw new InvalidIntervalException('Invalid interval.');
Zeile 844... Zeile 865...
844
 
865
 
845
        if ($interval->spec() === 'PT0S' && !$interval->f && !$interval->getStep()) {
866
        if ($interval->spec() === 'PT0S' && !$interval->f && !$interval->getStep()) {
846
            throw new InvalidIntervalException('Empty interval is not accepted.');
867
            throw new InvalidIntervalException('Empty interval is not accepted.');
Zeile -... Zeile 868...
-
 
868
        }
847
        }
869
 
Zeile 848... Zeile 870...
848
 
870
        $self = $this->copyIfImmutable();
Zeile 849... Zeile 871...
849
        $this->dateInterval = $interval;
871
        $self->dateInterval = $interval;
Zeile 850... Zeile 872...
850
 
872
 
851
        $this->isDefaultInterval = false;
873
        $self->isDefaultInterval = false;
Zeile 852... Zeile 874...
852
 
874
 
853
        $this->handleChangedParameters();
875
        $self->handleChangedParameters();
854
 
876
 
855
        return $this;
877
        return $self;
856
    }
878
    }
857
 
879
 
858
    /**
880
    /**
859
     * Invert the period date interval.
-
 
860
     *
-
 
861
     * @return $this
881
     * Invert the period date interval.
862
     */
882
     *
Zeile 863... Zeile 883...
863
    public function invertDateInterval()
883
     * @return static
864
    {
884
     */
865
        $interval = $this->dateInterval->invert();
885
    public function invertDateInterval()
866
 
886
    {
867
        return $this->setDateInterval($interval);
887
        return $this->setDateInterval($this->dateInterval->invert());
868
    }
888
    }
869
 
889
 
870
    /**
890
    /**
871
     * Set start and end date.
891
     * Set start and end date.
872
     *
892
     *
873
     * @param DateTime|DateTimeInterface|string      $start
893
     * @param DateTime|DateTimeInterface|string      $start
874
     * @param DateTime|DateTimeInterface|string|null $end
-
 
875
     *
-
 
876
     * @return $this
-
 
877
     */
894
     * @param DateTime|DateTimeInterface|string|null $end
Zeile 878... Zeile 895...
878
    public function setDates($start, $end)
895
     *
879
    {
896
     * @return static
880
        $this->setStartDate($start);
897
     */
881
        $this->setEndDate($end);
898
    public function setDates($start, $end)
882
 
899
    {
883
        return $this;
900
        return $this->setStartDate($start)->setEndDate($end);
884
    }
901
    }
885
 
902
 
886
    /**
903
    /**
887
     * Change the period options.
904
     * Change the period options.
888
     *
905
     *
889
     * @param int|null $options
906
     * @param int|null $options
890
     *
907
     *
891
     * @throws InvalidArgumentException
908
     * @throws InvalidArgumentException
Zeile -... Zeile 909...
-
 
909
     *
892
     *
910
     * @return static
Zeile 893... Zeile 911...
893
     * @return $this
911
     */
Zeile 894... Zeile 912...
894
     */
912
    public function setOptions($options)
895
    public function setOptions($options)
913
    {
Zeile 896... Zeile 914...
896
    {
914
        if (!\is_int($options) && $options !== null) {
897
        if (!\is_int($options) && $options !== null) {
915
            throw new InvalidPeriodParameterException('Invalid options.');
898
            throw new InvalidPeriodParameterException('Invalid options.');
916
        }
Zeile 921... Zeile 939...
921
     * @param int       $options
939
     * @param int       $options
922
     * @param bool|null $state
940
     * @param bool|null $state
923
     *
941
     *
924
     * @throws \InvalidArgumentException
942
     * @throws \InvalidArgumentException
925
     *
943
     *
926
     * @return $this
944
     * @return static
927
     */
945
     */
928
    public function toggleOptions($options, $state = null)
946
    public function toggleOptions($options, $state = null)
929
    {
947
    {
930
        if ($state === null) {
948
        if ($state === null) {
931
            $state = ($this->options & $options) !== $options;
949
            $state = ($this->options & $options) !== $options;
Zeile 941... Zeile 959...
941
    /**
959
    /**
942
     * Toggle EXCLUDE_START_DATE option.
960
     * Toggle EXCLUDE_START_DATE option.
943
     *
961
     *
944
     * @param bool $state
962
     * @param bool $state
945
     *
963
     *
946
     * @return $this
964
     * @return static
947
     */
965
     */
948
    public function excludeStartDate($state = true)
966
    public function excludeStartDate($state = true)
949
    {
967
    {
950
        return $this->toggleOptions(static::EXCLUDE_START_DATE, $state);
968
        return $this->toggleOptions(static::EXCLUDE_START_DATE, $state);
951
    }
969
    }
Zeile 953... Zeile 971...
953
    /**
971
    /**
954
     * Toggle EXCLUDE_END_DATE option.
972
     * Toggle EXCLUDE_END_DATE option.
955
     *
973
     *
956
     * @param bool $state
974
     * @param bool $state
957
     *
975
     *
958
     * @return $this
976
     * @return static
959
     */
977
     */
960
    public function excludeEndDate($state = true)
978
    public function excludeEndDate($state = true)
961
    {
979
    {
962
        return $this->toggleOptions(static::EXCLUDE_END_DATE, $state);
980
        return $this->toggleOptions(static::EXCLUDE_END_DATE, $state);
963
    }
981
    }
Zeile 1097... Zeile 1115...
1097
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
1115
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
1098
     *
1116
     *
1099
     * @param callable $callback
1117
     * @param callable $callback
1100
     * @param string   $name
1118
     * @param string   $name
1101
     *
1119
     *
1102
     * @return $this
1120
     * @return static
1103
     */
1121
     */
1104
    public function addFilter($callback, $name = null)
1122
    public function addFilter($callback, $name = null)
1105
    {
1123
    {
-
 
1124
        $self = $this->copyIfImmutable();
1106
        $tuple = $this->createFilterTuple(\func_get_args());
1125
        $tuple = $self->createFilterTuple(\func_get_args());
Zeile 1107... Zeile 1126...
1107
 
1126
 
Zeile 1108... Zeile 1127...
1108
        $this->filters[] = $tuple;
1127
        $self->filters[] = $tuple;
Zeile 1109... Zeile 1128...
1109
 
1128
 
1110
        $this->handleChangedParameters();
1129
        $self->handleChangedParameters();
Zeile 1111... Zeile 1130...
1111
 
1130
 
1112
        return $this;
1131
        return $self;
1113
    }
1132
    }
1114
 
1133
 
1115
    /**
1134
    /**
1116
     * Prepend a filter to the stack.
1135
     * Prepend a filter to the stack.
1117
     *
1136
     *
1118
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
1137
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
1119
     *
1138
     *
1120
     * @param callable $callback
1139
     * @param callable $callback
1121
     * @param string   $name
1140
     * @param string   $name
1122
     *
1141
     *
-
 
1142
     * @return static
1123
     * @return $this
1143
     */
Zeile 1124... Zeile 1144...
1124
     */
1144
    public function prependFilter($callback, $name = null)
Zeile 1125... Zeile 1145...
1125
    public function prependFilter($callback, $name = null)
1145
    {
Zeile 1126... Zeile 1146...
1126
    {
1146
        $self = $this->copyIfImmutable();
1127
        $tuple = $this->createFilterTuple(\func_get_args());
1147
        $tuple = $self->createFilterTuple(\func_get_args());
Zeile 1128... Zeile 1148...
1128
 
1148
 
1129
        array_unshift($this->filters, $tuple);
1149
        array_unshift($self->filters, $tuple);
1130
 
1150
 
1131
        $this->handleChangedParameters();
1151
        $self->handleChangedParameters();
1132
 
1152
 
1133
        return $this;
1153
        return $self;
1134
    }
1154
    }
1135
 
1155
 
1136
    /**
1156
    /**
-
 
1157
     * Remove a filter by instance or name.
1137
     * Remove a filter by instance or name.
1158
     *
Zeile 1138... Zeile 1159...
1138
     *
1159
     * @param callable|string $filter
1139
     * @param callable|string $filter
1160
     *
1140
     *
1161
     * @return static
1141
     * @return $this
1162
     */
1142
     */
1163
    public function removeFilter($filter)
1143
    public function removeFilter($filter)
1164
    {
Zeile 1144... Zeile 1165...
1144
    {
1165
        $self = $this->copyIfImmutable();
Zeile 1145... Zeile 1166...
1145
        $key = \is_callable($filter) ? 0 : 1;
1166
        $key = \is_callable($filter) ? 0 : 1;
Zeile 1146... Zeile 1167...
1146
 
1167
 
1147
        $this->filters = array_values(array_filter(
1168
        $self->filters = array_values(array_filter(
Zeile 1148... Zeile 1169...
1148
            $this->filters,
1169
            $this->filters,
1149
            function ($tuple) use ($key, $filter) {
1170
            function ($tuple) use ($key, $filter) {
1150
                return $tuple[$key] !== $filter;
1171
                return $tuple[$key] !== $filter;
Zeile 1191... Zeile 1212...
1191
    /**
1212
    /**
1192
     * Set filters stack.
1213
     * Set filters stack.
1193
     *
1214
     *
1194
     * @param array $filters
1215
     * @param array $filters
1195
     *
1216
     *
1196
     * @return $this
1217
     * @return static
1197
     */
1218
     */
1198
    public function setFilters(array $filters)
1219
    public function setFilters(array $filters)
1199
    {
1220
    {
-
 
1221
        $self = $this->copyIfImmutable();
1200
        $this->filters = $filters;
1222
        $self->filters = $filters;
Zeile 1201... Zeile 1223...
1201
 
1223
 
Zeile 1202... Zeile 1224...
1202
        $this->updateInternalState();
1224
        $self->updateInternalState();
Zeile 1203... Zeile 1225...
1203
 
1225
 
1204
        $this->handleChangedParameters();
1226
        $self->handleChangedParameters();
Zeile 1205... Zeile 1227...
1205
 
1227
 
1206
        return $this;
1228
        return $self;
1207
    }
1229
    }
1208
 
1230
 
1209
    /**
1231
    /**
1210
     * Reset filters stack.
1232
     * Reset filters stack.
1211
     *
1233
     *
-
 
1234
     * @return static
1212
     * @return $this
1235
     */
Zeile 1213... Zeile 1236...
1213
     */
1236
    public function resetFilters()
1214
    public function resetFilters()
1237
    {
1215
    {
1238
        $self = $this->copyIfImmutable();
Zeile 1216... Zeile 1239...
1216
        $this->filters = [];
1239
        $self->filters = [];
1217
 
1240
 
1218
        if ($this->endDate !== null) {
1241
        if ($self->endDate !== null) {
Zeile 1219... Zeile 1242...
1219
            $this->filters[] = [static::END_DATE_FILTER, null];
1242
            $self->filters[] = [static::END_DATE_FILTER, null];
Zeile 1220... Zeile 1243...
1220
        }
1243
        }
1221
 
1244
 
Zeile 1222... Zeile 1245...
1222
        if ($this->recurrences !== null) {
1245
        if ($self->recurrences !== null) {
1223
            $this->filters[] = [static::RECURRENCES_FILTER, null];
1246
            $self->filters[] = [static::RECURRENCES_FILTER, null];
1224
        }
1247
        }
1225
 
1248
 
1226
        $this->handleChangedParameters();
1249
        $self->handleChangedParameters();
1227
 
1250
 
1228
        return $this;
1251
        return $self;
1229
    }
1252
    }
1230
 
1253
 
1231
    /**
1254
    /**
1232
     * Add a recurrences filter (set maximum number of recurrences).
1255
     * Add a recurrences filter (set maximum number of recurrences).
1233
     *
1256
     *
1234
     * @param int|float|null $recurrences
1257
     * @param int|float|null $recurrences
Zeile 1245... Zeile 1268...
1245
 
1268
 
1246
        if ($recurrences === null) {
1269
        if ($recurrences === null) {
1247
            return $this->removeFilter(static::RECURRENCES_FILTER);
1270
            return $this->removeFilter(static::RECURRENCES_FILTER);
Zeile -... Zeile 1271...
-
 
1271
        }
-
 
1272
 
1248
        }
1273
        /** @var self $self */
Zeile 1249... Zeile 1274...
1249
 
1274
        $self = $this->copyIfImmutable();
1250
        $this->recurrences = $recurrences === INF ? INF : (int) $recurrences;
1275
        $self->recurrences = $recurrences === INF ? INF : (int) $recurrences;
1251
 
1276
 
Zeile 1252... Zeile 1277...
1252
        if (!$this->hasFilter(static::RECURRENCES_FILTER)) {
1277
        if (!$self->hasFilter(static::RECURRENCES_FILTER)) {
Zeile 1253... Zeile 1278...
1253
            return $this->addFilter(static::RECURRENCES_FILTER);
1278
            return $self->addFilter(static::RECURRENCES_FILTER);
1254
        }
1279
        }
Zeile 1255... Zeile 1280...
1255
 
1280
 
1256
        $this->handleChangedParameters();
1281
        $self->handleChangedParameters();
1257
 
1282
 
1258
        return $this;
1283
        return $self;
1259
    }
1284
    }
1260
 
1285
 
1261
    /**
1286
    /**
1262
     * Change the period start date.
1287
     * Change the period start date.
1263
     *
1288
     *
1264
     * @param DateTime|DateTimeInterface|string $date
1289
     * @param DateTime|DateTimeInterface|string $date
1265
     * @param bool|null                         $inclusive
1290
     * @param bool|null                         $inclusive
1266
     *
1291
     *
1267
     * @throws InvalidPeriodDateException
1292
     * @throws InvalidPeriodDateException
1268
     *
1293
     *
1269
     * @return $this
1294
     * @return static
Zeile -... Zeile 1295...
-
 
1295
     */
1270
     */
1296
    public function setStartDate($date, $inclusive = null)
Zeile 1271... Zeile 1297...
1271
    public function setStartDate($date, $inclusive = null)
1297
    {
1272
    {
1298
        if (!$this->isInfiniteDate($date) && !($date = ([$this->dateClass, 'make'])($date))) {
1273
        if (!$this->isInfiniteDate($date) && !($date = ([$this->dateClass, 'make'])($date))) {
1299
            throw new InvalidPeriodDateException('Invalid start date.');
Zeile 1274... Zeile 1300...
1274
            throw new InvalidPeriodDateException('Invalid start date.');
1300
        }
1275
        }
1301
 
Zeile 1276... Zeile 1302...
1276
 
1302
        $self = $this->copyIfImmutable();
1277
        $this->startDate = $date;
1303
        $self->startDate = $date;
1278
 
1304
 
1279
        if ($inclusive !== null) {
1305
        if ($inclusive !== null) {
1280
            $this->toggleOptions(static::EXCLUDE_START_DATE, !$inclusive);
1306
            $self = $self->toggleOptions(static::EXCLUDE_START_DATE, !$inclusive);
1281
        }
1307
        }
1282
 
1308
 
1283
        return $this;
1309
        return $self;
1284
    }
1310
    }
1285
 
1311
 
1286
    /**
1312
    /**
1287
     * Change the period end date.
1313
     * Change the period end date.
1288
     *
1314
     *
1289
     * @param DateTime|DateTimeInterface|string|null $date
1315
     * @param DateTime|DateTimeInterface|string|null $date
Zeile 1301... Zeile 1327...
1301
 
1327
 
1302
        if (!$date) {
1328
        if (!$date) {
1303
            return $this->removeFilter(static::END_DATE_FILTER);
1329
            return $this->removeFilter(static::END_DATE_FILTER);
Zeile -... Zeile 1330...
-
 
1330
        }
1304
        }
1331
 
Zeile 1305... Zeile 1332...
1305
 
1332
        $self = $this->copyIfImmutable();
1306
        $this->endDate = $date;
1333
        $self->endDate = $date;
1307
 
1334
 
Zeile 1308... Zeile 1335...
1308
        if ($inclusive !== null) {
1335
        if ($inclusive !== null) {
1309
            $this->toggleOptions(static::EXCLUDE_END_DATE, !$inclusive);
1336
            $self = $self->toggleOptions(static::EXCLUDE_END_DATE, !$inclusive);
1310
        }
1337
        }
Zeile 1311... Zeile 1338...
1311
 
1338
 
Zeile 1312... Zeile 1339...
1312
        if (!$this->hasFilter(static::END_DATE_FILTER)) {
1339
        if (!$self->hasFilter(static::END_DATE_FILTER)) {
1313
            return $this->addFilter(static::END_DATE_FILTER);
1340
            return $self->addFilter(static::END_DATE_FILTER);
Zeile 1314... Zeile 1341...
1314
        }
1341
        }
1315
 
1342
 
1316
        $this->handleChangedParameters();
1343
        $self->handleChangedParameters();
Zeile 1798... Zeile 1825...
1798
     *
1825
     *
1799
     * @return static
1826
     * @return static
1800
     */
1827
     */
1801
    public function setTimezone($timezone)
1828
    public function setTimezone($timezone)
1802
    {
1829
    {
-
 
1830
        $self = $this->copyIfImmutable();
1803
        $this->tzName = $timezone;
1831
        $self->tzName = $timezone;
1804
        $this->timezone = $timezone;
1832
        $self->timezone = $timezone;
Zeile 1805... Zeile 1833...
1805
 
1833
 
1806
        if ($this->startDate) {
1834
        if ($self->startDate) {
1807
            $this->setStartDate($this->startDate->setTimezone($timezone));
1835
            $self = $self->setStartDate($self->startDate->setTimezone($timezone));
Zeile 1808... Zeile 1836...
1808
        }
1836
        }
1809
 
1837
 
1810
        if ($this->endDate) {
1838
        if ($self->endDate) {
Zeile 1811... Zeile 1839...
1811
            $this->setEndDate($this->endDate->setTimezone($timezone));
1839
            $self = $self->setEndDate($self->endDate->setTimezone($timezone));
1812
        }
1840
        }
Zeile 1813... Zeile 1841...
1813
 
1841
 
1814
        return $this;
1842
        return $self;
1815
    }
1843
    }
Zeile 1821... Zeile 1849...
1821
     *
1849
     *
1822
     * @return static
1850
     * @return static
1823
     */
1851
     */
1824
    public function shiftTimezone($timezone)
1852
    public function shiftTimezone($timezone)
1825
    {
1853
    {
-
 
1854
        $self = $this->copyIfImmutable();
1826
        $this->tzName = $timezone;
1855
        $self->tzName = $timezone;
1827
        $this->timezone = $timezone;
1856
        $self->timezone = $timezone;
Zeile 1828... Zeile 1857...
1828
 
1857
 
1829
        if ($this->startDate) {
1858
        if ($self->startDate) {
1830
            $this->setStartDate($this->startDate->shiftTimezone($timezone));
1859
            $self = $self->setStartDate($self->startDate->shiftTimezone($timezone));
Zeile 1831... Zeile 1860...
1831
        }
1860
        }
1832
 
1861
 
1833
        if ($this->endDate) {
1862
        if ($self->endDate) {
Zeile 1834... Zeile 1863...
1834
            $this->setEndDate($this->endDate->shiftTimezone($timezone));
1863
            $self = $self->setEndDate($self->endDate->shiftTimezone($timezone));
1835
        }
1864
        }
Zeile 1836... Zeile 1865...
1836
 
1865
 
1837
        return $this;
1866
        return $self;
1838
    }
1867
    }
Zeile 2211... Zeile 2240...
2211
     *
2240
     *
2212
     * @param string                              $unit
2241
     * @param string                              $unit
2213
     * @param float|int|string|\DateInterval|null $precision
2242
     * @param float|int|string|\DateInterval|null $precision
2214
     * @param string                              $function
2243
     * @param string                              $function
2215
     *
2244
     *
2216
     * @return $this
2245
     * @return static
2217
     */
2246
     */
2218
    public function roundUnit($unit, $precision = 1, $function = 'round')
2247
    public function roundUnit($unit, $precision = 1, $function = 'round')
2219
    {
2248
    {
-
 
2249
        $self = $this->copyIfImmutable();
2220
        $this->setStartDate($this->getStartDate()->roundUnit($unit, $precision, $function));
2250
        $self = $self->setStartDate($self->getStartDate()->roundUnit($unit, $precision, $function));
Zeile 2221... Zeile 2251...
2221
 
2251
 
2222
        if ($this->endDate) {
2252
        if ($self->endDate) {
2223
            $this->setEndDate($this->getEndDate()->roundUnit($unit, $precision, $function));
2253
            $self = $self->setEndDate($self->getEndDate()->roundUnit($unit, $precision, $function));
Zeile 2224... Zeile 2254...
2224
        }
2254
        }
2225
 
-
 
2226
        $this->setDateInterval($this->getDateInterval()->roundUnit($unit, $precision, $function));
-
 
2227
 
2255
 
Zeile 2228... Zeile 2256...
2228
        return $this;
2256
        return $self->setDateInterval($self->getDateInterval()->roundUnit($unit, $precision, $function));
2229
    }
2257
    }
2230
 
2258
 
2231
    /**
2259
    /**
2232
     * Truncate the current instance at the given unit with given precision if specified.
2260
     * Truncate the current instance at the given unit with given precision if specified.
2233
     *
2261
     *
2234
     * @param string                              $unit
2262
     * @param string                              $unit
2235
     * @param float|int|string|\DateInterval|null $precision
2263
     * @param float|int|string|\DateInterval|null $precision
2236
     *
2264
     *
2237
     * @return $this
2265
     * @return static
2238
     */
2266
     */
2239
    public function floorUnit($unit, $precision = 1)
2267
    public function floorUnit($unit, $precision = 1)
Zeile 2245... Zeile 2273...
2245
     * Ceil the current instance at the given unit with given precision if specified.
2273
     * Ceil the current instance at the given unit with given precision if specified.
2246
     *
2274
     *
2247
     * @param string                              $unit
2275
     * @param string                              $unit
2248
     * @param float|int|string|\DateInterval|null $precision
2276
     * @param float|int|string|\DateInterval|null $precision
2249
     *
2277
     *
2250
     * @return $this
2278
     * @return static
2251
     */
2279
     */
2252
    public function ceilUnit($unit, $precision = 1)
2280
    public function ceilUnit($unit, $precision = 1)
2253
    {
2281
    {
2254
        return $this->roundUnit($unit, $precision, 'ceil');
2282
        return $this->roundUnit($unit, $precision, 'ceil');
2255
    }
2283
    }
Zeile 2258... Zeile 2286...
2258
     * Round the current instance second with given precision if specified (else period interval is used).
2286
     * Round the current instance second with given precision if specified (else period interval is used).
2259
     *
2287
     *
2260
     * @param float|int|string|\DateInterval|null $precision
2288
     * @param float|int|string|\DateInterval|null $precision
2261
     * @param string                              $function
2289
     * @param string                              $function
2262
     *
2290
     *
2263
     * @return $this
2291
     * @return static
2264
     */
2292
     */
2265
    public function round($precision = null, $function = 'round')
2293
    public function round($precision = null, $function = 'round')
2266
    {
2294
    {
2267
        return $this->roundWith(
2295
        return $this->roundWith(
2268
            $precision ?? $this->getDateInterval()->setLocalTranslator(TranslatorImmutable::get('en'))->forHumans(),
2296
            $precision ?? $this->getDateInterval()->setLocalTranslator(TranslatorImmutable::get('en'))->forHumans(),
Zeile 2273... Zeile 2301...
2273
    /**
2301
    /**
2274
     * Round the current instance second with given precision if specified (else period interval is used).
2302
     * Round the current instance second with given precision if specified (else period interval is used).
2275
     *
2303
     *
2276
     * @param float|int|string|\DateInterval|null $precision
2304
     * @param float|int|string|\DateInterval|null $precision
2277
     *
2305
     *
2278
     * @return $this
2306
     * @return static
2279
     */
2307
     */
2280
    public function floor($precision = null)
2308
    public function floor($precision = null)
2281
    {
2309
    {
2282
        return $this->round($precision, 'floor');
2310
        return $this->round($precision, 'floor');
2283
    }
2311
    }
Zeile 2285... Zeile 2313...
2285
    /**
2313
    /**
2286
     * Ceil the current instance second with given precision if specified (else period interval is used).
2314
     * Ceil the current instance second with given precision if specified (else period interval is used).
2287
     *
2315
     *
2288
     * @param float|int|string|\DateInterval|null $precision
2316
     * @param float|int|string|\DateInterval|null $precision
2289
     *
2317
     *
2290
     * @return $this
2318
     * @return static
2291
     */
2319
     */
2292
    public function ceil($precision = null)
2320
    public function ceil($precision = null)
2293
    {
2321
    {
2294
        return $this->round($precision, 'ceil');
2322
        return $this->round($precision, 'ceil');
2295
    }
2323
    }
Zeile 2474... Zeile 2502...
2474
     * Handle change of the parameters.
2502
     * Handle change of the parameters.
2475
     */
2503
     */
2476
    protected function handleChangedParameters()
2504
    protected function handleChangedParameters()
2477
    {
2505
    {
2478
        if (($this->getOptions() & static::IMMUTABLE) && $this->dateClass === Carbon::class) {
2506
        if (($this->getOptions() & static::IMMUTABLE) && $this->dateClass === Carbon::class) {
2479
            $this->setDateClass(CarbonImmutable::class);
2507
            $this->dateClass = CarbonImmutable::class;
2480
        } elseif (!($this->getOptions() & static::IMMUTABLE) && $this->dateClass === CarbonImmutable::class) {
2508
        } elseif (!($this->getOptions() & static::IMMUTABLE) && $this->dateClass === CarbonImmutable::class) {
2481
            $this->setDateClass(Carbon::class);
2509
            $this->dateClass = Carbon::class;
2482
        }
2510
        }
Zeile 2483... Zeile 2511...
2483
 
2511
 
2484
        $this->validationResult = null;
2512
        $this->validationResult = null;