diff --git a/app/Support/Calendar/Periodicity.php b/app/Support/Calendar/Periodicity.php index 05825e19a1..75c492bb13 100644 --- a/app/Support/Calendar/Periodicity.php +++ b/app/Support/Calendar/Periodicity.php @@ -27,6 +27,7 @@ enum Periodicity case Weekly; case Fortnightly; case Monthly; + case Bimonthly; case Quarterly; case HalfYearly; case Yearly; diff --git a/app/Support/Calendar/Periodicity/Bimonthly.php b/app/Support/Calendar/Periodicity/Bimonthly.php new file mode 100644 index 0000000000..a8aac196fa --- /dev/null +++ b/app/Support/Calendar/Periodicity/Bimonthly.php @@ -0,0 +1,27 @@ +. + */ + +namespace FireflyIII\Support\Calendar\Periodicity; + +final class Bimonthly extends Monthly +{ + const INTERVAL = 2; +} diff --git a/tests/Support/Calendar/CalculatorProvider.php b/tests/Support/Calendar/CalculatorProvider.php index dcbad2c8d3..20e6172e1e 100644 --- a/tests/Support/Calendar/CalculatorProvider.php +++ b/tests/Support/Calendar/CalculatorProvider.php @@ -84,6 +84,17 @@ readonly class CalculatorProvider CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-10-30'), Carbon::parse('2024-02-29')), 3), CalculatorProvider::from(Periodicity::Monthly, new IntervalProvider(Carbon::parse('2023-10-31'), Carbon::parse('2024-02-29')), 3), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(6)), 2), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-08-29'), Carbon::parse('2020-02-29')), 2), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-08-30'), Carbon::parse('2020-02-29')), 2), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-08-31'), Carbon::parse('2020-02-29')), 2), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-10-30'), Carbon::parse('2020-02-29')), 1), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2019-10-31'), Carbon::parse('2020-02-29')), 1), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-02-29'), Carbon::parse('2021-02-28')), 5), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-08-29'), Carbon::parse('2021-02-28')), 2), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-08-30'), Carbon::parse('2021-02-28')), 2), + CalculatorProvider::from(Periodicity::Bimonthly, new IntervalProvider(Carbon::parse('2020-08-31'), Carbon::parse('2021-02-28')), 2), + CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::now(), Carbon::now()->addMonthsNoOverflow(9)), 2), CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-29'), Carbon::parse('2020-02-29')), 2), CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-30'), Carbon::parse('2020-02-29')), 2), diff --git a/tests/Support/Calendar/CalculatorTest.php b/tests/Support/Calendar/CalculatorTest.php index c4fb07c6e8..d3a05fe0cf 100644 --- a/tests/Support/Calendar/CalculatorTest.php +++ b/tests/Support/Calendar/CalculatorTest.php @@ -27,6 +27,7 @@ use FireflyIII\Support\Calendar\Calculator; use FireflyIII\Support\Calendar\Exceptions\IntervalException; use FireflyIII\Support\Calendar\Periodicity; use FireflyIII\Support\Navigation; +use Tests\Support\Calendar\Periodicity\BimonthlyTest; use Tests\Support\Calendar\Periodicity\DailyTest; use Tests\Support\Calendar\Periodicity\FortnightlyTest; use Tests\Support\Calendar\Periodicity\HalfYearlyTest; @@ -58,6 +59,7 @@ class CalculatorTest extends TestCase $intervals = array_merge($intervals, self::convert(Periodicity::Weekly, WeeklyTest::provideIntervals())); $intervals = array_merge($intervals, self::convert(Periodicity::Fortnightly, FortnightlyTest::provideIntervals())); $intervals = array_merge($intervals, self::convert(Periodicity::Monthly, MonthlyTest::provideIntervals())); + $intervals = array_merge($intervals, self::convert(Periodicity::Bimonthly, BimonthlyTest::provideIntervals())); $intervals = array_merge($intervals, self::convert(Periodicity::Quarterly, QuarterlyTest::provideIntervals())); $intervals = array_merge($intervals, self::convert(Periodicity::HalfYearly, HalfYearlyTest::provideIntervals())); $intervals = array_merge($intervals, self::convert(Periodicity::Yearly, YearlyTest::provideIntervals())); diff --git a/tests/Support/Calendar/Periodicity/BimonthlyTest.php b/tests/Support/Calendar/Periodicity/BimonthlyTest.php new file mode 100644 index 0000000000..90c46c59b5 --- /dev/null +++ b/tests/Support/Calendar/Periodicity/BimonthlyTest.php @@ -0,0 +1,50 @@ +. + */ + +namespace Tests\Support\Calendar\Periodicity; + +use Carbon\Carbon; +use FireflyIII\Support\Calendar\Periodicity; +use FireflyIII\Support\Calendar\Periodicity\Interval; + +class BimonthlyTest extends IntervalTestCase +{ + public static function factory(): Interval + { + return new Periodicity\Bimonthly(); + } + + public static function provideIntervals(): array + { + return [ + new IntervalProvider(Carbon::now(), Carbon::now()->addMonths(2)), + new IntervalProvider(Carbon::parse('2019-01-29'), Carbon::parse('2019-03-29')), + new IntervalProvider(Carbon::parse('2018-12-30'), Carbon::parse('2019-02-28')), + new IntervalProvider(Carbon::parse('2018-12-31'), Carbon::parse('2019-02-28')), + new IntervalProvider(Carbon::parse('2018-11-01'), Carbon::parse('2019-01-01')), + new IntervalProvider(Carbon::parse('2019-11-29'), Carbon::parse('2020-01-29')), + new IntervalProvider(Carbon::parse('2019-11-30'), Carbon::parse('2020-01-30')), + new IntervalProvider(Carbon::parse('2020-12-29'), Carbon::parse('2021-02-28')), + new IntervalProvider(Carbon::parse('2020-12-30'), Carbon::parse('2021-02-28')), + new IntervalProvider(Carbon::parse('2020-12-31'), Carbon::parse('2021-02-28')), + ]; + } +}