From 9106de5cb44e4a4364bca1cfb9eaf14c63b405e1 Mon Sep 17 00:00:00 2001 From: HAMAD ABDULLA Date: Wed, 21 Feb 2024 12:01:40 +0300 Subject: [PATCH 01/12] Adding holidays for Bahrain (#206) * Adding holidays for Bahrain * Update Bahrain.php * Update tests/Countries/BahrainTest.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/bahrain/ar/holidays.json | 16 ++ lang/bahrain/en/holidays.json | 16 ++ src/Countries/Bahrain.php | 212 ++++++++++++++++++ .../it_can_calculate_bahrain_holidays.snap | 62 +++++ tests/Countries/BahrainTest.php | 18 ++ 5 files changed, 324 insertions(+) create mode 100644 lang/bahrain/ar/holidays.json create mode 100644 lang/bahrain/en/holidays.json create mode 100644 src/Countries/Bahrain.php create mode 100644 tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap create mode 100644 tests/Countries/BahrainTest.php diff --git a/lang/bahrain/ar/holidays.json b/lang/bahrain/ar/holidays.json new file mode 100644 index 00000000..a1fcc4b3 --- /dev/null +++ b/lang/bahrain/ar/holidays.json @@ -0,0 +1,16 @@ +{ + "New Year\\'s Day": "رأس السنة الميلادية", + "Labour Day": "عيد العمال", + "Eid al-Fitr": "عيد الفطر المبارك", + "Eid al-Fitr Day 2": "عيد الفطر المبارك", + "Eid al-Fitr Day 3": "عيد الفطر المبارك", + "Eid al-Adha": "عيد الأضحى المبارك", + "Eid al-Adha Day 2": "عيد الأضحى المبارك", + "Eid al-Adha Day 3": "عيد الأضحى المبارك", + "Islamic New Year": "رأس السنة الهجرية", + "Birthday of the Prophet Muhammad": "المولد النبوي الشريف", + "Arafat Day": "يوم عرفة", + "National Day": "اليوم الوطني", + "National Day 2": "اليوم الوطني", + "Arafat Day 2": "يوم عرفة", +} \ No newline at end of file diff --git a/lang/bahrain/en/holidays.json b/lang/bahrain/en/holidays.json new file mode 100644 index 00000000..a5be25ff --- /dev/null +++ b/lang/bahrain/en/holidays.json @@ -0,0 +1,16 @@ +{ + "New Year\\'s Day": "New Year\\'s Day", + "Labour Day": "Labour Day", + "Eid al-Fitr": "Eid al-Fitr", + "Eid al-Fitr Day 2": "Eid al-Fitr", + "Eid al-Fitr Day 3": "Eid al-Fitr", + "Eid al-Adha": "Eid al-Adha", + "Eid al-Adha Day 2": "Eid al-Adha", + "Eid al-Adha Day 3": "Eid al-Adha", + "Islamic New Year": "Islamic New Year", + "Birthday of the Prophet Muhammad": "Birthday of the Prophet Muhammad", + "Arafat Day": "Arafat Day", + "National Day": "National Day", + "National Day 2": "National Day", + "Arafat Day 2": "Arafat Day", +} diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php new file mode 100644 index 00000000..71e66bbc --- /dev/null +++ b/src/Countries/Bahrain.php @@ -0,0 +1,212 @@ + '05-24', + 2021 => '05-13', + 2022 => '05-02', + 2023 => '04-20', + 2024 => '04-10', + 2025 => '03-31', + 2026 => '03-21', + 2027 => '03-10', + 2028 => '02-27', + 2029 => '02-15', + 2030 => '02-04', + 2031 => '01-25', + 2032 => '01-15', + 2033 => '01-03', + 2034 => '12-13', + 2035 => '12-02', + 2036 => '11-20', + 2037 => '11-09', + ]; + + protected const ARAFAT_DAY_HOLIDAYS = [ + 2020 => '07-30', + 2021 => '07-19', + 2022 => '07-09', + 2023 => '06-27', + 2024 => '06-16', + 2025 => '06-06', + 2026 => '05-26', + 2027 => '05-16', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-13', + 2031 => '04-02', + 2032 => '03-21', + 2033 => '03-11', + 2034 => '03-01', + 2035 => '02-18', + 2036 => '02-07', + 2037 => '01-26', + ]; + + protected const EID_AL_ADHA_HOLIDAYS = [ + 2020 => '07-31', + 2021 => '07-20', + 2022 => '07-09', + 2023 => '06-28', + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-06', + 2029 => '04-25', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-02', + 2035 => '02-19', + 2036 => '02-08', + 2037 => '01-27', + ]; + + protected const ISLAMIC_NEW_YEAR_HOLIDAYS = [ + 2020 => '08-20', + 2021 => '08-09', + 2022 => '07-30', + 2023 => '07-19', + 2024 => '07-08', + 2025 => '06-06', + 2026 => '06-17', + 2027 => '06-07', + 2028 => '05-26', + 2029 => '05-15', + 2030 => '05-05', + 2031 => '04-24', + 2032 => '04-12', + 2033 => '04-01', + 2034 => '03-22', + 2035 => '03-12', + 2036 => '02-29', + 2037 => '02-17', + ]; + + protected const ASHURA_HOLIDAYS = [ + 2020 => '08-30', + 2021 => '08-19', + 2022 => '08-08', + 2023 => '07-28', + 2024 => '07-17', + 2025 => '07-07', + 2026 => '06-26', + 2027 => '06-15', + 2028 => '06-04', + 2029 => '05-24', + 2030 => '05-13', + 2031 => '05-02', + 2032 => '04-20', + 2033 => '04-10', + 2034 => '03-30', + 2035 => '03-19', + 2036 => '03-08', + 2037 => '02-25', + ]; + + protected const PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS = [ + 2020 => '10-29', + 2021 => '10-21', + 2022 => '10-08', + 2023 => '09-28', + 2024 => '09-16', + 2025 => '09-06', + 2026 => '08-26', + 2027 => '08-15', + 2028 => '08-04', + 2029 => '07-25', + 2030 => '07-14', + 2031 => '07-03', + 2032 => '06-21', + 2033 => '06-10', + 2034 => '05-31', + 2035 => '05-21', + 2036 => '05-09', + 2037 => '04-29', + ]; + + public function countryCode(): string + { + return 'bh'; + } + + protected function allHolidays(int $year): array + { + $variableHolidays = $this->variableHolidays($year); + + return array_merge([ + 'New Year\'s Day' => '1-1', + 'Labour Day' => '5-1', + 'National Day' => '12-16', + 'National Day 2' => '12-17', + ], $variableHolidays); + } + + /** + * @return array + */ +protected function variableHolidays(int $year): array +{ + $holidays = [ + ['EID_AL_FITR_HOLIDAYS', 'Eid al-Fitr', 3], + ['EID_AL_ADHA_HOLIDAYS', 'Eid al-Adha', 3], + ['ARAFAT_DAY_HOLIDAYS', 'Arafat Day'], + ['ISLAMIC_NEW_YEAR_HOLIDAYS', 'Islamic New Year'], + ['ASHURA_HOLIDAYS', 'Ashura', 2], + ['PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS', 'Birthday of the Prophet Muhammad'] + ]; + + $dates = []; + foreach ($holidays as $holiday) { + $dates = array_merge($dates, $this->getIslamicHolidayDatesForYear(constant('self::' . $holiday[0]), $year, $holiday[1], $holiday[2] ?? 1)); + } + + return $dates; +} + + /** + * Prepare holiday dates for the given year. + * + * @param array $holidayDates Array mapping years to dates. + * @param int $year The year for which to prepare holiday dates. + * @param string $holidayName The name of the holiday. + * @param int $duration The duration of the holiday in days. + * @return array An array of holiday dates. + */ + private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, string $holidayName, int $duration = 1): array + { + $dates = []; + + if ($year < 2020) { + throw InvalidYear::yearTooLow(2020); + } + + if (! isset($holidayDates[$year])) { + return $dates; + } + + $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); + + if ($duration === 1) { + // For single-day holidays, use the holiday name without "Day" + $dates[$holidayName] = $startDay; + } else { + // For multi-day holidays, append "Day N" for the second day onwards + for ($i = 0; $i < $duration; $i++) { + $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); + $dates[$dayLabel] = $startDay->addDays($i); + } + } + + return $dates; + } +} diff --git a/tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap b/tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap new file mode 100644 index 00000000..457cb19b --- /dev/null +++ b/tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap @@ -0,0 +1,62 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Eid al-Fitr", + "date": "2024-04-10" + }, + { + "name": "Eid al-Fitr Day 2", + "date": "2024-04-11" + }, + { + "name": "Eid al-Fitr Day 3", + "date": "2024-04-12" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Arafat Day", + "date": "2024-06-16" + }, + { + "name": "Eid al-Adha", + "date": "2024-06-17" + }, + { + "name": "Eid al-Adha Day 2", + "date": "2024-06-18" + }, + { + "name": "Eid al-Adha Day 3", + "date": "2024-06-19" + }, + { + "name": "Islamic New Year", + "date": "2024-07-08" + }, + { + "name": "Ashura", + "date": "2024-07-17" + }, + { + "name": "Ashura Day 2", + "date": "2024-07-18" + }, + { + "name": "Birthday of the Prophet Muhammad", + "date": "2024-09-16" + }, + { + "name": "National Day", + "date": "2024-12-16" + }, + { + "name": "National Day 2", + "date": "2024-12-17" + } +] \ No newline at end of file diff --git a/tests/Countries/BahrainTest.php b/tests/Countries/BahrainTest.php new file mode 100644 index 00000000..b8a7c458 --- /dev/null +++ b/tests/Countries/BahrainTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 0e1036109f89b86a34c374148e515ef015a790ec Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 21 Feb 2024 09:02:09 +0000 Subject: [PATCH 02/12] Fix styling --- src/Countries/Bahrain.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 71e66bbc..1c7cee12 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -154,24 +154,24 @@ protected function allHolidays(int $year): array /** * @return array */ -protected function variableHolidays(int $year): array -{ - $holidays = [ - ['EID_AL_FITR_HOLIDAYS', 'Eid al-Fitr', 3], - ['EID_AL_ADHA_HOLIDAYS', 'Eid al-Adha', 3], - ['ARAFAT_DAY_HOLIDAYS', 'Arafat Day'], - ['ISLAMIC_NEW_YEAR_HOLIDAYS', 'Islamic New Year'], - ['ASHURA_HOLIDAYS', 'Ashura', 2], - ['PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS', 'Birthday of the Prophet Muhammad'] - ]; + protected function variableHolidays(int $year): array + { + $holidays = [ + ['EID_AL_FITR_HOLIDAYS', 'Eid al-Fitr', 3], + ['EID_AL_ADHA_HOLIDAYS', 'Eid al-Adha', 3], + ['ARAFAT_DAY_HOLIDAYS', 'Arafat Day'], + ['ISLAMIC_NEW_YEAR_HOLIDAYS', 'Islamic New Year'], + ['ASHURA_HOLIDAYS', 'Ashura', 2], + ['PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS', 'Birthday of the Prophet Muhammad'], + ]; - $dates = []; - foreach ($holidays as $holiday) { - $dates = array_merge($dates, $this->getIslamicHolidayDatesForYear(constant('self::' . $holiday[0]), $year, $holiday[1], $holiday[2] ?? 1)); - } + $dates = []; + foreach ($holidays as $holiday) { + $dates = array_merge($dates, $this->getIslamicHolidayDatesForYear(constant('self::'.$holiday[0]), $year, $holiday[1], $holiday[2] ?? 1)); + } - return $dates; -} + return $dates; + } /** * Prepare holiday dates for the given year. From e750838d28faffd9fdf2cd3fae8bb9c0922a184f Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:59:00 +0100 Subject: [PATCH 03/12] move trait from abstract class + introduce new interface --- src/Concerns/Translatable.php | 10 +++++++++- src/Contracts/HasTranslations.php | 10 ++++++++++ src/Countries/Country.php | 7 ++++--- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/Contracts/HasTranslations.php diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 237c8905..11e40f07 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -6,9 +6,17 @@ trait Translatable { - protected function translate(string $country, string $name, ?string $locale = null): string + public function translate(string $country, string $name, ?string $locale = null): string { if ($locale === null) { + if ($this->defaultLocale()) { + $locale = $this->defaultLocale(); + } else { + return $name; + } + } + + if ($locale === $this->defaultLocale()) { return $name; } diff --git a/src/Contracts/HasTranslations.php b/src/Contracts/HasTranslations.php new file mode 100644 index 00000000..45939535 --- /dev/null +++ b/src/Contracts/HasTranslations.php @@ -0,0 +1,10 @@ + */ @@ -33,7 +32,9 @@ public function get(int $year, ?string $locale = null): array } } - $name = $this->translate(basename(str_replace('\\', '/', static::class)), $name, $locale); + if ($this instanceof HasTranslations) { + $name = $this->translate(basename(str_replace('\\', '/', static::class)), $name, $locale); + } $translatedHolidays[$name] = $date; } From d674cbdc2421ac14916d08d5017662d85b1dfe11 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:59:20 +0100 Subject: [PATCH 04/12] introduce default locale for countries with translations --- src/Countries/Albania.php | 11 ++++++++++- src/Countries/Azerbaijan.php | 12 ++++++++++-- src/Countries/Bahrain.php | 11 ++++++++++- src/Countries/Bangladesh.php | 11 ++++++++++- src/Countries/Belarus.php | 11 ++++++++++- src/Countries/Belgium.php | 11 ++++++++++- src/Countries/Egypt.php | 11 ++++++++++- src/Countries/Finland.php | 11 ++++++++++- src/Countries/Germany.php | 11 ++++++++++- src/Countries/Iran.php | 12 +++++++++++- src/Countries/Montenegro.php | 11 ++++++++++- src/Countries/Switzerland.php | 11 ++++++++++- src/Countries/Syria.php | 11 ++++++++++- src/Countries/Uzbekistan.php | 11 ++++++++++- src/Countries/Vietnam.php | 10 +++++++++- 15 files changed, 150 insertions(+), 16 deletions(-) diff --git a/src/Countries/Albania.php b/src/Countries/Albania.php index dd0e05d3..65424c76 100644 --- a/src/Countries/Albania.php +++ b/src/Countries/Albania.php @@ -3,15 +3,24 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidYear; -class Albania extends Country +class Albania extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'al'; } + public function defaultLocale(): string + { + return 'al'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Azerbaijan.php b/src/Countries/Azerbaijan.php index b92cd3b1..10b10abf 100644 --- a/src/Countries/Azerbaijan.php +++ b/src/Countries/Azerbaijan.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Azerbaijan extends Country +class Azerbaijan extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'az'; } + public function defaultLocale(): string + { + return 'az'; + } + protected function allHolidays(int $year): array { return array_merge([ @@ -31,7 +40,6 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - // does not change according to the standard return []; } } diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 1c7cee12..9d9b4d6b 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -4,10 +4,14 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidYear; -class Bahrain extends Country +class Bahrain extends Country implements HasTranslations { + use Translatable; + protected const EID_AL_FITR_HOLIDAYS = [ 2020 => '05-24', 2021 => '05-13', @@ -139,6 +143,11 @@ public function countryCode(): string return 'bh'; } + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { $variableHolidays = $this->variableHolidays($year); diff --git a/src/Countries/Bangladesh.php b/src/Countries/Bangladesh.php index b269f53d..a11c9907 100644 --- a/src/Countries/Bangladesh.php +++ b/src/Countries/Bangladesh.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Bangladesh extends Country +class Bangladesh extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'bd'; } + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Belarus.php b/src/Countries/Belarus.php index f065d714..18eca92b 100644 --- a/src/Countries/Belarus.php +++ b/src/Countries/Belarus.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Belarus extends Country +class Belarus extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'by'; } + public function defaultLocale(): string + { + return 'be'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Belgium.php b/src/Countries/Belgium.php index 8710daf7..3c9b423b 100644 --- a/src/Countries/Belgium.php +++ b/src/Countries/Belgium.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Belgium extends Country +class Belgium extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'be'; } + public function defaultLocale(): string + { + return 'nl'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index 464759c2..d6f8af4e 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -4,10 +4,14 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidYear; -class Egypt extends Country +class Egypt extends Country implements HasTranslations { + use Translatable; + protected const EID_AL_FITR_HOLIDAYS = [ 2005 => '11-04', 2006 => '10-24', @@ -229,6 +233,11 @@ public function countryCode(): string return 'eg'; } + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { $fixedHolidays = $this->fixedHolidays($year); diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index bcb2e72c..c9d6d601 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -4,14 +4,23 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Finland extends Country +class Finland extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'fi'; } + public function defaultLocale(): string + { + return 'fi'; + } + protected function allHolidays(int $year): array { return array_merge( diff --git a/src/Countries/Germany.php b/src/Countries/Germany.php index fda0dc46..04fdda15 100644 --- a/src/Countries/Germany.php +++ b/src/Countries/Germany.php @@ -3,9 +3,13 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Germany extends Country +class Germany extends Country implements HasTranslations { + use Translatable; + protected function __construct( protected ?string $region = null, ) { @@ -16,6 +20,11 @@ public function countryCode(): string return 'de'; } + public function defaultLocale(): string + { + return 'de'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Iran.php b/src/Countries/Iran.php index a70be6c5..d118bf91 100644 --- a/src/Countries/Iran.php +++ b/src/Countries/Iran.php @@ -2,13 +2,23 @@ namespace Spatie\Holidays\Countries; -class Iran extends Country +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; + +class Iran extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'ir'; } + public function defaultLocale(): string + { + return 'fa'; + } + protected function allHolidays(int $year): array { return [ diff --git a/src/Countries/Montenegro.php b/src/Countries/Montenegro.php index 9ff1de06..a8d41397 100644 --- a/src/Countries/Montenegro.php +++ b/src/Countries/Montenegro.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Montenegro extends Country +class Montenegro extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'me'; } + public function defaultLocale(): string + { + return 'sr'; + } + public function allHolidays(int $year): array { // Montenegro has two days off for most holidays diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index d4d71068..d9305fbf 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -3,10 +3,14 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidRegion; -class Switzerland extends Country +class Switzerland extends Country implements HasTranslations { + use Translatable; + private const REGIONS = [ 'ch-ag', 'ch-ar', @@ -82,6 +86,11 @@ public function countryCode(): string return 'ch'; } + public function defaultLocale(): string + { + return 'de'; + } + /** * @return array */ diff --git a/src/Countries/Syria.php b/src/Countries/Syria.php index 86ecd5d3..51d9e5f6 100644 --- a/src/Countries/Syria.php +++ b/src/Countries/Syria.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Syria extends Country +class Syria extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'sy'; } + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Uzbekistan.php b/src/Countries/Uzbekistan.php index ffb37191..ceb3cade 100644 --- a/src/Countries/Uzbekistan.php +++ b/src/Countries/Uzbekistan.php @@ -3,9 +3,13 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Uzbekistan extends Country +class Uzbekistan extends Country implements HasTranslations { + use Translatable; + /** * Islamic holidays (Ramadan & Sacrifice) are obtained constantly from 1991 to 2037 (https://www.timeanddate.com/holidays/uzbekistan/) */ @@ -123,6 +127,11 @@ public function countryCode(): string return 'uz'; } + public function defaultLocale(): string + { + return 'uz'; + } + /** @return array */ protected function allHolidays(int $year): array { diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index 7d650404..51564dba 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -5,9 +5,12 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; use Spatie\Holidays\Calendars\ChineseCalendar; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Vietnam extends Country +class Vietnam extends Country implements HasTranslations { + use Translatable; use ChineseCalendar; public function countryCode(): string @@ -15,6 +18,11 @@ public function countryCode(): string return 'vn'; } + public function defaultLocale(): string + { + return 'vi'; + } + protected function allHolidays(int $year): array { return array_merge([ From df6dff525c4362d20b8295811ee20f3a65244cb5 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:01:16 +0100 Subject: [PATCH 05/12] remove all translation files if default locale --- lang/bahrain/en/holidays.json | 16 --------------- lang/bangladesh/en/holidays.json | 10 ---------- lang/egypt/en/holidays.json | 33 ------------------------------- lang/iran/fa/holidays.json | 12 ----------- lang/montenegro/sr/holidays.json | 18 ----------------- lang/switzerland/de/holidays.json | 19 ------------------ 6 files changed, 108 deletions(-) delete mode 100644 lang/bahrain/en/holidays.json delete mode 100644 lang/bangladesh/en/holidays.json delete mode 100644 lang/egypt/en/holidays.json delete mode 100644 lang/iran/fa/holidays.json delete mode 100644 lang/montenegro/sr/holidays.json delete mode 100644 lang/switzerland/de/holidays.json diff --git a/lang/bahrain/en/holidays.json b/lang/bahrain/en/holidays.json deleted file mode 100644 index a5be25ff..00000000 --- a/lang/bahrain/en/holidays.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "New Year\\'s Day": "New Year\\'s Day", - "Labour Day": "Labour Day", - "Eid al-Fitr": "Eid al-Fitr", - "Eid al-Fitr Day 2": "Eid al-Fitr", - "Eid al-Fitr Day 3": "Eid al-Fitr", - "Eid al-Adha": "Eid al-Adha", - "Eid al-Adha Day 2": "Eid al-Adha", - "Eid al-Adha Day 3": "Eid al-Adha", - "Islamic New Year": "Islamic New Year", - "Birthday of the Prophet Muhammad": "Birthday of the Prophet Muhammad", - "Arafat Day": "Arafat Day", - "National Day": "National Day", - "National Day 2": "National Day", - "Arafat Day 2": "Arafat Day", -} diff --git a/lang/bangladesh/en/holidays.json b/lang/bangladesh/en/holidays.json deleted file mode 100644 index 456af398..00000000 --- a/lang/bangladesh/en/holidays.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "International Mother Language Day": "International Mother Language Day", - "Birthday of Sheikh Mujibur Rahman": "Birthday of Sheikh Mujibur Rahman", - "Independence Day": "Independence Day", - "Bengali New Year": "Bengali New Year", - "May Day": "May Day", - "National Mourning Day": "National Mourning Day", - "Victory Day": "Victory Day", - "Christmas Day": "Christmas Day" -} diff --git a/lang/egypt/en/holidays.json b/lang/egypt/en/holidays.json deleted file mode 100644 index a503639e..00000000 --- a/lang/egypt/en/holidays.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "New Year\\'s Day": "New Year\\'s Day", - "Coptic Christmas Day": "Coptic Christmas Day", - "Revolution Day 2011": "Revolution Day 2011", - "March Equinox": "March Equinox", - "Sinai Liberation Day": "Sinai Liberation Day", - "Labour Day": "Labour Day", - "Coptic Good Friday": "Coptic Good Friday", - "Coptic Holy Saturday": "Coptic Holy Saturday", - "Coptic Easter Sunday": "Coptic Easter Sunday", - "Spring Festival": "Spring Festival", - "June Solstice": "June Solstice", - "June 30 Revolution Day": "June 30 Revolution Day", - "Day off for June 30 Revolution Day": "Day off for June 30 Revolution Day", - "Revolution Day": "Revolution Day", - "Day off for Revolution Day": "Day off for Revolution Day", - "Flooding of the Nile": "Flooding of the Nile", - "Nayrouz": "Nayrouz", - "September Equinox": "September Equinox", - "Armed Forces Day": "Armed Forces Day", - "Day off for Armed Forces Day": "Day off for Armed Forces", - "December Solstice": "December Solstice", - "Eid al-Fitr": "Eid al-Fitr", - "Eid al-Fitr Day 2": "Eid al-Fitr", - "Eid al-Fitr Day 3": "Eid al-Fitr", - "Eid al-Adha": "Eid al-Adha", - "Eid al-Adha Day 2": "Eid al-Adha", - "Eid al-Adha Day 3": "Eid al-Adha", - "Eid al-Adha Day 4": "Eid al-Adha", - "Islamic New Year": "Islamic New Year (Muharram)", - "Birthday of the Prophet Muhammad": "Birthday of the Prophet Muhammad", - "Arafat Day": "Arafat Day", -} diff --git a/lang/iran/fa/holidays.json b/lang/iran/fa/holidays.json deleted file mode 100644 index a8f7a256..00000000 --- a/lang/iran/fa/holidays.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "پیروزی انقلاب اسلامی پنجاه و هفت": "پیروزی انقلاب اسلامی پنجاه و هفت", - "روز ملی شدن صنعت نفت": "روز ملی شدن صنعت نفت", - "نخستین روز نوروز": "نخستین روز نوروز", - "دومین روز نوروز": "دومین روز نوروز", - "سومین روز نوروز": "سومین روز نوروز", - "چهارمین روز نوروز": "چهارمین روز نوروز", - "روز جمهوری اسلامی": "روز جمهوری اسلامی", - "سیزده بدر": "سیزده بدر", - "رحلت روح\u200Cالله خمینی": "رحلت روح\u200Cالله خمینی", - "قیام ۱۵ خرداد": "قیام ۱۵ خرداد" -} \ No newline at end of file diff --git a/lang/montenegro/sr/holidays.json b/lang/montenegro/sr/holidays.json deleted file mode 100644 index e09ad680..00000000 --- a/lang/montenegro/sr/holidays.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "Nova godina - prvi dan": "Nova godina - prvi dan", - "Nova godina - drugi dan": "Nova godina - drugi dan", - "Badnji dan": "Badnji dan", - "Božić - prvi dan": "Božić - prvi dan", - "Božić - drugi dan": "Božić - drugi dan", - "Praznik rada - prvi dan": "Praznik rada - prvi dan", - "Praznik rada - drugi dan": "Praznik rada - drugi dan", - "Veliki petak": "Veliki petak", - "Vaskrs": "Vaskrs", - "Vaskršnji ponedjeljak": "Vaskršnji ponedeljak", - "Dan nezavisnosti - prvi dan": "Dan nezavisnosti - prvi dan", - "Dan nezavisnosti - drugi dan": "Dan nezavisnosti - drugi dan", - "Dan državnosti - prvi dan": "Dan državnosti - prvi dan", - "Dan državnosti - drugi dan": "Dan državnosti - drugi dan", - "Njegošev dan - prvi dan": "Njegošev dan - prvi dan", - "Njegošev dan - drugi dan": "Njegošev dan - drugi dan" -} \ No newline at end of file diff --git a/lang/switzerland/de/holidays.json b/lang/switzerland/de/holidays.json deleted file mode 100644 index f5935846..00000000 --- a/lang/switzerland/de/holidays.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "Neujahr": "Neujahr", - "Berchtoldstag": "Berchtoldstag", - "Heilige Drei Könige": "Heilige Drei Könige", - "Josefstag": "Josefstag", - "Karfreitag": "Karfreitag", - "Ostermontag": "Ostermontag", - "Tag der Arbeit": "Tag der Arbeit", - "Auffahrt": "Auffahrt", - "Pfingstmontag": "Pfingstmontag", - "Fronleichnam": "Fronleichnam", - "Bundesfeier": "Bundesfeier", - "Maria Himmelfahrt": "Maria Himmelfahrt", - "Buss- und Bettag" : "Buss- und Bettag", - "Allerheiligen": "Allerheiligen", - "Maria Empfängnis": "Maria Empfängnis", - "Weihnachtstag": "Weihnachtstag", - "Stephanstag": "Stephanstag" -} From 98fa89a9e152b20c9b1ca1d54cd2c14bab3e9b5f Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 21 Feb 2024 12:01:41 +0000 Subject: [PATCH 06/12] Fix styling --- src/Countries/Country.php | 1 - src/Countries/Vietnam.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index c3975568..c0a66860 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Exceptions\InvalidYear; diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index 51564dba..a57ae68a 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -10,8 +10,8 @@ class Vietnam extends Country implements HasTranslations { - use Translatable; use ChineseCalendar; + use Translatable; public function countryCode(): string { From 6ed98737e622b43701e3c8684a837b289613775c Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:08:07 +0100 Subject: [PATCH 07/12] make more readable --- src/Concerns/Translatable.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 11e40f07..4b33cbb6 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -9,11 +9,8 @@ trait Translatable public function translate(string $country, string $name, ?string $locale = null): string { if ($locale === null) { - if ($this->defaultLocale()) { - $locale = $this->defaultLocale(); - } else { - return $name; - } + return $name; + } if ($locale === $this->defaultLocale()) { From 7010c1f0059fe993e3ad809131598b2e9567ad17 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:30:48 +0100 Subject: [PATCH 08/12] cleanup --- src/Concerns/Observable.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Concerns/Observable.php b/src/Concerns/Observable.php index aa7254ff..9dd55006 100644 --- a/src/Concerns/Observable.php +++ b/src/Concerns/Observable.php @@ -46,12 +46,11 @@ protected function observedChristmasDay(int $year): ?CarbonInterface protected function observedBoxingDay(int $year): ?CarbonInterface { - $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); - $boxingDay = $christmasDay->addDay(); + $boxingDay = (new CarbonImmutable($year.'-12-26'))->startOfDay(); - return match ($christmasDay->dayName) { - 'Friday' => $boxingDay->next('monday'), - 'Saturday' => $boxingDay->next('tuesday'), + return match ($boxingDay->dayName) { + 'Saturday' => $boxingDay->next('monday'), + 'Sunday' => $boxingDay->next('tuesday'), default => null, }; } From 9d9d4d2dcdd18c0d241ce6cda85b380416cd7acd Mon Sep 17 00:00:00 2001 From: Warren White Date: Thu, 7 Mar 2024 08:53:32 -0800 Subject: [PATCH 09/12] Fixed: incorrect date for Victoria Day in 2024 is May 20th, not May 27th --- .../CanadaTest/it_can_calculate_canadian_holidays.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap b/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap index 3168b8ea..19caffc6 100644 --- a/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap +++ b/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap @@ -13,7 +13,7 @@ }, { "name": "Victoria Day", - "date": "2024-05-27" + "date": "2024-05-20" }, { "name": "Canada Day", From 619930adba23de3e11cb2413b2a4a149919aca1f Mon Sep 17 00:00:00 2001 From: Warren White Date: Thu, 7 Mar 2024 09:00:20 -0800 Subject: [PATCH 10/12] Fixed: Victoria day is the first Monday preceding May 25th Changed from the last Monday of May which is incorrect. --- src/Countries/Canada.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index f1350e19..414a8369 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -31,11 +31,9 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $victoriaDay = (new CarbonImmutable("last monday of May $year"))->startOfDay(); - - if ($victoriaDay->day < 25) { - $victoriaDay = $victoriaDay->addWeek(); - } + // the Monday preceding May 25 + $victoriaDay = CarbonImmutable::createFromFormat( 'Y-m-d', "{$year}-05-25" ) + ->previous('Monday'); return [ 'Victoria Day' => $victoriaDay, From 75edf147994625c6d6bd67ac812687c130ae0c84 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 8 Mar 2024 09:22:01 +0000 Subject: [PATCH 11/12] Fix styling --- src/Countries/Canada.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index 414a8369..021738ac 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -32,7 +32,7 @@ protected function variableHolidays(int $year): array $easter = $this->easter($year); // the Monday preceding May 25 - $victoriaDay = CarbonImmutable::createFromFormat( 'Y-m-d', "{$year}-05-25" ) + $victoriaDay = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-25") ->previous('Monday'); return [ From ee306aeca1f6851a0e59b16f7c44de3009e7c175 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 8 Mar 2024 09:23:13 +0000 Subject: [PATCH 12/12] Update CHANGELOG --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e34faae..c80882d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to `holidays` will be documented in this file. +## 1.8.0 - 2024-03-08 + +### What's Changed + +* Adding holidays for Bahrain by @bo3bdo in https://github.com/spatie/holidays/pull/206 +* Add default locale by @Nielsvanpach in https://github.com/spatie/holidays/pull/208 +* Fix: Canada Victoria Day correction in test and calculation by @mercury64 in https://github.com/spatie/holidays/pull/211 + +### New Contributors + +* @bo3bdo made their first contribution in https://github.com/spatie/holidays/pull/206 +* @mercury64 made their first contribution in https://github.com/spatie/holidays/pull/211 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.7.0...1.8.0 + ## 1.7.0 - 2024-02-08 ### What's Changed