Skip to content

Commit

Permalink
Fix Health and Sports Day (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager authored Oct 10, 2023
1 parent b9d7e11 commit d15cfce
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.46.0] - XXXX-XX-XX

### Fixed
- Japan - Fix Health and Sports Day

## [1.45.0] - 2023-08-27

### Added
Expand Down
51 changes: 42 additions & 9 deletions src/Nager.Date/PublicHolidays/JapanProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
//using AASharp;

namespace Nager.Date.PublicHolidays
{
Expand Down Expand Up @@ -50,23 +49,25 @@ public IEnumerable<PublicHoliday> GetHolidays(int year)
items.Add(new PublicHoliday(thirdMondayInJuly, "海の日", "Marine Day", countryCode));
items.Add(new PublicHoliday(mountainDay, "山の日", "Mountain Day", countryCode));
items.Add(new PublicHoliday(thirdMondayInSeptember, "敬老の日", "Respect for the Aged Day", countryCode));
items.Add(new PublicHoliday(secondMondayInOctober, "体育の日", "Health and Sports Day", countryCode));
items.Add(new PublicHoliday(cultureDay, "文化の日", "Culture Day", countryCode));
items.Add(new PublicHoliday(thanksgivingDay, "勤労感謝の日", "Labour Thanksgiving Day", countryCode));

//Will change to the date of the new emperor on the death of the current one
items.AddIfNotNull(this.GetEmperorsBirthday(year, countryCode));
items.AddIfNotNull(this.GetVernalEquinox(year, countryCode));
items.AddIfNotNull(this.GetAutumnalEquinox(year, countryCode));
items.AddIfNotNull(this.EmperorsBirthday(year, countryCode));
items.AddIfNotNull(this.VernalEquinox(year, countryCode));
items.AddIfNotNull(this.AutumnalEquinox(year, countryCode));

items.AddIfNotNull(this.SportsDay(year, countryCode));

return items.OrderBy(o => o.Date);
}

/// <summary>
/// https://en.wikipedia.org/wiki/Golden_Week_(Japan)
/// Get the Golden Week for a given year
/// </summary>
/// <see href="https://en.wikipedia.org/wiki/Golden_Week_(Japan)" />
/// <param name="year"></param>
[Obsolete("Not a holiday logic")]
public DateTime GetGoldenWeekStartDate(int year)
{
var showaDay = new DateTime(year, 4, 29).Shift(saturday => saturday, sunday => sunday.AddDays(1));
Expand All @@ -81,7 +82,7 @@ public DateTime GetGoldenWeekStartDate(int year)
/// <param name="year"></param>
/// <param name="countryCode"></param>
/// <returns>Emperors Birthday object or null</returns>
private PublicHoliday GetEmperorsBirthday(int year, CountryCode countryCode)
private PublicHoliday EmperorsBirthday(int year, CountryCode countryCode)
{
if (year < 1868)
{
Expand Down Expand Up @@ -131,7 +132,39 @@ private PublicHoliday GetEmperorsBirthday(int year, CountryCode countryCode)
countryCode);
}

private PublicHoliday GetVernalEquinox(int year, CountryCode countryCode)
private PublicHoliday SportsDay(int year, CountryCode countryCode)
{
if (year <= 1965)
{
return null;
}
else if (year > 1965 && year < 2000)
{
return new PublicHoliday(new DateTime(year, 10, 10), "体育の日", "Health and Sports Day", countryCode);
}
else if (year >= 2000 && year < 2020)
{
var secondMondayInOctober = DateSystem.FindDay(year, Month.October, DayOfWeek.Monday, Occurrence.Second);
return new PublicHoliday(secondMondayInOctober, "体育の日", "Health and Sports Day", countryCode);
}
else if (year == 2020)
{
return new PublicHoliday(new DateTime(year, 07, 24), "スポーツの日", "Sports Day", countryCode);
}
else if (year == 2021)
{
return new PublicHoliday(new DateTime(year, 07, 23), "スポーツの日", "Sports Day", countryCode);
}
else if (year >= 2022)
{
var secondMondayInOctober = DateSystem.FindDay(year, Month.October, DayOfWeek.Monday, Occurrence.Second);
return new PublicHoliday(secondMondayInOctober, "スポーツの日", "Sports Day", countryCode);
}

return null;
}

private PublicHoliday VernalEquinox(int year, CountryCode countryCode)
{
if (year < 1850 || year > 2151)
{
Expand Down Expand Up @@ -160,7 +193,7 @@ private PublicHoliday GetVernalEquinox(int year, CountryCode countryCode)
return new PublicHoliday(new DateTime(year, 3, (int)equinoxDay), "春分の日", "Vernal Equinox Day", countryCode);
}

private PublicHoliday GetAutumnalEquinox(int year, CountryCode countryCode)
private PublicHoliday AutumnalEquinox(int year, CountryCode countryCode)
{
if (year < 1850 || year > 2151)
{
Expand Down

0 comments on commit d15cfce

Please sign in to comment.