Knows about workdays and holidays, public and otherwise. Answers the age-old question When is mothersday this year?.
Add this line to your application's Gemfile:
gem 'timetress'
And then execute:
$ bundle
Or install it yourself as:
$ gem install timetress
Timetress.christmas 2012
=> #<Date: 2012-12-25>
# On New Year's Eve, 2011
Timetress.next_christmas
=> #<Date: 2012-12-25>
# On Christmas Day, 2012
Timetress.previous_christmas
=> #<Date: 2011-12-25>
A public holiday, national holiday or legal holiday is a holiday generally established by law and is usually a non-working day during the year.
- Wikipedia
Timetress::Norway.public_holidays(2012)
=> [#<Date: 2012-01-01>, #<Date: 2012-04-05>,...]
Timetress::Scotland.public_holidays(2012)
=> [#<Date: 2012-01-02>, #<Date: 2012-01-03>,...]
A workday is a day of the week which is neither a weekend, nor a public holiday.
Timetress::Norway.workday? Date.new(2012, 1, 5)
=> true
Timetress::Norway.workday? Date.new(2012, 5, 17)
=> false
Timetress::Scotland.workday? Date.new(2012, 1, 2)
=> false
In calculating deadlines and lead time, it's often helpful to count workdays:
Timetress::Norway.nth_workday_before 4, Date.new(2012, 10, 25)
=> #<Date: 2012-10-19>
Timetress::Norway.nth_workday_after 1, Date.new(2012, 10, 25)
=> #<Date: 2012-10-26>
Public holidays are emphasized below.
- New Year's Day: January 1st.
- Mothersday: Second Sunday in February.
- Valentines Day: February 14.
- Labour Day: May 1.
- National Holiday: May 17.
- Maundy Thursday: The Thursday before Easter Sunday.
- Good Friday: The Friday before Easter Sunday.
- Easter Sunday: Don't ask. It's crazy.
- Easter Monday: The day after Easter Sunday.
- Ascension: The Thursday which is the 40th day after Easter.
- Pentecost Sunday: The Sunday which is the 50th day after Easter.
- Pentecost Monday: The Sunday which is the 51st day after Easter.
- Fathersday: Second Sunday in November.
- Christmas Eve: December 24th.
- Christmas: December 25th.
- Boxing Day: December 26th.
Bank holidays are holidays when banks and many other businesses are closed for the day. Public holidays are holidays which have been observed through custom and practice.
In Scotland, bank holidays always extend the weekend. This is done via a royal proclamation.
Royal proclamation is used to move bank holidays that would otherwise fall on a weekend. In this way, public holidays are not 'lost' in years when they coincide with weekends.
Essentially, if a holiday lands on a weekend, there is a royal proclamation "moving" the day everybody gets off work to the next weekday. I.e. if New Year's Days is on a Sunday, everybody gets Monday off.
- New Year's Day: January 1st
- New Year's Holiday: January 2nd
- Good Friday: The Friday before Easter Sunday
- May Day: First Monday in May
- Spring Holiday/Victoria Day: The last Monday in May
- Summer Holiday: First Monday in August
- St. Andrew's Day: November 30th / royal proclamation
- Christmas Day: December 25th / royal proclamation
- Boxing Day: December 26th / royal proclamation
All of the bank holidays (without royal proclamation) plus:
- Mother's Day: Fourth Sunday in Lent
- Father's Day: Third Sunday in June
The cycle of Easter dates repeats after exactly 5,700,000 years, with April 19 being the most common date.
http://en.wikipedia.org/wiki/Computus
The current implementation simply has a list of 200 years worth of easter.
There are numerous holidays that did not make it onto the list in the first pass, mostly because I don't know about them. I had to look all but New Year's Eve up on Wikipedia.
Please do add missing holidays, as well as modules for other countries.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request