holidays / holidays Goto Github PK
View Code? Open in Web Editor NEWA collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!
License: Other
A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!
License: Other
I'd like to remove some holidays that are defined in us.yml, and add some new ones. I only want to do this for usage at our organization. I'd also like to have these changes reflected on our heroku deploy. I really don't want to fork the gem, nor do I really want to unpack it and modify it locally. What's the ideal way to use the standard gem, but customize holidays using the yml files? It's not clear to me how to do this.
We should be tracking test coverage.
FYI, while investigating this I discovered that we still support Ruby 1.8.7 , which is so out of date that it should probably be dropped as part of this change.
Monkey patching Date
should be deprecated, then eventually moved into a core_extension
file for optional inclusion. Monkey patching was cool in 2007, but not so much now.
holidays 3.0.0 afaik
Backtrace from newrelic:
NoMethodError: undefined method `calculate_mday' for Date:Class
….0/gems/holidays-3.0.0/lib/generated_definitions/au.rb: 109:in `march_pub_hol_sa'
….0/gems/holidays-3.0.0/lib/generated_definitions/au.rb: 31:in `block in holidays_by_month'
…3.0.0/lib/holidays/definition/repository/proc_cache.rb: 30:in `call'
…3.0.0/lib/holidays/definition/repository/proc_cache.rb: 30:in `lookup'
…olidays-3.0.0/lib/holidays/use_case/context/between.rb: 81:in `call_proc'
…olidays-3.0.0/lib/holidays/use_case/context/between.rb: 28:in `block (3 levels) in call'
…olidays-3.0.0/lib/holidays/use_case/context/between.rb: 20:in `each'
…olidays-3.0.0/lib/holidays/use_case/context/between.rb: 20:in `block (2 levels) in call'
…olidays-3.0.0/lib/holidays/use_case/context/between.rb: 17:in `each'
…olidays-3.0.0/lib/holidays/use_case/context/between.rb: 17:in `block in call'
…olidays-3.0.0/lib/holidays/use_case/context/between.rb: 16:in `each'
…olidays-3.0.0/lib/holidays/use_case/context/between.rb: 16:in `call'
….bundle/ruby/2.1.0/gems/holidays-3.0.0/lib/holidays.rb: 122:in `between'
…leases/0.0.2183/app/controllers/holidays_controller.rb: 8:in `index'
Reproduce code
irb(main):003:0> Time.now
=> 2016-01-04 09:42:09 +1030
irb(main):004:0> Holidays.between(Time.now, 1.month.from_now, [:au_sa])
NoMethodError: undefined method `calculate_mday' for Date:Class
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/generated_definitions/au.rb:109:in `march_pub_hol_sa'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/generated_definitions/au.rb:31:in `block in holidays_by_month'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/definition/repository/proc_cache.rb:30:in `call'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/definition/repository/proc_cache.rb:30:in `lookup'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/use_case/context/between.rb:81:in `call_proc'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/use_case/context/between.rb:28:in `block (3 levels) in call'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/use_case/context/between.rb:20:in `each'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/use_case/context/between.rb:20:in `block (2 levels) in call'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/use_case/context/between.rb:17:in `each'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/use_case/context/between.rb:17:in `block in call'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/use_case/context/between.rb:16:in `each'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays/use_case/context/between.rb:16:in `call'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/holidays-3.0.0/lib/holidays.rb:122:in `between'
from (irb):4
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/railties-4.1.12/lib/rails/commands/console.rb:90:in `start'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/railties-4.1.12/lib/rails/commands/console.rb:9:in `start'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/railties-4.1.12/lib/rails/commands/commands_tasks.rb:69:in `console'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/railties-4.1.12/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /home/clockwerx/.rbenv/versions/2.1.7/lib/ruby/gems/2.1.0/gems/railties-4.1.12/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'irb(main):005:0>
When executing "gem install holidays" I get version 1.0.5 installed. But the definitions for :ch are not included, as I can see them in the sources on github, which also claim to be version 1.0.5.
months:
0:
name: Jueves Santo
regions: [es_pv, es_ct, es_na, es_v, es_vc, es_an]
function: easter(year)-3
name: Viernes Santo
regions: [es]
function: easter(year)-2
name: Lunes de Pascua
regions: [es_pv, es_ct, es_na, es_v, es_vc]
function: easter(year)+1
1:
name: Año Nuevo
regions: [es]
mday: 1
observed: to_monday_if_sunday
name: Día de Reyes
regions: [es]
mday: 6
observed: to_monday_if_sunday
2:
name: Día de Andalucía
regions: [es_an]
mday: 28
observed: to_monday_if_sunday
3:
name: Día de las Islas Baleares
regions: [es_ib]
mday: 1
observed: to_monday_if_sunday
name: San José
regions: [es_v, es_vc, es_cm, es_mu, es_m]
mday: 19
observed: to_monday_if_sunday
4:
name: San Jorge
regions: [es_ar, es_cl]
mday: 23
observed: to_monday_if_sunday
name: Día de Aragón
regions: [es_ar]
mday: 23
observed: to_monday_if_sunday
5:
name: Día del Trabajador
regions: [es]
mday: 1
observed: to_monday_if_sunday
name: Fiesta de la Comunidad
regions: [es_m]
mday: 2
observed: to_monday_if_sunday
name: Día de las Canarias
regions: [es_cn]
mday: 30
observed: to_monday_if_sunday
name: Día de la Región Castilla-La Mancha
regions: [es_cm]
mday: 31
observed: to_monday_if_sunday
6:
name: Día de la Región de Murcia
regions: [es_mu]
mday: 9
observed: to_monday_if_sunday
name: Día de La Rioja
regions: [es_lo]
mday: 9
observed: to_monday_if_sunday
7:
name: Santiago Apostol
regions: [es_ga]
mday: 23
observed: to_monday_if_sunday
8:
name: Asunción
regions: [es]
mday: 15
observed: to_monday_if_sunday
9:
name: Día de Ceuta
regions: [es_ce]
mday: 2
observed: to_monday_if_sunday
name: Día de Asturias
regions: [es_o]
mday: 8
observed: to_monday_if_sunday
name: Día de Extremadura
regions: [es_ex]
mday: 8
name: Fiesta Nacional de Cataluña
regions: [es_ct]
mday: 11
observed: to_monday_if_sunday
10:
name: Día de Valencia
regions: [es_vc, es_v]
mday: 9
observed: to_monday_if_sunday
name: Día de la Hispanidad
regions: [es]
mday: 12
observed: to_monday_if_sunday
11:
name: Todos los Santos
regions: [es]
mday: 1
observed: to_monday_if_sunday
12:
name: Día de la Constitución
regions: [es]
mday: 6
observed: to_monday_if_sunday
name: Inmaculada Concepción
regions: [es]
mday: 8
observed: to_monday_if_sunday
name: Navidad del Señor
regions: [es]
mday: 25
observed: to_monday_if_sunday
name: San Esteban
regions: [es_ib, es_ct]
mday: 26
observed: to_monday_if_sunday
tests: |
{Date.civil(2009,1,1) => 'Año Nuevo',
Date.civil(2009,1,6) => 'Día de Reyes',
Date.civil(2009,4,10) => 'Viernes Santo',
Date.civil(2009,5,1) => 'Día del Trabajador',
Date.civil(2009,8,15) => 'Asunción',
Date.civil(2009,10,12) => 'Día de la Hispanidad',
Date.civil(2009,11,1) => 'Todos los Santos',
Date.civil(2009,12,6) => 'Día de la Constitución',
Date.civil(2009,12,8) => 'Inmaculada Concepción',
Date.civil(2009,12,25) => 'Navidad del Señor'}.each do |date, name|
assert_equal name, (Holidays.on(date, :es, :informal)[0] || {})[:name]
end
[:es_pv, :es_ct, :es_na, :es_v, :es_vc, :es_].each do |r|
assert_equal 'Jueves Santo', Date.civil(2009,4,9).holidays(r)[0][:name]
assert_equal 'Lunes de Pascua', Date.civil(2009,4,13).holidays(r)[0][:name]
end
[:es_v, :es_vc, :es_cm, :es_mu, :es_m, :es_].each do |r|
assert_equal 'San José', Date.civil(2009,3,19).holidays(r)[0][:name]
end
[:es_ar, :es_cl, :es_].each do |r|
assert_equal 'San Jorge', Date.civil(2009,4,23).holidays(r)[0][:name]
end
[:es_vc, :es_v, :es_].each do |r|
assert_equal 'Día de Valencia', Date.civil(2009,10,9).holidays(r)[0][:name]
end
[:es_ib, :es_ct, :es_].each do |r|
assert_equal 'San Esteban', Date.civil(2009,12,26).holidays(r)[0][:name]
end
assert_equal 'Día de Andalucía', Date.civil(2009,2,28).holidays(:es_an)[0][:name]
assert_equal 'Día de las Islas Baleares', Date.civil(2009,3,1).holidays(:es_ib)[0][:name]
assert_equal 'Fiesta de la Comunidad', Date.civil(2006,5,2).holidays(:es_m)[0][:name]
assert_equal 'Día de las Canarias', Date.civil(2006,5,30).holidays(:es_cn)[0][:name]
assert_equal 'Día de la Región Castilla-La Mancha', Date.civil(2009,5,31).holidays(:es_cm)[0][:name]
assert_equal 'Día de la Región de Murcia', Date.civil(2009,6,9).holidays(:es_mu)[0][:name]
assert_equal 'Día de La Rioja', Date.civil(2009,6,9).holidays(:es_lo)[0][:name]
assert_equal 'Santiago Apostol', Date.civil(2009,7,23).holidays(:es_ga)[0][:name]
assert_equal 'Día de Ceuta', Date.civil(2009,9,2).holidays(:es_ce)[0][:name]
assert_equal 'Día de Asturias', Date.civil(2009,9,8).holidays(:es_o)[0][:name]
assert_equal 'Día de Extremadura', Date.civil(2009,9,8).holidays(:es_ex)[0][:name]
assert_equal 'Fiesta Nacional de Cataluña', Date.civil(2009,9,11).holidays(:es_ct)[0][:name]
The federal_reserve
region currently counts Inaguration Day as a holiday, but according to this it's not (just the Governors Board being closed, which doesn't count), so I think it should be removed.
Also, it doesn't look like Independence Day should be using to_monday_if_sunday
.
Hi,
for some reason it keeps trying to fetch it from https://github.com/alexdunae/holidays
"bundle install --local
Fetching https://github.com/alexdunae/holidays
error: Failed connect to github.com:443; Connection timed out while accessing https://github.com/alexdunae/holidays/info/refs
fatal: HTTP request failed"
i'm on Ubuntu 12.04
gem -v
1.8.15
In Japan there is a Buddhist calendar system called "rokuyo". More info here: http://www.seiyaku.com/customs/rokuyo.php. It is standard to see Rokuyo on most calendars printed in Japan.
The logic is complex but essentially each day has a rokuyo day which is one of 6 values, and unlike western weekdays (mon, tues, weds) they don't follow a consistent cycle and reset based on lunar month and other exceptions.
I'd like to make a new "rokuyo" file; if that's cool I'll raise a PR in the next month.
We will maintain our copy at https://github.com/wearemolecule/holidays. In case people are looking to get pull requests in one centralized repo.
Give me your tired, your poor,
Your huddled pull requests yearning to breathe free
It looks like the Fed holidays are incorrect based on this (shouldn't have christmas and new years eve):
http://www.federalreserve.gov/aboutthefed/k8.htm
I can submit a pull request if needed, just let me know.
Thanks a lot for this great gem (BTW I wrote a wrapper for java access (https://github.com/gdepourtales/holidays))
Below the typos I found
In ch.yaml :
Missing final s: Jeûne genevois
In fr.yaml:
The umlaut is should be on the 'e': Noël
The gem appears to miss out the Summer bank holiday in August i.e.
Holidays.on(Date.civil(2015,8,31), :gb, :observed)
=> []
(See https://www.gov.uk/bank-holidays for an accurate list for 2015/2016.)
Oddly, the gb data includes the last Monday of the month as a bank holiday: https://github.com/holidays/holidays/blob/v2.2.0/data/gb.yaml
Hi,
In gb.yaml St. Andrew's Day is incorrectly listed as informal:
This is now a Bank Holiday since 2007.
I'm not sure how to correct this, since dates prior to 2006 should still report informal.
When installing the latest version of the gem (version 1.0.4) we get an error
See this Stack post for error and workarounds http://stackoverflow.com/questions/7848937/error-instaling-holidays-gem/7849210#7849210
Couldn't understand why a dependency was added on holidays in the holidays gem. Could you explain why this was done?
May 8 is not a german holiday:
require "holidays"
require "holidays/de"
Date.civil(2010,5,8).holiday?(:de)
=> true
should be false
I'm trying to implement the Islamic holidays too, but when I create a yaml-file, for "islam", and then the rb-file, I get the error, that it can't be loaded. Why? Any Ideas?
First off - thanks for your work on this awesome gem.
The NZ region file includes the Nelson Anniversary, but has the region as :nz_ak
- which is Auckland (other end of the country, and has its own anniversary! - see here and here)
https://github.com/holidays/holidays/blob/master/data/nz.yaml#L42
The same goes for Taranaki, which is closer but still a separate region. According to the yml file, its anniversary also incorrectly falls under :nz_ak
.
It's not clear which is the Nelson region - :nz_nl
seems to be for Northland. I'd be happy to make a change to the data files themselves, but not confident I'd test them properly. Based on how I think things work, it might look something like:
2:
- name: Nelson Anniversary Day
regions: [nz_ne]
mday: 1
observed: closest_monday
and
3:
- name: Taranaki Anniversary Day
regions: [nz_ta]
week: 2
wday: 1
observed: closest_monday
Thanks muchly!
This year the 4th of July falls on a Saturday and is observed on Friday 3rd. However, when I run the following, the 4th is still listed as a holiday
y Holidays.between(Date.civil(2015,1,1),Date.civil(2015,12,31),:nyse)
Similarly the following returns false:
d = Date.civil(2015,7,3) d.holiday?(:nyse)
If this is a bug I'll be happy to investigate and supply a fix, but I want to confirm that I'm not missing part of the puzzle.
Thanks
Jason
Since Ruby 1.9.3 is no longer supported we should require the newer versions. This shouldn't (I hope) require code changes, simply a change in what we test on Travis.
Hi Alex,
If i do this:
date = Date.civil(2011,3,8)
(Holidays.on(date, :br, :informal))
=> [{:date=>Mon, 08 Mar 2011, :name=>"Carnaval", :regions=>[:br]}]
but
Date.civil(2011,3,8).holiday?(:br)
gives me: false...
thanks!
Using:
Rails 3.0.7
ruby-1.9.2-p136
Holidays can be revoked, created, and changed so there should be functionality that specifies the validity of a holiday in certain years. For example, Memorial Day prior to 1971 had a different definition: instead of always falling on May 30 it was changed to the last Monday in May. We need functionality that can select the correct holidays based on the year. So if we are searching for holidays that fall between 1970 and 1971, we should have logic that filters out the holiday definition based on date.
Perhaps something like:
5:
The gem is working perfectly fine in development mode when cache_classes is set to false. However, when in production mode gem fails to recognize the Canadian holidays e.g New year's day. I made some initial investigation and found that.
Line 342 of holidays.rb file
raise UnknownRegionError unless regions.all? { |r| r == :any or @@regions.include?(r) or begin require "holidays/#{r.to_s}"; rescue LoadError; false; end }
I believe we should we should have this modified to load the holiday definitions file if not loaded as follows (Just changed the order of condition)
raise UnknownRegionError unless regions.all? { |r| r == :any or begin require "holidays/#{r.to_s}"; rescue LoadError; false; end or @@regions.include?(r)}
Also, why do we have :ca region specified in holidays/us.rb holiday definition file?
If I call DateTime.now.holiday?(:region)
on a holiday, it returns false. However DateTime.now.to_date.holiday?(:region)
and Date.today.holiday?(:region)
will behave as expected
Hi,
I would fix these myself but I'm not sure how, hopefully you can help!
http://www.justice.qld.gov.au/fair-and-safe-work/industrial-relations/public-holidays/dates lists public holidays in Queensland.
Thanks!
I run into the following problem.
The first time when I use a region outside of north-america (eg. :de , :no, :el) in a Holidays Method (Holidays.on, Holidays.between) I get a UnknownRegionError, but firing the command a second time Holidays returns the
right value.
ruby-1.9.2-p290 :017 > g = Holidays.on('2011-1-1'.to_date, :el)
Holidays::UnknownRegionError: Holidays::UnknownRegionError
from /home/roland/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/holidays-1.0.3/lib/holidays.rb:308:in parse_regions' from /home/roland/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/holidays-1.0.3/lib/holidays.rb:279:in
parse_options'
from /home/roland/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/holidays-1.0.3/lib/holidays.rb:103:in between' from /home/roland/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/holidays-1.0.3/lib/holidays.rb:66:in
on'
from (irb):17
from /home/roland/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/railties-3.0.9/lib/rails/commands/console.rb:44:in start' from /home/roland/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/railties-3.0.9/lib/rails/commands/console.rb:8:in
start'
from /home/roland/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/railties-3.0.9/lib/rails/commands.rb:23:in <top (required)>' from script/rails:6:in
require'
from script/rails:6:in `
ruby-1.9.2-p290 :018 > g = Holidays.on('2011-1-1'.to_date, :el)
=> [{:date=>Sat, 01 Jan 2011, :name=>"Πρωτοχρονιά", :regions=>[:el]}]
While researching #141 I found that it seems as if observed holidays that fall across month boundaries are not found as expected.
An example: Holidays.on(Date.civil(2017, 1, 30), :nz_ne, :observed)
The reason that I see is that when we build the dates hash here we do it based on the specified month. In the case above it will return {2017 => [0, 1]}
since we gave 1/30/2017. The issue is that the definition we want is found in month 2. We never interrogate the holidays in that month/region since we are only looking at generic (i.e. easter or yearly holidays, the 0) or January holidays. We never check February holidays and thus never perform the 'observed' method for 'closest monday from 2/1/2017' and thus never get 1/30/2017.
One easy but maybe crappy solution is to grab additional months when building the dates hash. If we have 1 then we also grab 2. If we have 6 then we also grab 5 and 7. This will increase the amount of processing we do but it will guarantee that we catch month-spanning calculations.
Although technically the public holiday is both Saturday 25th April and Monday 27th April (as per http://www.commerce.wa.gov.au/labour-relations/public-holidays-western-australia), the rule of "to_monday_if_weekend" is not working. Instead I'm seeing the following (all loaded):
{:date=>Sat, 25 Apr 2015, :name=>"ANZAC Day", :regions=>[:au]}
{:date=>Sat, 25 Apr 2015, :name=>"ANZAC Day", :regions=>[:au_nsw, :au_vic, :au_qld, :au_nt, :au_act, :au_sa, :au_tas]}
{:date=>Sat, 25 Apr 2015, :name=>"ANZAC Day", :regions=>[:au_wa, :nz]}
When I tried to add a custom holiday using a yaml file as per the Readme instructions, I got a NoMethodError: undefined method call' for "easter(year)-47":String error
.
Holidays.call_proc
is waiting for a Proc
, but when the yaml is loaded by .load_custom
, function nodes are are sent to .call_proc
as regular Strings.
I didn't dive into the code much, but I implemented a solution that didn't break any tests. Maybe there's a better way of doing this.
module Holidays
def self.call_proc(function, year) # :nodoc:
proc_key = Digest::MD5.hexdigest("#{function.to_s}_#{year.to_s}")
@@proc_cache[proc_key] = string_to_proc(function).call(year) unless @@proc_cache[proc_key]
@@proc_cache[proc_key]
end
def self.string_to_proc(function)
function.is_a?(String) ? Proc.new{ |year| eval(function) } : function
end
end
Hi,
It will be very nice if the Bulgarian holidays are added. I've prepared "bg.yaml" that is tested. It seems it is working fine. The problem is that the Orthodox Easter is calculated according the Julian calender -> http://en.wikipedia.org/wiki/Easter. I found this functionality implemented in project https://github.com/Loyolny/when_easter, so I used it. Maybe you could implement the same code for the Orthodox Easter calculations or just use the plug in.
How can I send you the yaml file?
Best regards!
I know this is a small project but I feel strongly that a Code of Conduct should be added if for no other reason than to indicate my overt support for a friendly, open, and cooperative open source community.
I'll be adding something along the lines of the Contributor Covenant in the coming weeks. I'm only waiting because I have a good head of steam going in my current work and don't want to lose that momentum. 😄
I have heard from co-workers that the new container-based Travis CI options are much faster. I want to look into switching (which seems straightforward) and testing it.
Doc: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
I think the code to roll christmas day and boxing day for UK holidays isn't quite right.
If Christmas day falls on a Saturday, then it will be _observed _ on Monday 27th Dec, with Boxing day observed on Tuesday 28th Dec.
If Christmas day falls on a Sunday, it will be observed on the Monday (26th Dec), with Boxing day observed on the Tuesday 27th.
I believe these cases do not work at the moment.
Culprit code :
regions.delete_if do |reg|
if reg.to_s =~ /_$/
prefix = reg.to_s.split('_').first
unless @@regions.include?(prefix.to_sym)
begin
require "holidays/#{prefix}"
rescue LoadError
raise UnknownRegionError, "Could not load holidays/#{prefix}"
end
end
regions << @@regions.select { |dr| dr.to_s =~ Regexp.new("^#{reg}") }
true
end
end
Let's say you can upload a file to /tmp on the server, like profile_pic.jpg that contains some ruby
Calling Holidays.between(Time.now, 2.years.from_now, '../../../../../../../../../../../../tmp/profile_pic.jpg')
will execute the ruby code inside the file.
the region parameter can be something issued from a user params, hence this issue.
Thanks
It seems the holiday? method is broken in version 3.0.0 (although I have not tested any other versions):
gem install holidays
Fetching: holidays-3.0.0.gem (100%)
Successfully installed holidays-3.0.0
Parsing documentation for holidays-3.0.0
Installing ri documentation for holidays-3.0.0
Done installing documentation for holidays after 1 seconds
1 gem installedirb -rpp
'
2.2.0 :001 > require 'holidays'
=> true
2.2.0 :002 > require 'generated_definitions/us'
=> true
2.2.0 :003 > Date.today.holiday?
NoMethodError: undefined methodholiday?' for #<Date: 2015-12-16 ((2457373j,0s,0n),+0s,2299161j)> from (irb):3 from /Users/user/.rvm/rubies/ruby-2.2.0/bin/irb:11:in
2.2.0 :004 > require 'holidays/core_extensions/date'
=> true
2.2.0 :005 > Date.today.holiday?
NoMethodError: undefined methodholiday?' for #<Date: 2015-12-16 ((2457373j,0s,0n),+0s,2299161j)> from (irb):5 from /Users/user/.rvm/rubies/ruby-2.2.0/bin/irb:11:in
'
2.2.0 :006 > Date.today.holiday?(:us)
NoMethodError: undefined methodholiday?' for #<Date: 2015-12-16 ((2457373j,0s,0n),+0s,2299161j)> from (irb):6 from /Users/user/.rvm/rubies/ruby-2.2.0/bin/irb:11:in
'
2.2.0 :007 >
Is there a way to get the next x
number of holidays? I saw between
, but we have a couple of uses where we'd like to get the next 2, and next 4 holidays.
Thanks
According to comments left in the Canadian definitions there seem to be certain holidays that should only apply after a certain year. We now have this functionality so we should update the definitions to make them more accurate.
Holidays in question:
New tests should be added to confirm that it gives the proper answers both before and after the cutoff.
Day after Thanksgiving does not always get calculated to the date following Thanksgiving. If the first day of the month falls on a Friday the the current calculation of the 4th Friday doesn't work and ends up being the week before Thanksgiving. It really should be calculated as the 4th Thursday + 1 day
> Holidays.between(Date.new(2013, 11, 01), Date.new(2013, 11, 30), :us_ca, :us, :informal)
=> [{:date=>Mon, 11 Nov 2013, :name=>"Veterans Day", :regions=>[:us]}, {:date=>Fri, 22 Nov 2013, :name=>"Day after Thanksgiving", :regions=>[:us_ca]}, {:date=>Thu, 28 Nov 2013, :name=>"Thanksgiving", :regions=>[:us]}]
Hi,
I am using version 1.0.5 of the gem and ever since the 30th have starting seeing a very odd issue (I wonder whether it could be related to the UK entering British Summer Time?)
Anyway:
Loading development environment (Rails 3.2.13)
irb(main):001:0> Holidays.on(Date.parse("2013-03-01"), :europe)
=> []
irb(main):002:0> Holidays.on(Date.parse("2013-03-01"), :europe)
Holidays::UnknownRegionError: Holidays::UnknownRegionError
from /var/lib/gems/1.9.1/bundler/gems/holidays-a365bba33b76/lib/holidays.rb:342:in `parse_regions'
from /var/lib/gems/1.9.1/bundler/gems/holidays-a365bba33b76/lib/holidays.rb:313:in `parse_options'
from /var/lib/gems/1.9.1/bundler/gems/holidays-a365bba33b76/lib/holidays.rb:124:in `between'
from /var/lib/gems/1.9.1/bundler/gems/holidays-a365bba33b76/lib/holidays.rb:70:in `on'
from (irb):2
from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Any idea what is going on here? All other regions appear to work fine.
What are people's thoughts about the current test suite? In the process of refactoring I am adding a bunch of new tests and I'm starting to wonder if I should spend the time to convert us to rspec.
I'll admit that I am partial to it over Test::Unit. It has a lot of additional features that I have come to rely upon. I'm really torn, though, because it's a lot of work and we already have working tests.
Looking for thoughts from others to help me decide.
Currently we have no minimum for the ruby version, which isn't true anymore. According to our Travis config we are only supporting 1.9.2 and up. This should be reflected.
In 2012 is Veterans Day in US on Sunday Nov 11.
According http://www.timeanddate.com/holidays/us/veterans-day if Veterans Day falls on a Sunday, Federal Offices are closed on Monday November 12.
Hi,
I'm trying to use this in an application to mark Bank Holidays in a user's calendar.
In order to make this work I'm assuming I need to collect the region a user is in, and to do that I'm going to need a list of regions, converted to English names (at the very least, possibly I18n'ed names in the future).
Is there anyway to do that?
Also, there seems to be some regions I wouldn't want a user to select. For example, if gb_con (Cornwall) is selected, then this will no longer show Easter Monday in England, which is incorrect:
> Holidays.on(Date.parse('2016-03-28'), :gb_con)
=> []
> Holidays.on(Date.parse('2016-03-28'), :gb_eng)
=> [{:date=>Mon, 28 Mar 2016, :name=>"Easter Monday", :regions=>[:gb_eng, :gb_wls, :gb_eaw, :gb_nir]}]
Holidays.easter 2012
=> Sun, 08 Apr 2012
That is all well and good but
date=Date.civil 2012, 4, 8
=> Sun, 08 Apr 2012
Holidays.on date,:us,:observed
=> []
and
date.holiday? :us
=> false
Also found weird behaviors such as:
development environment (Rails 3.2.3)
irb(main):001:0> d=Date.civil 2012,7,4
=> Wed, 04 Jul 2012
irb(main):002:0> d.holidays
=> []
irb(main):003:0> d.holidays :us
=> [{:date=>Wed, 04 Jul 2012, :name=>"Independence Day", :regions=>[:us]}]
d.holidays
=> [{:date=>Wed, 04 Jul 2012, :name=>"Independence Day", :regions=>[:us]}]
We're using the holidays gem to prevent performing actions on holidays, but some holidays defined in the yaml files, such as liberation day, is an normal working day.
I know how to add custom holidays, but how can i override a specific holiday?
Hi, I'm using the holidays gem and was wondering if it doesn't worth it to change the regions names to be I18n compliant. For example, instead of br
we would have pt-BR
. In this way, we could check the holidays just passing the I18n.locale as a region parameter.
By the way, I can implement this change.
Thoughts?
I think they should be included as follows...
5 => [{:function => lambda { |year| Holidays.ca_victoria_day(year) }, :function_id => "ca_victoria_day(year)", :name => "Victoria Day", :regions => [:ca]},
{:function => lambda { |year| Holidays.ca_victoria_day(year) }, :function_id => "ca_victoria_day(year)", :name => "National Patriotes Day", :regions => [:ca_qc]},
{:mday => 1, :name => "Día del Trabajo", :regions => [:mx]},
{:mday => 5, :type => :informal, :name => "Cinco de Mayo", :regions => [:mx]},
{:mday => 5, :name => "La Batalla de Puebla", :regions => [:mx_pue]},
{:mday => 10, :type => :informal, :name => "Día de la Madre", :regions => [:mx]},
{:mday => 15, :type => :informal, :name => "Día del Maestro", :regions => [:mx]},
{:wday => 1, :week => -1, :name => "Memorial Day", :regions => [:us]},
{:wday => 0, :week => 2, :type => :informal, :name => "Mother's Day", :regions => [:us, :ca]}],
6 => [{:mday => 24, :name => "Discovery Day", :regions => [:ca_nf]},
{:mday => 24, :name => "Fête Nationale", :regions => [:ca_qc]},
{:mday => 21, :name => "National Aboriginal Day", :regions => [:ca_nt]},
{:wday => 0, :week => 3, :type => :informal, :name => "Día del Padre", :regions => [:mx]},
{:wday => 0, :week => 3, :type => :informal, :name => "Father's Day", :regions => [:us, :ca]}],
Hey! Just updated from 1.0.6 to 1.0.7 and something went wrong:
1.0.7:
Loading development environment (Rails 4.1.6)
2.1.1 :001 > Date.current.holiday?
NoMethodError: undefined method `holiday?' for Mon, 13 Oct 2014:Date
Seems like Holidays isn't loaded all.
1.0.6:
Loading development environment (Rails 4.1.6)
2.1.1 :001 > Date.current.holiday?
=> false
I simply have this in my Gemfile:
gem 'holidays'
I skimmed through the change history since 1.0.6 and couldn't find anything relevant that would affect loading of Holidays.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.