Skip to content

Commit

Permalink
Add Turkmenistan Holidays
Browse files Browse the repository at this point in the history
  • Loading branch information
kakajansh committed Jan 18, 2024
1 parent d8cbb76 commit 67b985e
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/Countries/Turkmenistan.php
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 [

Check failure on line 37 in src/Countries/Turkmenistan.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Turkmenistan::variableHolidays() should return array<string, Carbon\CarbonImmutable> but returns array<string, string>.
'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

Check failure on line 45 in src/Countries/Turkmenistan.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Turkmenistan::islamicCalendar() has parameter $nextYear with no type specified.
{
$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));

Check failure on line 51 in src/Countries/Turkmenistan.php

View workflow job for this annotation

GitHub Actions / phpstan

Cannot call method setTimeStamp() on DateTime|false.

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

Check failure on line 67 in src/Countries/Turkmenistan.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Turkmenistan::getHijriYear() has parameter $nextYear with no type specified.
{
$formatter = $this->getIslamicFormatter();
$formatter->setPattern('yyyy');
$dateTime = DateTime::createFromFormat('d/m/Y', '01/01/' . ($nextYear ? $year + 1 : $year));

return (int) $formatter->format($dateTime);

Check failure on line 73 in src/Countries/Turkmenistan.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #1 $datetime of method IntlDateFormatter::format() expects array|DateTimeInterface|float|int|IntlCalendar|string, DateTime|false given.
}
}
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"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/TurkmenistanTest.php
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();
});

0 comments on commit 67b985e

Please sign in to comment.