Skip to content

Commit

Permalink
Merge branch 'spatie:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickomeara authored Jan 21, 2024
2 parents 2234633 + f25e127 commit 8643eaf
Show file tree
Hide file tree
Showing 72 changed files with 1,958 additions and 48 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[*.snap]
insert_final_newline = false
8 changes: 8 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Contributing a new country ?

* [ ] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/spatie/holidays/pulls) for the same country?

1. Create a new class in the Countries directory. It should extend the Country class.
2. Add a test for the new country in the tests directory.
3. Run the tests so a snapshot gets created.
4. Verify the result in the newly created snapshot is correct.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
php: [8.3, 8.2, 8.1]
stability: [prefer-lowest, prefer-stable]

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.php_cs
.php_cs.cache
.phpunit.cache
.vscode
build
composer.lock
coverage
Expand Down
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,67 @@

All notable changes to `holidays` will be documented in this file.

## 1.1.0 - 2024-01-19

### What's Changed

* Fix incorrect usage in README by @cybernerdie in https://github.com/spatie/holidays/pull/16
* Add Andorra Holidays by @BurtDS in https://github.com/spatie/holidays/pull/36
* Add documentation on how to contribute by @Nielsvanpach in https://github.com/spatie/holidays/pull/73
* Danish holidays by @RootAccessPlease in https://github.com/spatie/holidays/pull/5
* Introducing Basic Playground by @devajmeireles in https://github.com/spatie/holidays/pull/28
* fix: Oudjaarsdag is not a public holiday by @RickDBCN in https://github.com/spatie/holidays/pull/64
* Adds support for Portuguese Holidays by @lamelas in https://github.com/spatie/holidays/pull/9
* Added Zambian Holidays by @chandachewe10 in https://github.com/spatie/holidays/pull/83
* Add Italian holidays by @mauricius in https://github.com/spatie/holidays/pull/24
* Add French holidays by @levrailoup in https://github.com/spatie/holidays/pull/15
* Add Czech holidays by @vrerabek in https://github.com/spatie/holidays/pull/22
* Update Brazil.php by @juliofagundes in https://github.com/spatie/holidays/pull/101
* Added Uganda Public Holidays and Unit Tests by @Crawford30 in https://github.com/spatie/holidays/pull/126
* Support for Venezuelan holidays by @ricardomartos in https://github.com/spatie/holidays/pull/125
* Add Macedonian holidays by @object505 in https://github.com/spatie/holidays/pull/119
* Adding Nicaragua Holidays by @calonzolg in https://github.com/spatie/holidays/pull/92
* add Philippine national holidays by @kndrckjvr in https://github.com/spatie/holidays/pull/25
* Adding Full Mexican Holidays by @davsaniuv in https://github.com/spatie/holidays/pull/23
* Add support for Irish public holidays by @marchanlon in https://github.com/spatie/holidays/pull/44
* Add support for Croatian public holidays by @mcbuckets in https://github.com/spatie/holidays/pull/45
* Bolivian holidays by @rats4final in https://github.com/spatie/holidays/pull/40
* Add Estonian holidays by @hulkur in https://github.com/spatie/holidays/pull/47
* Update README.md by @eltociear in https://github.com/spatie/holidays/pull/134
* Public Holidays for Malawi by @Crawford30 in https://github.com/spatie/holidays/pull/133
* Add Bangladesh holidays by @arifszn in https://github.com/spatie/holidays/pull/21
* Adding Full Mandatory Mexican holidays by @dantes4ur in https://github.com/spatie/holidays/pull/20
* mexico fixes by @Nielsvanpach in https://github.com/spatie/holidays/pull/140

### New Contributors

