Add Bimonthly periodicity for Support\Calendar

This commit is contained in:
Antonio Spinelli 2023-07-03 10:36:56 -03:00
parent 563879c218
commit 6ac3cc384b
No known key found for this signature in database
GPG Key ID: 85B740F3F834EFC4
5 changed files with 91 additions and 0 deletions

View File

@ -27,6 +27,7 @@ enum Periodicity
case Weekly; case Weekly;
case Fortnightly; case Fortnightly;
case Monthly; case Monthly;
case Bimonthly;
case Quarterly; case Quarterly;
case HalfYearly; case HalfYearly;
case Yearly; case Yearly;

View File

@ -0,0 +1,27 @@
<?php
/**
* Copyright (c) 2023 james@firefly-iii.org
*
* 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;
}

View File

@ -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-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::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::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-29'), Carbon::parse('2020-02-29')), 2),
CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-30'), Carbon::parse('2020-02-29')), 2), CalculatorProvider::from(Periodicity::Quarterly, new IntervalProvider(Carbon::parse('2019-05-30'), Carbon::parse('2020-02-29')), 2),

View File

@ -27,6 +27,7 @@ use FireflyIII\Support\Calendar\Calculator;
use FireflyIII\Support\Calendar\Exceptions\IntervalException; use FireflyIII\Support\Calendar\Exceptions\IntervalException;
use FireflyIII\Support\Calendar\Periodicity; use FireflyIII\Support\Calendar\Periodicity;
use FireflyIII\Support\Navigation; use FireflyIII\Support\Navigation;
use Tests\Support\Calendar\Periodicity\BimonthlyTest;
use Tests\Support\Calendar\Periodicity\DailyTest; use Tests\Support\Calendar\Periodicity\DailyTest;
use Tests\Support\Calendar\Periodicity\FortnightlyTest; use Tests\Support\Calendar\Periodicity\FortnightlyTest;
use Tests\Support\Calendar\Periodicity\HalfYearlyTest; 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::Weekly, WeeklyTest::provideIntervals()));
$intervals = array_merge($intervals, self::convert(Periodicity::Fortnightly, FortnightlyTest::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::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::Quarterly, QuarterlyTest::provideIntervals()));
$intervals = array_merge($intervals, self::convert(Periodicity::HalfYearly, HalfYearlyTest::provideIntervals())); $intervals = array_merge($intervals, self::convert(Periodicity::HalfYearly, HalfYearlyTest::provideIntervals()));
$intervals = array_merge($intervals, self::convert(Periodicity::Yearly, YearlyTest::provideIntervals())); $intervals = array_merge($intervals, self::convert(Periodicity::Yearly, YearlyTest::provideIntervals()));

View File

@ -0,0 +1,50 @@
<?php
/**
* Copyright (c) 2023 james@firefly-iii.org
*
* 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')),
];
}
}