holidays / holidays

A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Observed holidays that span month-end are not found

ppeble opened this issue · comments

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)

  • region: nz_ne - Nelson Anniversary Day - actual holiday is 2/1 but it is observed on the closest monday. For 2017 2/1 is a Wednesday, meaning that it is actually observed on 1/30/2017. When we submit the above we should see the 'Nelson Anniversary Day', since Monday, 1/30/2017 is when it is 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.

I'm going to close this. I have handled this here in the refactor branch, which will be merged soonish. I took the opportunity to start splitting up the massive 'between' context. Now we have slightly better test coverage and things are a bit more split apart than before.