Skip to content

Commit

Permalink
Australia - Fix Easter Sunday (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager authored Mar 19, 2024
1 parent 1ea439b commit a75a9d5
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
64 changes: 64 additions & 0 deletions src/Nager.Date.UnitTest/Countries/AustraliaTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace Nager.Date.UnitTest.Countries
{
[TestClass]
public class AustraliaTest
{
[TestMethod]
public void TestEasterSunday2021()
{
var year = 2021;
var expectedSubdivisionCodes = new string[] { "AU-ACT", "AU-NSW", "AU-QLD", "AU-VIC" };

this.TestEasterSunday(year, expectedSubdivisionCodes);
}

[TestMethod]
public void TestEasterSunday2022()
{
var year = 2022;
var expectedSubdivisionCodes = new string[] { "AU-ACT", "AU-NSW", "AU-QLD", "AU-VIC", "AU-WA" };

this.TestEasterSunday(year, expectedSubdivisionCodes);
}

[TestMethod]
public void TestEasterSunday2023()
{
var year = 2023;
var expectedSubdivisionCodes = new string[] { "AU-ACT", "AU-NSW", "AU-NT", "AU-QLD", "AU-VIC", "AU-WA" };

this.TestEasterSunday(year, expectedSubdivisionCodes);
}

[TestMethod]
public void TestEasterSunday2024()
{
var year = 2024;
var expectedSubdivisionCodes = new string[] { "AU-ACT", "AU-NSW", "AU-NT", "AU-QLD", "AU-SA", "AU-VIC", "AU-WA" };

this.TestEasterSunday(year, expectedSubdivisionCodes);
}

[TestMethod]
public void TestEasterSunday2025()
{
var year = 2025;
var expectedSubdivisionCodes = new string[] { "AU-ACT", "AU-NSW", "AU-NT", "AU-QLD", "AU-SA", "AU-VIC", "AU-WA" };

this.TestEasterSunday(year, expectedSubdivisionCodes);
}

private void TestEasterSunday(int year, string[] expectedSubdivisionCodes)
{
var englishName = "Easter Sunday";

var holidays = HolidaySystem.GetHolidays(year, CountryCode.AU);
var easterSundayHoliday = holidays.FirstOrDefault(holiday => holiday.EnglishName == englishName);
Assert.IsNotNull(easterSundayHoliday);
CollectionAssert.AreEquivalent(expectedSubdivisionCodes, easterSundayHoliday.SubdivisionCodes);
}
}
}
15 changes: 10 additions & 5 deletions src/Nager.Date/HolidayProviders/AustraliaHolidayProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,18 @@ private HolidaySpecification EasterSunday(int year)
{
var holidaySpecification = this._catholicProvider.EasterSunday("Easter Sunday", year);

var counties = new [] { "AU-ACT", "AU-NSW", "AU-VIC" };
if (year >= 2022)
string[] subdivisionCodes = year switch
{
counties = ["AU-ACT", "AU-NSW", "AU-VIC", "AU-WA"];
}
< 2010 => [],
>= 2010 and <= 2015 => ["AU-NSW"],
2016 => ["AU-ACT", "AU-NSW", "AU-VIC"],
>= 2017 and <= 2021 => ["AU-ACT", "AU-NSW", "AU-QLD", "AU-VIC"],
2022 => ["AU-ACT", "AU-NSW", "AU-QLD", "AU-VIC", "AU-WA"],
2023 => ["AU-ACT", "AU-NSW", "AU-NT", "AU-QLD", "AU-VIC", "AU-WA"],
>= 2024 => ["AU-ACT", "AU-NSW", "AU-NT", "AU-QLD", "AU-SA", "AU-VIC", "AU-WA"]
};

holidaySpecification.SubdivisionCodes = counties;
holidaySpecification.SubdivisionCodes = subdivisionCodes;
return holidaySpecification;
}

Expand Down

0 comments on commit a75a9d5

Please sign in to comment.