Upstream spatie/period state of the touched files before f717c7c624
This commit is contained in:
1 parent
67bae2d40e
commit
a0a637fda7
3 files changed
+1
-28
No files matched your search
@@ -66,12 +66,6 @@ trait PeriodGetters
|
||||
|
||||
public function length(): int
|
||||
{
|
||||
// Boundary exclusions can push the included start past the included end,
|
||||
// leaving no units at all.
|
||||
if ($this->includedStart() > $this->includedEnd()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Length of month and year are not fixed, so we can't predict the length without iterate
|
||||
// TODO: maybe we can use cal_days_in_month ?
|
||||
if ($this->precision->equals(Precision::MONTH(), Precision::YEAR())) {
|
||||
@@ -79,7 +73,7 @@ trait PeriodGetters
|
||||
}
|
||||
|
||||
if ($this->precision->equals(Precision::HOUR(), Precision::MINUTE(), Precision::SECOND())) {
|
||||
$length = $this->includedEnd()->getTimestamp() - $this->includedStart()->getTimestamp();
|
||||
$length = abs($this->includedEnd()->getTimestamp() - $this->includedStart()->getTimestamp());
|
||||
|
||||
if ($this->precision->equals(Precision::SECOND())) {
|
||||
return $length + 1;
|
||||
|
||||
@@ -88,18 +88,3 @@ dataset('expected_period_lengths', function () {
|
||||
yield [24, Period::make('2018-01-01 00:00:00', '2018-01-01 23:59:59', Precision::HOUR())];
|
||||
yield [24, Period::make('2018-01-01 00:00:00', '2018-01-02 00:00:00', Precision::HOUR(), Boundaries::EXCLUDE_END())];
|
||||
});
|
||||
|
||||
// Single-unit periods left empty by their boundary exclusions. The
|
||||
// iterator yields nothing for these, so length() must return 0.
|
||||
dataset('empty_period_lengths', function () {
|
||||
yield 'day, exclude start' => [Period::make('2018-01-01', '2018-01-01', Precision::DAY(), Boundaries::EXCLUDE_START())];
|
||||
yield 'day, exclude end' => [Period::make('2018-01-01', '2018-01-01', Precision::DAY(), Boundaries::EXCLUDE_END())];
|
||||
yield 'day, exclude all' => [Period::make('2018-01-01', '2018-01-01', Precision::DAY(), Boundaries::EXCLUDE_ALL())];
|
||||
|
||||
yield 'hour, exclude all' => [Period::make('2018-01-01 10:00:00', '2018-01-01 10:00:00', Precision::HOUR(), Boundaries::EXCLUDE_ALL())];
|
||||
yield 'minute, exclude all' => [Period::make('2018-01-01 10:00:00', '2018-01-01 10:00:00', Precision::MINUTE(), Boundaries::EXCLUDE_ALL())];
|
||||
yield 'second, exclude all' => [Period::make('2018-01-01 10:00:00', '2018-01-01 10:00:00', Precision::SECOND(), Boundaries::EXCLUDE_ALL())];
|
||||
|
||||
yield 'month, exclude all' => [Period::make('2018-01-01', '2018-01-01', Precision::MONTH(), Boundaries::EXCLUDE_ALL())];
|
||||
yield 'year, exclude all' => [Period::make('2018-01-01', '2018-01-01', Precision::YEAR(), Boundaries::EXCLUDE_ALL())];
|
||||
});
|
||||
@@ -11,12 +11,6 @@ it('can determine the period length', function () {
|
||||
expect($period->length())->toEqual(15);
|
||||
});
|
||||
|
||||
it('returns a length of 0 for an empty period, consistent with its iterator', function (Period $period) {
|
||||
expect($period->includedStart())->toBeGreaterThan($period->includedEnd());
|
||||
expect($period->length())->toEqual(0);
|
||||
expect($period->length())->toEqual(iterator_count($period));
|
||||
})->with('empty_period_lengths');
|
||||
|
||||
it('can renew a period', function () {
|
||||
$period = Period::make('2018-01-01', '2018-01-15');
|
||||
|
||||
|
||||
Reference in new issue
Block a user