View Source ChineseHoliday (chinese_holiday v0.2.0)

Provides utilities for handling chinese holiday related problems.

Summary

Functions

Gets all the supported years.

Gets the version of data.

Checks if a given date is a holiday.

Checks if a given date is a working day.

Functions

@spec get_supported_years() :: list()

Gets all the supported years.

Examples

iex> ChineseHoliday.get_supported_years()
[2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024]
@spec get_version() :: DateTime.t()

Gets the version of data.

The version is a plain %DateTime{}.

Examples

iex> ChineseHoliday.get_version()
~U[2023-11-08 08:31:00Z]
@spec is_holiday?(Date.t()) :: boolean()

Checks if a given date is a holiday.

Following dates will be considered as holidays:

  • dates in holiday schedules which are published by State Council of the People's Republic of China, aka. chinese statutory holiday.

To get the original information, please visit 中华人民共和国中央人民政府 - 政府信息公开, and search '节假日'.

Examples

# the holiday of lunar new year
iex> ChineseHoliday.is_holiday?(~D[2023-01-21])
true

# the holiday of lunar new year
iex> ChineseHoliday.is_holiday?(~D[2023-01-27])
true

# it's time to work ;)
iex> ChineseHoliday.is_holiday?(~D[2023-01-28])
false

# the holiday information is missing, so this function doesn't know how to handle it.
# in this case, it will log a warning message, and return `false`.
iex> ChineseHoliday.is_holiday?(~D[2090-01-28])
false
@spec is_working_day?(Date.t()) :: boolean()

Checks if a given date is a working day.

Following dates will be considered as working days:

  • dates marked as additional working days to compensate for the long holiday break.
  • dates which are normal weekdays (monday ~ friday), and are not in the duration of any holiday.

Examples

# additional working days
iex> ChineseHoliday.is_working_day?(~D[2023-01-28])
true

iex> ChineseHoliday.is_working_day?(~D[2023-01-29])
true

# weekdays in the duration of one holiday
iex> ChineseHoliday.is_working_day?(~D[2023-01-27])
false

# normal weekdays
iex> ChineseHoliday.is_working_day?(~D[2023-01-30])
true

iex> ChineseHoliday.is_working_day?(~D[2023-01-31])
true

# normal weekends
iex> ChineseHoliday.is_working_day?(~D[2023-02-11])
false

# the working day information is missing, so this function doesn't know how to handle it.
# in this case, it will log a warning message, and return `false`.
iex> ChineseHoliday.is_working_day?(~D[2090-01-28])
false