Skip to content

Commit

Permalink
Add tests for hijri dates
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Oct 19, 2024
1 parent bafa1b5 commit 5eb0c3c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/Cmixin/BusinessDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,33 @@ public function testIfRuleWithHijriCalendar()

self::assertSame(['hari-raya-puasa' => '2020-05-25 00:00:00'], $year(2020));
self::assertSame(['hari-raya-puasa' => '2021-05-13 00:00:00'], $year(2021));

$carbon::resetHolidays();
$carbon::setHolidays('custom', [
'hari-raya-haji' => '= 10 dhu al-hijjah if sunday then next monday',
]);
$carbon::setHolidaysRegion('custom');
$year = static function (int $year) use ($carbon) {
return array_map('strval', $carbon::getYearHolidays($year));
};

self::assertSame(['hari-raya-haji' => '2000-03-16 00:00:00'], $year(2000));
self::assertSame(['hari-raya-haji' => '2001-03-06 00:00:00'], $year(2001));
self::assertSame(['hari-raya-haji' => '2002-02-23 00:00:00'], $year(2002));
self::assertSame(['hari-raya-haji' => '2003-02-12 00:00:00'], $year(2003));
self::assertSame(['hari-raya-haji' => '2004-02-02 00:00:00'], $year(2004));
self::assertSame(['hari-raya-haji' => '2005-01-21 00:00:00'], $year(2005));
self::assertSame([
'hari-raya-haji' => '2006-01-10 00:00:00',
'hari-raya-haji-oc-2' => '2006-12-31 00:00:00',
], $year(2006));
self::assertSame(['hari-raya-haji' => '2009-11-28 00:00:00'], $year(2009));
self::assertSame(['hari-raya-haji' => '2010-11-17 00:00:00'], $year(2010));
self::assertSame(['hari-raya-haji' => '2011-11-07 00:00:00'], $year(2011));
self::assertSame(['hari-raya-haji' => '2021-07-20 00:00:00'], $year(2021));
self::assertSame(['hari-raya-haji' => '2022-07-11 00:00:00'], $year(2022));
self::assertSame(['hari-raya-haji' => '2023-06-29 00:00:00'], $year(2023));
self::assertSame(['hari-raya-haji' => '2024-06-17 00:00:00'], $year(2024));
}

public function testCaseInsensitivity()
Expand Down
30 changes: 30 additions & 0 deletions tests/Cmixin/Calendar/HijriCalendarTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Tests\Cmixin\Calendar;

use Cmixin\BusinessDay\Calendar\HijriCalendar;
use PHPUnit\Framework\TestCase;

class HijriCalendarTest extends TestCase
{
/** @dataProvider getDates */
public function testHolidaysSpecificDates(string $hijri, string $gregorian): void
{
$calendar = new HijriCalendar();
[$year, $month, $day] = explode('-', $hijri);
$date = $calendar->getDate($year, $month, $day);

self::assertSame($gregorian, implode('-', $date));
}

public static function getDates(): array
{
$tests = [
['1428-12-10', '2007-12-20'],
['1429-12-10', '2008-12-9'], // some converters give 2008-12-8
['1430-12-10', '2009-11-28'], // some converters give 2009-11-27
];

return array_combine(array_column($tests, 0), $tests);
}
}

0 comments on commit 5eb0c3c

Please sign in to comment.