Skip to content

Commit

Permalink
Merge pull request #2745 from kylekatarnls/fix/issue-2744-skip
Browse files Browse the repository at this point in the history
Enforce $skip array type
  • Loading branch information
kylekatarnls authored Jan 2, 2023
2 parents 5ef3b72 + 3018dea commit 1e60d1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Carbon/Traits/Difference.php
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ public function diffForHumans($other = null, $syntax = null, $short = false, $pa
$parts = min(7, max(1, (int) $parts));
$skip = \is_array($syntax) ? ($syntax['skip'] ?? []) : [];

return $this->diffAsCarbonInterval($other, false, $skip)
return $this->diffAsCarbonInterval($other, false, (array) $skip)
->setLocalTranslator($this->getLocalTranslator())
->forHumans($syntax, (bool) $short, $parts, $options ?? $this->localHumanDiffOptions ?? static::getHumanDiffOptions());
}
Expand Down
10 changes: 10 additions & 0 deletions tests/Carbon/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,16 @@ public function testDiffWithSkippedUnits()
Carbon::parse('2020-05-25')
->diffForHumans(['skip' => ['y', 'm', 'w']])
);

Carbon::setTestNow('2023-01-02 16:57');
$this->assertSame(
'1 day 16 hours 57 minutes',
Carbon::yesterday()->diffForHumans([
'syntax' => CarbonInterface::DIFF_ABSOLUTE,
'parts' => 3,
'skip' => 's',
])
);
}

public function testDiffForHumansNowAndSecondWithTimezone()
Expand Down

0 comments on commit 1e60d1b

Please sign in to comment.