diff --git a/src/Countries/Turkmenistan.php b/src/Countries/Turkmenistan.php new file mode 100644 index 000000000..11004160a --- /dev/null +++ b/src/Countries/Turkmenistan.php @@ -0,0 +1,75 @@ + '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 */ + 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); + } +} diff --git a/tests/.pest/snapshots/Countries/TurkmenistanTest/it_can_calculate_turkmen_holidays.snap b/tests/.pest/snapshots/Countries/TurkmenistanTest/it_can_calculate_turkmen_holidays.snap new file mode 100644 index 000000000..3f4a419d5 --- /dev/null +++ b/tests/.pest/snapshots/Countries/TurkmenistanTest/it_can_calculate_turkmen_holidays.snap @@ -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" + } +] \ No newline at end of file diff --git a/tests/Countries/TurkmenistanTest.php b/tests/Countries/TurkmenistanTest.php new file mode 100644 index 000000000..7f29d6635 --- /dev/null +++ b/tests/Countries/TurkmenistanTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +});