Christmas Calculation Off by 1 for 2016 in :us Region
jnorlen-nerdery opened this issue · comments
As far as I can tell, the Christmas calculation is currently returning 2016-12-26 (when it should be 2016-12-25) for the date of Christmas within the US region. This also appears to (though I haven't directly validated it) affect New Year's as well. At first I thought I was doing Timezones incorrectly... but even with a reduced repro and no TZs in play it seems to be incorrect.
require 'holidays'
start_date = Date.civil(2016, 1, 1)
end_date = Date.civil(2017, 1, 1)
holidays = Holidays.between(start_date,
end_date,
:us,
:informal,
:observed)
christmas = holidays.find{|h| h[:name] == 'Christmas Day'}[:date]
puts christmas
# ruby ./repro.rb
# => 2016-12-26
Ooof. Thanks for reporting this @jordan-norlen! I will look into it this week with @ttwo32 and we'll get back to you. Not sure what's going on yet.
(I just happened to be looking at issues and that's why I responded so fast, I'm not a robot I swear)
lol, that was amazing. :) Thanks @ptrimble!
No problem! 😄
My guess is that our 'observed' logic has some issues. The observed
stuff is supposed to move the date to another day depending on what's going on with a weekend, for example, so perhaps there's a bug in there somewhere. I'll investigate and get back to you.
Well now I feel bad. :) I just noticed and grokked what :observed does (been tracking a 'bug' in our codebase). It totally makes sense that the code I posted is moving Christmas to the following Monday (25th->26th) as that's exactly what we told it to do.
I'm going to go ahead and close this and thank you for an awesome library and being so speedy in your response. :)
Oh okay! That makes sense. Don't feel bad, I personally had trouble with it when I first picked this library up.
Let us know if you do spot weird behavior, though...that part of our codebase is one that doesn't have a lot of good test coverage (not enough, anyway). I refactored a lot of this gem over the last year but the observed
logic and some of the built-in functions (like easter
, etc) were left untouched because...they were working and no one reported any issues.
Don't try to fix something that ain't broken, right? But that means I live in fear that there IS a bug in there that will require me to dig into it. 😄
Thanks again for even taking the time to report something, we appreciate it!