Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/seanbehan/holiday
https://github.com/seanbehan/holiday
Last synced: 28 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/seanbehan/holiday
- Owner: seanbehan
- Created: 2011-09-11T01:53:46.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-09-12T13:19:32.000Z (over 13 years ago)
- Last Synced: 2024-11-16T16:11:41.900Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 109 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Holiday
Holiday is a gem that lets you configure holidays for multiple countries with YAML.
## Default Usage
First setup path to a YAML file and set the country code.
```ruby
Holiday.yaml_file = "/path/to/yaml/holiday.yml"
Holiday.country = "US"```
You can query for dates
```ruby
# Defaults to current year
Holiday.find("christmas")
Holiday.find("labour day")```
Or supply a year
```ruby
# Can supply the year as optional argument
Holiday.find(:christmas, 2005)
Holiday.find(:thanksgiving, 1999)```
## YAML
The YAML format for Holiday is as follows
```yaml
holiday:
US:
christmas:
when: december 25th
as: christmas
halloween:
when: october 31st
as: halloween, all hallows eve
labor_day:
when: 1st monday in september
as: labor day, labour day
thanksgiving:
when: 4th thursday in november
as: thanksgiving, turkey day
```Holidays are scoped by country code. Each holiday needs both "when" and "as" keys. The "when" key can either be an exact
month and day, or the occurrence of the holiday in the given month. E.g., "1st monday in september".The "as" key is used to identify holidays by alternate names and spellings. For instance, "thanksgiving" and "turkey day" should both
point to the 4th thursday in november.```ruby
Holiday.find("turkey day")
Holiday.find(:thanksgiving)```
## Other methods
There are a few other methods that may be useful
```ruby
Holiday.all # array containing all keys and alternate names of holidays from yaml file
Holiday.scan("a string containing a holiday by name, like christmas") # => christmas
Holiday::Query.find("all hallows eve") # => october 31st```