Skip to content

Commit

Permalink
Merge pull request #180 from spatie/bug/orthodox-easter
Browse files Browse the repository at this point in the history
Bug fix: calculating orthodox easter
  • Loading branch information
Nielsvanpach authored Jan 25, 2024
2 parents 37b0717 + 1fa7a39 commit 4d30204
Show file tree
Hide file tree
Showing 57 changed files with 130 additions and 84 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"laravel/prompts": "^0.1.15",
"pestphp/pest": "^2.31",
"phpstan/phpstan": "^1.10.56",
"spatie/invade": "^2.0",
"spatie/ray": "^1.40.1",
"symfony/var-dumper": "^6.4"
},
Expand Down
7 changes: 1 addition & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@ parameters:

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

-
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

-
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
Expand Down
9 changes: 6 additions & 3 deletions src/Countries/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ protected function easter(int $year): CarbonImmutable

protected function orthodoxEaster(int $year): CarbonImmutable
{
$timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN);
$daysDifference = (int) ($year / 100) - (int) ($year / 400) - 2;
// Paschal full moon date
// Not covered edge case:
// when the full moon is on a 3 April, Easter is the next Sunday
$easter = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-04-03")
->startOfDay();

return CarbonImmutable::createFromTimestamp(strtotime("+$daysDifference days", $timestamp));
return $easter->addDays(easter_days($year, CAL_EASTER_ALWAYS_JULIAN));
}

public static function find(string $countryCode): ?Country
Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/AndorraTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate andorra holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'ad')->get();

Expand Down
24 changes: 12 additions & 12 deletions tests/Countries/AustraliaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Spatie\Holidays\Holidays;

it('can calculate australian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Melbourne');
CarbonImmutable::setTestNow('2024-01-22');

$holidays = Holidays::for(country: 'au')->get();

Expand All @@ -19,7 +19,7 @@
});

it('can calculate australian holidays for a specific year', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Melbourne');
CarbonImmutable::setTestNow('2024-01-22');

$holidays = Holidays::for(country: 'au', year: 2025)->get();

Expand All @@ -31,7 +31,7 @@
});

it('can calculate regional australian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Melbourne');
CarbonImmutable::setTestNow('2024-01-22');

$holidays = Holidays::for(Australia::make('vic'))->get();

Expand All @@ -43,7 +43,7 @@
});

it('can calculate the day before afl grand final', function () {
CarbonImmutable::setTestNowAndTimezone('2021-01-22', 'Australia/Melbourne');
CarbonImmutable::setTestNow('2021-01-22');

$holidays = Holidays::for(Australia::make('vic'))->get();

Expand All @@ -52,7 +52,7 @@
});

it('can calculate the day before afl grand final during lockdown', function () {
CarbonImmutable::setTestNowAndTimezone('2020-01-22', 'Australia/Melbourne');
CarbonImmutable::setTestNow('2020-01-22');

$holidays = Holidays::for(Australia::make('vic'))->get();

Expand All @@ -61,7 +61,7 @@
});

it('does not return the day before afl grand final before 2015', function () {
CarbonImmutable::setTestNowAndTimezone('2014-01-22', 'Australia/Melbourne');
CarbonImmutable::setTestNow('2014-01-22');

$holidays = Holidays::for(Australia::make('vic'))->get();

Expand All @@ -70,7 +70,7 @@
});

it("returns queen's birthday before her death", function () {
CarbonImmutable::setTestNowAndTimezone('2021-01-22', 'Australia/Perth');
CarbonImmutable::setTestNow('2021-01-22', 'Australia/Perth');

$holidays = Holidays::for(Australia::make('wa'))->get();

Expand All @@ -82,7 +82,7 @@
});

it("returns king's birthday after her death", function () {
CarbonImmutable::setTestNowAndTimezone('2022-01-22', 'Australia/Perth');
CarbonImmutable::setTestNow('2022-01-22', 'Australia/Perth');

$holidays = Holidays::for(Australia::make('wa'))->get();

Expand All @@ -94,7 +94,7 @@
});

it('can calculate Adelaide Cup Day before 2006', function () {
CarbonImmutable::setTestNowAndTimezone('2005-01-22', 'Australia/Adelaide');
CarbonImmutable::setTestNow('2005-01-22', 'Australia/Adelaide');

$holidays = Holidays::for(Australia::make('sa'))->get();

Expand All @@ -103,7 +103,7 @@
});

it('can calculate Adelaide Cup Day after 2006', function () {
CarbonImmutable::setTestNowAndTimezone('2007-01-22', 'Australia/Adelaide');
CarbonImmutable::setTestNow('2007-01-22', 'Australia/Adelaide');

$holidays = Holidays::for(Australia::make('sa'))->get();

Expand All @@ -112,7 +112,7 @@
});

it('can calculate Reconciliation Day on 27 May', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-22', 'Australia/Canberra');
CarbonImmutable::setTestNow('2024-01-22', 'Australia/Canberra');

$holidays = Holidays::for(Australia::make('act'))->get();

Expand All @@ -121,7 +121,7 @@
});

it('can calculate Reconciliation Day after 27 May', function () {
CarbonImmutable::setTestNowAndTimezone('2025-01-22', 'Australia/Canberra');
CarbonImmutable::setTestNow('2025-01-22', 'Australia/Canberra');

$holidays = Holidays::for(Australia::make('act'))->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/AustriaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate austrian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'at')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/BangladeshTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate bangladesh holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'bd')->get();

Expand Down
8 changes: 4 additions & 4 deletions tests/Countries/BelarusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate belarus holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'by')->get();

Expand All @@ -18,7 +18,7 @@
});

it('can calculate belarus holidays in English', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'by', locale: 'en')->get();

Expand All @@ -30,7 +30,7 @@
});

it('can calculate belarus holidays in Belarus Lacinka', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'by', locale: 'be-latn')->get();

Expand All @@ -42,7 +42,7 @@
});

it('can calculate belarus holidays in Russian', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'by', locale: 'ru')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/BelgiumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate belgian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'be')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/BoliviaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate bolivian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'bo')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/BrazilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate brazil holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'br')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/CanadaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate canadian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'ca')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/ColombiaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate colombian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'co')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/CroatiaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate croatian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'hr')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/CzechiaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate czech holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'cz')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/DenmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate danish holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'da')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/DominicanRepublicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate dominican republic holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'do')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/ElSalvadorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate el salvador holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'sv')->get();

Expand Down
2 changes: 1 addition & 1 deletion tests/Countries/EstoniaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate estonian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Europe/Tallinn');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'ee')->get();

Expand Down
4 changes: 2 additions & 2 deletions tests/Countries/FinlandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Spatie\Holidays\Holidays;

it('can calculate finnish holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'fi')->get();

Expand All @@ -19,7 +19,7 @@
});

it('can get finnish holidays in swedish', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'fi', locale: 'sv')->get();

Expand Down
6 changes: 3 additions & 3 deletions tests/Countries/FranceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Spatie\Holidays\Holidays;

it('can calculate french holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'fr')->get();

Expand All @@ -19,7 +19,7 @@
});

it('can calculate french easter based region holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(France::make('FR-57'))->get();

Expand All @@ -31,7 +31,7 @@
});

it('can calculate french date based regional holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(France::make('FR-BL'))->get();

Expand Down
Loading

0 comments on commit 4d30204

Please sign in to comment.