Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
* 7.1:
  relax format assertions for fstat() results on Windows
  update ICU data from 75.1 to 76.1
  fix referencing the SYMFONY_VERSION env var
  handle error results of DateTime::modify()
  • Loading branch information
xabbuh committed Nov 8, 2024
2 parents 2c6f9d2 + 2b49bf0 commit 83b447a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions RateLimiterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,21 @@ public function create(?string $key = null): LimiterInterface
protected static function configureOptions(OptionsResolver $options): void
{
$intervalNormalizer = static function (Options $options, string $interval): \DateInterval {
try {
// Create DateTimeImmutable from unix timesatmp, so the default timezone is ignored and we don't need to
// deal with quirks happening when modifying dates using a timezone with DST.
$now = \DateTimeImmutable::createFromFormat('U', time());
// Create DateTimeImmutable from unix timesatmp, so the default timezone is ignored and we don't need to
// deal with quirks happening when modifying dates using a timezone with DST.
$now = \DateTimeImmutable::createFromFormat('U', time());

return $now->diff($now->modify('+'.$interval));
} catch (\Exception $e) {
if (!preg_match('/Failed to parse time string \(\+([^)]+)\)/', $e->getMessage(), $m)) {
throw $e;
}
try {
$nowPlusInterval = @$now->modify('+' . $interval);
} catch (\DateMalformedStringException $e) {
throw new \LogicException(\sprintf('Cannot parse interval "%s", please use a valid unit as described on https://www.php.net/datetime.formats.relative.', $interval), 0, $e);
}

throw new \LogicException(\sprintf('Cannot parse interval "%s", please use a valid unit as described on https://www.php.net/datetime.formats.relative.', $m[1]));
if (!$nowPlusInterval) {
throw new \LogicException(\sprintf('Cannot parse interval "%s", please use a valid unit as described on https://www.php.net/datetime.formats.relative.', $interval));
}

return $now->diff($nowPlusInterval);
};

$options
Expand Down

0 comments on commit 83b447a

Please sign in to comment.