View Source ChineseHoliday (chinese_holiday v0.1.2)

Provides utilities for handling chinese holiday related problems.

Link to this section 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.

Link to this section Functions

@spec get_supported_years() :: list()

Gets all the supported years.

examples

Examples

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

Gets the version of data.

The version is a plain %DateTime{}.

examples

Examples

iex> ChineseHoliday.get_version()
~U[2022-12-10 02:02: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

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

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