Skip to content
forked from toggl/holidefs

Definition-based national holidays in Elixir

License

Notifications You must be signed in to change notification settings

vanjabucic/holidefs

 
 

Repository files navigation

Holidefs

CI Module Version Hex Docs Total Download License Last Updated

Definition-based national holidays in Elixir.

Installation

The package can be installed by adding :holidefs to your list of dependencies in mix.exs:

def deps do
  [
    {:holidefs, git: "https://github.com/vanjabucic/holidefs.git"}
  ]
end

Configuration

# Limit the holiday definitions to US
config :holidefs, locales: [:us]

Usage

To get holidays from you country you can use the functions on Holidefs module, like this:

Holidefs.between(:us, ~D[2018-03-01], ~D[2018-04-01])
# => {:ok, [%Holidefs.Holiday{name: "Good Friday", ...}, ...]}

See Holidefs doc to the complete list of functions.

Also, for all these functions you can give a list of options like this:

{:ok, holidays} = Holidefs.between(:us, ~D[2024-01-01], ~D[2025-01-01], include_informal?: true, observed?: true)

Or, example for Nerck holidays

defmodule NercHolidays do
  @nerc_holidays ["New Year's Day", "Memorial Day", "Independence Day", "Labor Day", "Thanksgiving", "Christmas Day"]

  def example(year) do
    {:ok, holidays} = Holidefs.between(:us, year, include_informal?: true, observed?: true)

    holidays
    |> Enum.filter(&(&1.name in @nerc_holidays))
    # |> Enum.map(& &1.observed_date)
    # |> Enum.map(&Date.to_gregorian_days(&1))
  end
end

For the complete list of options and their meaning check Holidefs.Options doc

License

Copyright (c) 2022 Toggl

This software is released under the MIT License.

About

Definition-based national holidays in Elixir

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 98.5%
  • Nix 1.5%