* @cybernerdie made their first contribution in https://github.com/spatie/holidays/pull/16
* @BurtDS made their first contribution in https://github.com/spatie/holidays/pull/36
* @Nielsvanpach made their first contribution in https://github.com/spatie/holidays/pull/73
* @RootAccessPlease made their first contribution in https://github.com/spatie/holidays/pull/5
* @RickDBCN made their first contribution in https://github.com/spatie/holidays/pull/64
* @lamelas made their first contribution in https://github.com/spatie/holidays/pull/9
* @chandachewe10 made their first contribution in https://github.com/spatie/holidays/pull/83
* @mauricius made their first contribution in https://github.com/spatie/holidays/pull/24
* @levrailoup made their first contribution in https://github.com/spatie/holidays/pull/15
* @vrerabek made their first contribution in https://github.com/spatie/holidays/pull/22
* @juliofagundes made their first contribution in https://github.com/spatie/holidays/pull/101
* @Crawford30 made their first contribution in https://github.com/spatie/holidays/pull/126
* @ricardomartos made their first contribution in https://github.com/spatie/holidays/pull/125
* @object505 made their first contribution in https://github.com/spatie/holidays/pull/119
* @calonzolg made their first contribution in https://github.com/spatie/holidays/pull/92
* @kndrckjvr made their first contribution in https://github.com/spatie/holidays/pull/25
* @davsaniuv made their first contribution in https://github.com/spatie/holidays/pull/23
* @marchanlon made their first contribution in https://github.com/spatie/holidays/pull/44
* @mcbuckets made their first contribution in https://github.com/spatie/holidays/pull/45
* @rats4final made their first contribution in https://github.com/spatie/holidays/pull/40
* @hulkur made their first contribution in https://github.com/spatie/holidays/pull/47
* @eltociear made their first contribution in https://github.com/spatie/holidays/pull/134
* @arifszn made their first contribution in https://github.com/spatie/holidays/pull/21
* @dantes4ur made their first contribution in https://github.com/spatie/holidays/pull/20

**Full Changelog**: https://github.com/spatie/holidays/compare/1.0.2...1.1.0

## 1.0.2 - 2024-01-17

### What's Changed
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $holidays = Holidays::for(Belgium::make())->get();
```

Alternatively, you could also pass an [ISO 3166-1](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) code to the `for` method.
In case of region based holidays, these will not be included. Use a country class instead.

```php
use Spatie\Holidays\Holidays;
Expand Down Expand Up @@ -87,9 +88,14 @@ use Spatie\Holidays\Holidays;
Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar
```

## Contributing a new country
### Package limitations
1. Islamic holidays are not supported (yet)

If you want to add a new country, you can create a pull request.
## Contributing

This is a community driven package. If you find any errors, please create an issue or a pull request.

## Adding a new country

1. Create a new class in the `Countries` directory. It should extend the `Country` class.
2. Add a test for the new country in the `tests` directory.
Expand All @@ -103,7 +109,7 @@ for example region specific holidays, you can pass this to the constructor of yo
$holidays = Holidays::for(Austria::make(region: 'de-bw'))->get();
```

The value, `de-bw`, will be passed to the region parameter of the contructor of a country.
The value, `de-bw`, will be passed to the region parameter of the constructor of a country.

