Add the Calendar Calculator

It encapsulates some date operations like sum. The result will be the
calculated date when calling the nextDateByInterval method, given the
date, periodicity, and skipInterval parameters.

For example, given a date of 2019-12-31, monthly periodicity, and skip
interval 0, the results will be 2020-01-31. Also, if the skip interval
is 1, the result is 2020-02-29. This is because the next date will add
another month to the current range.
This commit is contained in:
Antonio Spinelli
2023-07-03 00:08:14 -03:00
parent 4e3c2ba72c
commit dbb7ed3d5d
4 changed files with 326 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<?php
namespace FireflyIII\Support\Calendar\Exceptions;
use FireflyIII\Support\Calendar\Periodicity;
use JetBrains\PhpStorm\Pure;
final class IntervalException extends \Exception
{
protected $message = 'The periodicity %s is unknown. Choose one of available periodicity: %s';
public readonly Periodicity $periodicity;
public readonly array $availableIntervals;
public static function unavailable(Periodicity $periodicity, array $instervals, int $code = 0, ?\Throwable $previous = null): IntervalException
{
$message = sprintf(
'The periodicity %s is unknown. Choose one of available periodicity: %s',
$periodicity->name,
join(', ', $instervals)
);
$exception = new IntervalException($message, $code, $previous);
$exception->periodicity = $periodicity;
$exception->availableIntervals = $instervals;
return $exception;
}
}