Skip to content

Commit

Permalink
Merge branch 'spatie:main' into add-indonesia-holiday
Browse files Browse the repository at this point in the history
  • Loading branch information
ddouble-d authored Jan 21, 2024
2 parents f4dada7 + 60b73ed commit e19e26d
Show file tree
Hide file tree
Showing 80 changed files with 2,444 additions and 55 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.
5 changes: 1 addition & 4 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Fix PHP code style issues

on:
push:
paths:
- '**.php'
on: [push]

permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: PHPStan

on: [push]
on: [push, pull_request]

jobs:
phpstan:
Expand Down
11 changes: 2 additions & 9 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
name: Tests

on:
push:
paths:
- '**.php'
- '.github/workflows/run-tests-pest.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
on: [push, pull_request]

jobs:
test:
Expand All @@ -16,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
54 changes: 45 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Spatie\Holidays\Holidays;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for('be')->get();
$holidays = Holidays::for('be')->get();
```

## Support us
Expand Down Expand Up @@ -40,21 +40,22 @@ You can get all holidays for a country by using the `get` method.

```php
use Spatie\Holidays\Holidays;
use Spatie\Holidays\Countries\Belgium;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for('be')->get();
$holidays = Holidays::for(Belgium::make())->get();
```

Alternatively, you could also pass an instance of `Country` to the `for` method.
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;
use Spatie\Holidays\Countries\Belgium;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for(Belgium::make())->get();
$holidays = Holidays::for('be')->get();
```

### Getting holidays for a specific year
Expand Down Expand Up @@ -87,6 +88,45 @@ use Spatie\Holidays\Holidays;
Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar
```

### Package limitations
1. Islamic holidays are not supported (yet)

## 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.
3. Run the tests so a snapshot gets created.
4. Verify the result in the newly created snapshot is correct.

In case your country has specific rules for calculating holidays,
for example region specific holidays, you can pass this to the constructor of your country class.

```php
$holidays = Holidays::for(Austria::make(region: 'de-bw'))->get();
```

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

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

protected function allHolidays(int $year): array
{
// Here you can use $this->region (or other variables) to calculate holidays
}
```

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for more details.

## Testing

```bash
Expand All @@ -97,10 +137,6 @@ composer test

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

## Security Vulnerabilities

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
"ext-calendar": "*"
},
"require-dev": {
"laravel/prompts": "^0.1.15",
"pestphp/pest": "^2.31",
"phpstan/phpstan": "^1.10.56",
"spatie/ray": "^1.40.1"
"spatie/ray": "^1.40.1",
"symfony/var-dumper": "^6.4"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 16 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
parameters:
ignoreErrors:
-
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Belgium\\:\\:allHolidays\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|string\\>\\.$#"
message: "#^Argument of an invalid type array\\<int, string\\>\\|false supplied for foreach, only iterables are supported\\.$#"
count: 1
path: src/Countries/Belgium.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

-
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|false\\>\\.$#"
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\|string\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|false\\>\\.$#"
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

Expand All @@ -21,9 +26,9 @@ parameters:
path: src/Countries/Country.php

-
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Hungary\\:\\:allHolidays\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|string\\>\\.$#"
message: "#^Cannot call method setTimezone\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#"
count: 1
path: src/Countries/Hungary.php
path: src/Countries/Mexico.php

-
message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#"
Expand All @@ -44,3 +49,8 @@ parameters:
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(Carbon\\\\CarbonImmutable\\)\\: mixed\\)\\|null, Closure\\(string\\)\\: non\\-falsy\\-string given\\.$#"
count: 1
path: src/Holidays.php

-
message: "#^Property Spatie\\\\Holidays\\\\Holidays\\:\\:\\$holidays \\(array\\<string, Carbon\\\\CarbonImmutable\\>\\) does not accept array\\<string, Carbon\\\\CarbonImmutable\\|string\\>\\.$#"
count: 1
path: src/Holidays.php
31 changes: 31 additions & 0 deletions playground.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Spatie\Holidays\Countries\Country;
use Spatie\Holidays\Holidays;

use function Laravel\Prompts\select;

require __DIR__.'/vendor/autoload.php';

$countries = [];

foreach (glob(__DIR__.'/src/Countries/*.php') as $filename) { // @phpstan-ignore-line
$countryClass = '\\Spatie\\Holidays\\Countries\\'.basename($filename, '.php');

if (basename($filename) === 'Country.php') {
continue;
}

$countries[$countryClass] = str_replace('\\Spatie\\Holidays\\Countries\\', '', $countryClass);
}

/** @var Country $class */
$class = select('Select a country', $countries);

$result = collect(Holidays::for($class::make())->get())
->map(fn (array $holiday) => [
'name' => $holiday['name'],
'date' => $holiday['date']->format('Y-m-d'), // @phpstan-ignore-line
])->toArray();

dd($result);
4 changes: 1 addition & 3 deletions src/Countries/Andorra.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public function countryCode(): string
return 'ad';
}

/** @return array<string, CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge([
Expand All @@ -31,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
6 changes: 2 additions & 4 deletions src/Countries/Austria.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public function countryCode(): string
return 'at';
}

/** @return array<string, CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge([
Expand All @@ -30,11 +29,10 @@ 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(1),
'Ostermontag' => $easter->addDay(),
'Christi Himmelfahrt' => $easter->addDays(39),
'Pfingstmontag' => $easter->addDays(50),
'Fronleichnam' => $easter->addDays(60),
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 [];
}
}
Loading

0 comments on commit e19e26d

Please sign in to comment.