/Mamemaki.HolidayJp

Calculate Japan public Holidays

Primary LanguageC#OtherNOASSERTION

Mamemaki.HolidayJp

Actions Status NuGet Badge License

.NET library for Calculate Japan public Holidays

  • Purely holiday calculator.
  • No dataset or other external resources used
  • No dependencies
  • Support 1955 to 2150 years range
  • Tested with syukujitsu.csv

Install

Install with NuGet:

PM> Install-Package Mamemaki.HolidayJp

Example Usage

Calculate public holidays of a year

var holidays = HolidayCalculator.GetHolidaysInYear(2019);
foreach (var holiday in holidays)
{
    Console.WriteLine($"[{holiday.Date.ToString("yyyy/MM/dd")}] {holiday.Name}");
}

Get public holidays for a date range

var jphol = new JapanHoliday();
var startDate = new DateTime(2016, 5, 1);
var endDate = new DateTime(2018, 5, 31);
var holidays = jphol.GetHolidaysInDateRange(startDate, endDate);
foreach (var holiday in holidays)
{
    Console.WriteLine($"[{holiday.Date.ToString("yyyy/MM/dd")}] {holiday.Name}");
}

Get public holiday for a date

var jphol = new JapanHoliday();
var date = new DateTime(2019, 1, 1);
var holiday = jphol.GetHoliday(date);
if (holiday != null)
{
    Console.WriteLine($"[{holiday.Date.ToString("yyyy/MM/dd")}] {holiday.Name}");
}
else
{
    Console.WriteLine($"{date.ToString("yyyy/MM/dd")} is not public holiday");
}

Check if a date is a weekend/weekday/holiday/workingday day

var jphol = new JapanHoliday();
var date = new DateTime(2019,11,8);
Console.WriteLine($"{date.ToString("yyyy/MM/dd")} is {(jphol.IsWeekday(date) ? "weekday" : "not weekday")}");
Console.WriteLine($"{date.ToString("yyyy/MM/dd")} is {(jphol.IsWeekend(date) ? "weekend" : "not weekend")}");
Console.WriteLine($"{date.ToString("yyyy/MM/dd")} is {(jphol.IsHoliday(date) ? "holiday" : "not holiday")}");
Console.WriteLine($"{date.ToString("yyyy/MM/dd")} is {(jphol.IsWorkingDay(date) ? "workingday" : "not workingday")}");
Console.WriteLine($"{date.ToString("yyyy/MM/dd")}'s next workingday is {jphol.NextWorkingDay(date).ToString("yyyy/MM/dd")}");
Console.WriteLine($"{date.ToString("yyyy/MM/dd")}'s previous workingday is {jphol.PreviousWorkingDay(date).ToString("yyyy/MM/dd")}");

API References

Holiday object

Name Description
Date Date of the holiday.
Kind Kind of the holiday. see HolidayKind.
Name Name of the holiday in Japanese.
GlobalName Name of the holiday in English.

HolidayKind enum

Name Description
National 国民の祝日
Citizens 国民の休日
Substitute 振替休日

HolidayCalculator class

This class is to calculate japan holidays. it has only one public method GetHolidaysInYear(int year) that calculates holidays in the specified year.

JapanHoliday class

This class has many utility methods for Japan holidays. And calculated results are cached so calculation does not execute twice.

Methods

IEnumerable<Holiday> GetHolidaysInYear(int year)

Get holidays in the specified year.

IEnumerable<Holiday> GetHolidaysInDateRange(DateTime dateStart, DateTime dateEnd)

Get public holidays for a date range.

Holiday GetHoliday(DateTime date)

Get holidays in the specified year.

bool IsHoliday(DateTime date)

Check if a date is a public holiday.

bool IsWeekday(DateTime date)

Check if a date is a weekday. weekday means Monday to Friday.

bool IsWeekend(DateTime date)

Check if a date is a weekend weekend means Saturday or Sunday.

bool IsWorkingDay()

Check if today is a working day. working day means Monday to Friday and does not holiday.

bool IsWorkingDay(DateTime date)

Check if a date is a working day. working day means Monday to Friday and does not holiday.

DateTime NextWorkingDay(DateTime date)

Get next working day of the specified date. working day means Monday to Friday and does not holiday.

DateTime PreviousWorkingDay(DateTime date)

Get previous working day of the specified date. working day means Monday to Friday and does not holiday.

Thanks

内閣府ホームページ

https://zariganitosh.hatenablog.jp/entry/20140929/japanese_holiday_memo

https://www.pahoo.org/e-soul/webtech/php02/php02-27-01.shtm

https://www.atmarkit.co.jp/ait/articles/1507/22/news024.html

License

Apache 2.0