generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use DateTime; | ||
use DateTimeZone; | ||
use DateInterval; | ||
use IntlDateFormatter; | ||
|
||
class Turkmenistan extends Country | ||
{ | ||
protected string $timezone = "Asia/Ashgabat"; | ||
|
||
public function countryCode(): string | ||
{ | ||
return 'tm'; | ||
} | ||
|
||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Täze ýyl' => '01-01', | ||
'Halkara zenanlar güni' => '03-08', | ||
'Milli bahar baýramy 1-nji güni' => '03-21', | ||
'Milli bahar baýramy 2-nji güni' => '03-22', | ||
'Türkmenistanyň Konstitusiýasynyň we Türkmenistanyň Döwlet baýdagynyň güni' => '05-18', | ||
'Türkmenistanyň Garaşsyzlyk güni' => '09-27', | ||
'Hatyra güni' => '10-06', | ||
'Halkara Bitaraplyk güni' => '12-12', | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
return [ | ||
'Oraza baýramy' => $this->islamicCalendar('01-10', $year), | ||
'Gurban baýramy 1-nji güni' => $this->islamicCalendar('10-12', $year), | ||
'Gurban baýramy 2-nji güni' => $this->islamicCalendar('11-12', $year), | ||
'Gurban baýramy 3-nji güni' => $this->islamicCalendar('12-12', $year), | ||
]; | ||
} | ||
|
||
protected function islamicCalendar(string $input, int $year, $nextYear = false): string | ||
{ | ||
$hijriYear = $this->getHijriYear(year: $year, nextYear: $nextYear); | ||
$formatter = $this->getIslamicFormatter(); | ||
|
||
$timeStamp = $formatter->parse($input . '/' . $hijriYear . ' AH'); | ||
$dateTime = date_create()->setTimeStamp($timeStamp)->setTimezone(new DateTimeZone($this->timezone)); | ||
|
||
return $dateTime->format('m-d'); | ||
} | ||
|
||
protected function getIslamicFormatter(): IntlDateFormatter | ||
{ | ||
return new IntlDateFormatter( | ||
locale: 'en-SG@calendar=islamic-civil', | ||
dateType: IntlDateFormatter::MEDIUM, | ||
timeType: IntlDateFormatter::NONE, | ||
timezone: $this->timezone, | ||
calendar: IntlDateFormatter::TRADITIONAL | ||
); | ||
} | ||
|
||
protected function getHijriYear(int $year, $nextYear = false): int | ||
{ | ||
$formatter = $this->getIslamicFormatter(); | ||
$formatter->setPattern('yyyy'); | ||
$dateTime = DateTime::createFromFormat('d/m/Y', '01/01/' . ($nextYear ? $year + 1 : $year)); | ||
|
||
return (int) $formatter->format($dateTime); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/.pest/snapshots/Countries/TurkmenistanTest/it_can_calculate_turkmen_holidays.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"name": "T\u00e4ze \u00fdyl", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Halkara zenanlar g\u00fcni", | ||
"date": "2024-03-08" | ||
}, | ||
{ | ||
"name": "Milli bahar ba\u00fdramy 1-nji g\u00fcni", | ||
"date": "2024-03-21" | ||
}, | ||
{ | ||
"name": "Milli bahar ba\u00fdramy 2-nji g\u00fcni", | ||
"date": "2024-03-22" | ||
}, | ||
{ | ||
"name": "Oraza ba\u00fdramy", | ||
"date": "2024-04-10" | ||
}, | ||
{ | ||
"name": "T\u00fcrkmenistany\u0148 Konstitusi\u00fdasyny\u0148 we T\u00fcrkmenistany\u0148 D\u00f6wlet ba\u00fddagyny\u0148 g\u00fcni", | ||
"date": "2024-05-18" | ||
}, | ||
{ | ||
"name": "Gurban ba\u00fdramy 1-nji g\u00fcni", | ||
"date": "2024-06-17" | ||
}, | ||
{ | ||
"name": "Gurban ba\u00fdramy 2-nji g\u00fcni", | ||
"date": "2024-06-18" | ||
}, | ||
{ | ||
"name": "Gurban ba\u00fdramy 3-nji g\u00fcni", | ||
"date": "2024-06-19" | ||
}, | ||
{ | ||
"name": "T\u00fcrkmenistany\u0148 Gara\u015fsyzlyk g\u00fcni", | ||
"date": "2024-09-27" | ||
}, | ||
{ | ||
"name": "Hatyra g\u00fcni", | ||
"date": "2024-10-06" | ||
}, | ||
{ | ||
"name": "Halkara Bitaraplyk g\u00fcni", | ||
"date": "2024-12-12" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate turkmen holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'tm')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |