Skip to content

Commit

Permalink
Merge pull request #9 from faridibin/development
Browse files Browse the repository at this point in the history
Add Carbon dependency and implement calculateNextDate method in Inter…
  • Loading branch information
faridibin authored Jan 6, 2025
2 parents c4f6d0d + bd980ff commit 4095ed3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"require": {
"php": "^8.0",
"guzzlehttp/guzzle": "^7.0",
"nesbot/carbon": "^3.8.4",
"ext-json": "*"
},
"require-dev": {
Expand Down
21 changes: 21 additions & 0 deletions src/Enums/Interval.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Faridibin\Paystack\Enums;

use Carbon\Carbon;

enum Interval: string
{
case HOURLY = 'hourly';
Expand All @@ -11,4 +13,23 @@ enum Interval: string
case QUARTERLY = 'quarterly';
case BI_ANNUALLY = 'biannually';
case ANNUALLY = 'annually';

/**
* Calculate the next date based on the interval
*
* @param Carbon $date
* @return Carbon
*/
public function calculateNextDate(Carbon $date): Carbon
{
return match ($this) {
self::HOURLY => $date->copy()->addHour(),
self::DAILY => $date->copy()->addDay(),
self::WEEKLY => $date->copy()->addWeek(),
self::MONTHLY => $date->copy()->addMonth(),
self::QUARTERLY => $date->copy()->addMonths(3),
self::BI_ANNUALLY => $date->copy()->addMonths(6),
self::ANNUALLY => $date->copy()->addYear(),
};
}
}

0 comments on commit 4095ed3

Please sign in to comment.