Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Add Bimonthly periodicity for Support\Calendar
Antonio Spinelli6ac3cc384bcc
diff --git a/app/Support/Calendar/Periodicity.php b/app/Support/Calendar/Periodicity.phpindex 05825e19a1..75c492bb13 100644--- a/app/Support/Calendar/Periodicity.php+++ b/app/Support/Calendar/Periodicity.php@@ -27,6 +27,7 @@ enum Periodicitycase 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.phpnew file mode 100644index 0000000000..a8aac196fa--- /dev/null+++ b/app/Support/Calendar/Periodicity/Bimonthly.php@@ -0,0 +1,27 @@+<?php++/**+ * Copyright (c) 2023 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++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.phpindex dcbad2c8d3..20e6172e1e 100644--- a/tests/Support/Calendar/CalculatorProvider.php+++ b/tests/Support/Calendar/CalculatorProvider.php@@ -84,6 +84,17 @@ readonly class CalculatorProviderCalculatorProvider::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.phpindex 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.phpnew file mode 100644index 0000000000..90c46c59b5--- /dev/null+++ b/tests/Support/Calendar/Periodicity/BimonthlyTest.php@@ -0,0 +1,50 @@+<?php++/**+ * Copyright (c) 2023 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++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')),+ ];+ }+}