nager / Nager.Date

Worldwide holidays (REST API), NuGet or docker container :earth_americas:
https://date.nager.at
MIT License
1.06k stars 172 forks source link

Japan - Not in accordance with national holiday law #566

Closed hisashi-kuwahara closed 3 months ago

hisashi-kuwahara commented 7 months ago

Affected country

Japan

Affected public holiday

substitute holiday

Source of the information

https://www8.cao.go.jp/chosei/shukujitsu/gaiyou.html

More information

In Japan, according to the law regarding national holidays, if a holiday falls on a Sunday, the holiday will not be moved and a substitute holiday will be set. (hereinafter referred to as Article 3, Paragraphs 2 and 3)

  1. If a "national holiday" falls on a Sunday, the next day that is not a "national holiday" that is closest to that day shall be considered a holiday.
  2. Days where the previous day and the next day are national holidays (limited to days that are not national holidays) are holidays.

e.g. Article 3, Paragraph 2 2025/5/3(sat)憲法記念日 2025/5/4(sun)みどりの日 2025/5/5(mon)こどもの日 2025/5/6(tue)substitute holiday

2025/11/23 勤労感謝の日 2025/11/24 substitute holiday

e.g. Article 3, Paragraph 3 2026/9/21(mon)敬老の日 2026/9/22(tue) substitute holiday 2026/9/23(wed)秋分の日

I have attached the code I made for Japan for your reference. JapanProvider.txt

tinohager commented 6 months ago

Link to discussion https://github.com/nager/Nager.Date/discussions/570#discussioncomment-7842743

tinohager commented 6 months ago

In Japan, according to the law regarding national holidays, if a holiday falls on a Sunday, the holiday will not be moved and a substitute holiday will be set. (hereinafter referred to as Article 3, Paragraphs 2 and 3)

  1. If a "national holiday" falls on a Sunday, the next day that is not a "national holiday" that is closest to that day shall be considered a holiday.
  2. Days where the previous day and the next day are national holidays (limited to days that are not national holidays) are holidays.

This is how it is regulated in most countries, as we do not currently have a better model for public holidays, we are postponing the holiday. It is clear that the original holiday remains there.

I have already started here with a logic that deals with this topic https://github.com/nager/Nager.Date/pull/367

Unfortunately I don't understand Japanese comments :)

            // 日本の振替休日

            // 祝日法第3条第2項
            // 「国民の祝日」が日曜日に当たるときは、その日後においてその日に最も近い「国民の祝日」でない日を休日とする。
            foreach (var item in items.Where(e => e.Date.DayOfWeek == DayOfWeek.Sunday).ToArray())
                for (var i = 1; ; i++)
                {
                    var transferDate = item.Date.AddDays(i);
                    if (transferDate.DayOfWeek != DayOfWeek.Sunday && !items.Any(e => e.Date == transferDate))
                    {
                        // 最も近い「国民の祝日」でない日
                        items.Add(new PublicHoliday(transferDate, "休日", "People's Day", countryCode)); // 振替休日を追加
                        break;
                    }
                }

            // 祝日法第3条第3項
            // その前日及び翌日が「国民の祝日」である日(「国民の祝日」でない日に限る。)は、休日とする。
            var targets = items.OrderBy(e => e.Date).ToArray(); // 日付順に並べ替え
            for (var i = 1; i < targets.Length; i++)
                if (targets[i].Date.Subtract(targets[i - 1].Date) == TimeSpan.FromDays(2)) // 祝日と祝日の間に「1日」の空きがある
                    items.Add(new PublicHoliday(targets[i].Date.AddDays(-1), "休日", "People's Day", countryCode)); // 振替休日を追加
tinohager commented 3 months ago

In the new version of Nager.Date we have now implemented the logic with which the moved date is also displayed.