Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Slovenian holidays #48

Closed
wants to merge 95 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
968f483
Slovenian holidays
juref-specto Jan 17, 2024
a01e132
Slovenian holidays tests
juref-specto Jan 17, 2024
587e5dc
Mistyped second new year date.
juref-specto Jan 18, 2024
7641078
Method call is provided 1 parameters, but the method signature uses 0…
juref-specto Jan 18, 2024
d3a6abc
Method call is provided 1 parameter, but the method signature uses 0 …
juref-specto Jan 18, 2024
6e79910
make tests faster
freekmurze Jan 18, 2024
d0598ae
Add Andorra Holidays
BurtDS Jan 17, 2024
d5cf084
Fix styling
freekmurze Jan 17, 2024
ed0c387
add docs for contributing + add example for regions
Nielsvanpach Jan 18, 2024
5d46b08
remove skipped test
Nielsvanpach Jan 18, 2024
52ebbef
edit readme
Nielsvanpach Jan 18, 2024
977717e
Update README.md
freekmurze Jan 18, 2024
ccbe257
fixes for phpstan
Nielsvanpach Jan 18, 2024
a882bca
ci changes
Nielsvanpach Jan 18, 2024
7b1b2ee
run ci for every PR
Nielsvanpach Jan 18, 2024
b092aa9
skip Brazil
Nielsvanpach Jan 18, 2024
157666d
ignore issue
Nielsvanpach Jan 18, 2024
7502ee7
Update README.md
Nielsvanpach Jan 18, 2024
04a5a2e
Added Danish holidays.
Jan 17, 2024
eb167fb
Added missing holidays.
Jan 17, 2024
6e254c9
Fixed spelling mistake.
Jan 17, 2024
8f3ac5e
Added generated snapshot.
Jan 17, 2024
6ebb998
Fixed errors regarding the order of day/month and took into account t…
Jan 18, 2024
f509cbc
Moved test to correct folder.
Jan 18, 2024
14ddf23
Fix styling
Nielsvanpach Jan 18, 2024
c898339
remove annotation
Nielsvanpach Jan 18, 2024
36b04be
introducing playground
devajmeireles Jan 17, 2024
922a3f2
Fix styling
Nielsvanpach Jan 18, 2024
49d0ee6
Update Netherlands.php
RickDBCN Jan 18, 2024
37c5e6e
update nl snapshot
Nielsvanpach Jan 18, 2024
e7ef948
Added portuguese holidays
lamelas Jan 17, 2024
85db67e
Use proper timezone
lamelas Jan 17, 2024
b17f18b
Fixes small typo
lamelas Jan 17, 2024
22bd2b3
Removing Carnaval as it is not an official holiday.
lamelas Jan 18, 2024
030531b
Fix for phpstan
lamelas Jan 18, 2024
52af88d
Fix styling
freekmurze Jan 18, 2024
ce11166
Added Zambian Holidays
chandachewe10 Jan 18, 2024
2dff651
Fix styling
freekmurze Jan 18, 2024
692bbbc
Update README.md
Nielsvanpach Jan 18, 2024
f7878ff
add: italian holidays
mauricius Jan 17, 2024
2477905
add: italian tests
mauricius Jan 17, 2024
96ad08c
remove: phpdoc
mauricius Jan 18, 2024
638f45c
fix: fix phpstan
mauricius Jan 18, 2024
2917568
Create pull_request_template.md
Nielsvanpach Jan 19, 2024
33839fa
Update pull_request_template.md
Nielsvanpach Jan 19, 2024
de0450c
Create France.php
levrailoup Jan 17, 2024
7e74122
Create FranceTest.php
levrailoup Jan 17, 2024
73e993b
Fix France.php
levrailoup Jan 17, 2024
0abc4f6
Create it_can_calculate_french_holidays.snap
levrailoup Jan 17, 2024
a219ea1
tests
levrailoup Jan 17, 2024
f4095e3
Update src/Countries/France.php
levrailoup Jan 17, 2024
eb3da65
Removed typehint from France::allHolidays()
levrailoup Jan 18, 2024
6c0f232
Added region-specific ISO 3166-2 codes
levrailoup Jan 18, 2024
e2d8fc3
Added regionHolidays return value type
levrailoup Jan 18, 2024
062ca33
Fix styling
Nielsvanpach Jan 19, 2024
71b36df
Add Czech holidays (#22)
vrerabek Jan 19, 2024
df95e99
Fix styling
Nielsvanpach Jan 19, 2024
20aa612
Update Brazil.php
juliofagundes Jan 18, 2024
dde4557
activate brazil
freekmurze Jan 19, 2024
8cec285
calculate correct easter date
freekmurze Jan 19, 2024
6154861
Added Uganda holidays and Tests
Crawford30 Jan 19, 2024
67db06b
Fixed::Name having ' on it
Crawford30 Jan 19, 2024
a094266
Fix styling
freekmurze Jan 19, 2024
307b304
Add Venezuela country class and test
ricardomartos Jan 19, 2024
cf98cd7
Fix styling
freekmurze Jan 19, 2024
9f6347d
Add Macedonian holidays
object505 Jan 19, 2024
7da301a
Added return type
object505 Jan 19, 2024
27ab746
Fix styling
freekmurze Jan 19, 2024
139c956
Adding Nicaragua Holidays
calonzolg Jan 18, 2024
d4be094
fixing return for phpstan
calonzolg Jan 18, 2024
1167645
match utc time
calonzolg Jan 18, 2024
fe983b0
add philippine's regular holidays
kndrckjvr Jan 17, 2024
13f0939
Adding Full Mexican Holidays
davsaniuv Jan 17, 2024
7528c00
Add Test
davsaniuv Jan 17, 2024
00bcc61
update test description and remove typo,
davsaniuv Jan 17, 2024
e696676
remove vscode folder
davsaniuv Jan 17, 2024
149d336
Delete .vscode directory
davsaniuv Jan 17, 2024
89cdd36
Fix styling
freekmurze Jan 19, 2024
bb3f072
wip
freekmurze Jan 19, 2024
fedc663
fix test
freekmurze Jan 19, 2024
cd8854d
wip
freekmurze Jan 19, 2024
82ad417
Fix styling
freekmurze Jan 19, 2024
daf469c
Add support for Irish public holidays (#44)
marchanlon Jan 19, 2024
d59c1d5
Fix styling
Nielsvanpach Jan 19, 2024
5f4e4bb
use better easter calculation for Ireland
Nielsvanpach Jan 19, 2024
e427e24
use correct dates for nicaragua and venezuela
Nielsvanpach Jan 19, 2024
098556f
cleanup
Nielsvanpach Jan 19, 2024
b65633b
move to baseline
Nielsvanpach Jan 19, 2024
dd21d89
Add support for Croatian public holidays (#45)
mcbuckets Jan 19, 2024
774279d
use easter() instead
Nielsvanpach Jan 19, 2024
d6dee65
Fix styling
Nielsvanpach Jan 19, 2024
2cf0129
Bolivian holidays (#40)
rats4final Jan 19, 2024
083026e
remove unneeded conversion
Nielsvanpach Jan 19, 2024
a6f754b
Add Estonian holidays (#47)
hulkur Jan 19, 2024
1c519e1
Easter method corrected after rebase
juref-specto Jan 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 39 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,21 @@ 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.

```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 +87,40 @@ use Spatie\Holidays\Holidays;
Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar
```

## Contributing a new country

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

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 contructor 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 +131,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
27 changes: 21 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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

Expand All @@ -21,9 +21,19 @@ 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: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Mexico\\:\\:transmisionPoderEjecutivoFederal\\(\\) has parameter \\$year with no type specified\\.$#"
count: 1
path: src/Countries/Mexico.php

-
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Mexico\\:\\:variableHolidays\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, string\\|true\\>\\.$#"
count: 1
path: src/Countries/Mexico.php

-
message: "#^Cannot call method isSunday\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#"
Expand All @@ -44,3 +54,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);
41 changes: 41 additions & 0 deletions src/Countries/Andorra.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Andorra extends Country
{
public function countryCode(): string
{
return 'ad';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Any nou' => '01-01',
'Reis' => '01-06',
'Dia de la Constitució' => '03-14',
'Festa del Treball' => '05-01',
'Assumpció' => '08-15',
'Mare de Déu de Meritxell' => '09-08',
'Tots Sants' => '11-01',
'Immaculada Concepció' => '11-08',
'Nadal' => '12-25',
'Sant Esteve' => '12-26',
], $this->variableHolidays($year));
}

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

return [
'Divendres Sant' => $easter->subDays(2),
'Dilluns de Pasqua' => $easter->addDay(),
'Dilluns de Pentecosta' => $easter->addDays(50),
];
}
}
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
4 changes: 1 addition & 3 deletions src/Countries/Belgium.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public function countryCode(): string
return 'be';
}

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

/** @return array<string, CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge([
Expand All @@ -22,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
Loading