```php
class Austria extends Country
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"ext-calendar": "*"
},
"require-dev": {
"laravel/pint": "^1.0",
"laravel/prompts": "^0.1.15",
"pestphp/pest": "^2.31",
"phpstan/phpstan": "^1.10.56",
Expand All @@ -46,7 +47,7 @@
"baseline": "vendor/bin/phpstan analyse --generate-baseline",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes"
"format": "vendor/bin/pint"
},
"config": {
"sort-packages": true,
Expand Down
16 changes: 13 additions & 3 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
message: "#^Argument of an invalid type array\\<int, string\\>\\|false supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/Countries/Brazil.php
path: src/Countries/Country.php

-
message: "#^Argument of an invalid type array\\<int, string\\>\\|false supplied for foreach, only iterables are supported\\.$#"
message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#"
count: 1
path: src/Countries/Country.php

Expand All @@ -15,11 +15,21 @@ parameters:
count: 1
path: src/Countries/Country.php

-
message: "#^Parameter \\#1 \\$timestamp of static method Carbon\\\\CarbonImmutable\\:\\:createFromTimestamp\\(\\) expects float\\|int\\|string, int\\|false given\\.$#"
count: 1
path: src/Countries/Country.php

-
message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(bool\\|Carbon\\\\CarbonImmutable, bool\\|Carbon\\\\CarbonImmutable\\)\\: int, Closure\\(Carbon\\\\CarbonImmutable, Carbon\\\\CarbonImmutable\\)\\: int\\<\\-1, 1\\> given\\.$#"
count: 1
path: src/Countries/Country.php

-
message: "#^Cannot call method setTimezone\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#"
count: 1
path: src/Countries/Mexico.php

-
message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#"
count: 1
Expand Down
3 changes: 1 addition & 2 deletions src/Countries/Andorra.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ protected function allHolidays(int $year): array
/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Europe/Brussels');
$easter = $this->easter($year);

return [
'Divendres Sant' => $easter->subDays(2),
Expand Down
8 changes: 1 addition & 7 deletions src/Countries/Austria.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

class Austria extends Country
{
protected function __construct(
public ?string $region = null
) {
}

public function countryCode(): string
{
return 'at';
Expand All @@ -34,8 +29,7 @@ protected function allHolidays(int $year): array
/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Europe/Vienna');
$easter = $this->easter($year);

return [
'Ostermontag' => $easter->addDay(),
Expand Down
34 changes: 34 additions & 0 deletions src/Countries/Bangladesh.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Bangladesh extends Country
{
public function countryCode(): string
{
return 'bd';
}

protected function allHolidays(int $year): array
{
return array_merge([
'International Mother Language Day' => '02-21',
'Birthday of Sheikh Mujibur Rahman' => '03-17',
'Independence Day' => '03-26',
'Bengali New Year' => '04-14',
'May Day' => '05-01',
'National Mourning Day' => '08-15',
'Victory Day' => '12-16',
'Christmas Day' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
// The variable holidays all follow the lunar calendar, so their dates are not confirmed.
return [];
}
}
3 changes: 1 addition & 2 deletions src/Countries/Belgium.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ protected function allHolidays(int $year): array
/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Europe/Brussels');
$easter = $this->easter($year);

return [
'Paasmaandag' => $easter->addDay(),
Expand Down
39 changes: 39 additions & 0 deletions src/Countries/Bolivia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Bolivia extends Country
{
public function countryCode(): string
{
return 'bo';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Día de Año Nuevo' => '01-01',
'Día del Estado Plurinacional' => '01-22',
'Día del Trabajador' => '05-01',
'Año Nuevo Aymara' => '06-21',
'Día de la Independencia' => '08-06',
'Día de Todos los Santos' => '11-02',
'Navidad' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = $this->easter($year);

return [
'Lunes de Carnaval' => $easter->subWeeks(6)->subDays(6),
'Martes de Carnaval' => $easter->subWeeks(6)->subDays(5),
'Viernes Santo' => $easter->subDays(2),
'Corpus Christi' => $easter->addWeeks(8)->addDays(4),
];
}
}
5 changes: 2 additions & 3 deletions src/Countries/Brazil.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public function countryCode(): string

protected function allHolidays(int $year): array
{
throw new \Exception('Not implemented yet.');

return array_merge([
'Dia de Ano Novo' => '01-01',
'Dia de Tiradentes' => '04-21',
Expand All @@ -23,14 +21,15 @@ protected function allHolidays(int $year): array
'Nossa Senhora Aparecida' => '10-12',
'Finados' => '11-02',
'Proclamação da República' => '11-15',
'Dia Nacional de Zumbi e da Consciência Negra' => '11-20',
'Natal' => '12-25',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))->setTimezone('America/Sao_Paulo');
$easter = $this->easter($year);

return [
'Carnaval' => $easter->subDays(47),
Expand Down
16 changes: 16 additions & 0 deletions src/Countries/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ public static function make(): static
return new static(...func_get_args());
}

protected function easter(int $year): CarbonImmutable
{
$easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-03-21")
->startOfDay();

return $easter->addDays(easter_days($year));
}

protected function orthodoxEaster(int $year): CarbonImmutable
{
$timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN);
$daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2;

return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp));
}

public static function find(string $countryCode): ?Country
{
$countryCode = strtolower($countryCode);
Expand Down
41 changes: 41 additions & 0 deletions src/Countries/Croatia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Croatia extends Country
{
public function countryCode(): string
{
return 'hr';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Nova godina' => '01-01',
'Bogojavljenje' => '01-06',
'Praznik rada' => '05-01',
'Dan državnosti' => '05-30',
'Dan antifašističke borbe' => '06-22',
'Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja' => '08-05',
'Velika Gospa' => '08-15',
'Svi sveti' => '11-01',
'Dan sjećanja na žrtve Domovinskog rata i Dan sjećanja na žrtvu Vukovara i Škabrnje' => '11-18',
'Božić' => '12-25',
'Sveti Stjepan' => '12-26',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = $this->easter($year);

return [
'Uskrsni ponedjeljak' => $easter->addDay(),
'Tijelovo' => $easter->addDays(60),
];
}
}
Loading

0 comments on commit 8643eaf

Please sign in to comment.