Skip to content

Commit

Permalink
added toAd function
Browse files Browse the repository at this point in the history
converts bs date to ad date and return carbon date
  • Loading branch information
kundankarna1994 committed Mar 4, 2024
1 parent 299c0d3 commit 3b576ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Facades/NepaliDateConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

/**
* @method static toBs()
* @method static toAd()
* @method static toBsDate()
* @method static toBsFormattedDate()
* @method static getAdDateByBsDate()
* @method static getBsDateByAdDate()
* @see \Proshore\NepaliDate\NepaliDateConverter
*/
class NepaliDateConverter extends Facade
{
Expand Down
16 changes: 16 additions & 0 deletions src/NepaliDateConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,20 @@ public function getBsDateByAdDate(int $adYear, int $adMonth, int $adDate) : arra
return $this->converter->getBsDateByAdDate($adYear, $adMonth, $adDate);
}

/**
* @param int $bsYear
* @param int $bsMonth
* @param int $bsDay
* @return Carbon|null
*/
public function toAd(int $bsYear, int $bsMonth, int $bsDay): Carbon|null
{
$date = $this->converter->getAdDateByBsDate($bsYear, $bsMonth, $bsDay);
if(! $date) {
return null;
}

return Carbon::createFromDate($date['year'], $date['month'], $date['date']);
}

}
5 changes: 5 additions & 0 deletions tests/Unit/NepaliDateConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@
$nepaliDate = Carbon::now()->addYears(100)->toBs();
expect($nepaliDate)->toBeNull();
});

test("can_get_ad_carbon_date_from_nepali_date", function () {
$date = \Proshore\NepaliDate\Facades\NepaliDateConverter::toAd(2080, 01, 06);
expect($date)->toBeInstanceOf(Carbon::class);
});

0 comments on commit 3b576ad

Please sign in to comment.