mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-09 06:07:49 +00:00
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:
28
app/Support/Calendar/Exceptions/IntervalException.php
Normal file
28
app/Support/Calendar/Exceptions/IntervalException.php
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user