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

Get next X number of holidays

brentdodell opened this issue · comments

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

Hi @brentdodell, no, unfortunately there is no use case along those lines that I am aware of. I would be happy to treat this as a feature request, though, if you wouldn't mind expanding a bit on the actual use case details. It doesn't seem like it would be incredibly difficult.

Can you outline a few concrete examples? One or two is fine. That way I can see exactly what you expect and we can discuss how I can implement it.

This is kind of what I had in mind...feel free to tweak if need-be.

def self.next(holiday_count, regions, from = Date.today)
end

holiday_count is the number of holidays to return
regions is an array of the regions
from is the date from which to find the next holiday_count number of holidays.

In my mind, from should be an optional param, defaulted to Date.today.

I originally had an inclusive param, to determine whether or not to include holidays that fall on the from date, or only show those that come after it. On second thought I decided that it would be just as easy, if not easier, to pass in Date.today + 1 for from if needing to exclude today's holidays and start with tomorrow's.

Get next 3 US holidays (including informal) after (and including) today:

Date.today
=> Tue, 23 Feb 2016

regions = [:us, :informal]

Holidays.next(3, regions)
=> [{:name => "St. Patrick's Day",...},
    {:name => "Good Friday",...},
    {:name => "Easter Sunday",...}]

Get next 4 US holidays after (and including) December 24th (it goes ahead and rolls to the new year)

regions = [:us]
from = Date.civil(2016, 12, 24)

Holidays.next(4, regions, from)
=> [{:name => "Christmas Day",...},
    {:name => "New Year's Day",...},
    {:name => "Martin Luther King, Jr. Day",...},
    {:name => "President's Day",...}]

What are your thoughts?

I really like this. I think this is a great idea. Let me take a stab at it soon, I think this is definitely doable.

Thanks for the suggestion! It's now on my official to-do list. 😄

Hi @ptrimble @brentdodell .
I have sent PR next_holiday method.
Maybe , this method matches your thoughts.
Please review my PR #191.

I'm going to write it here even though I wrote it on the PR as well but: @ttwo32's PR looks great! I think it almost exactly satisfies the use case that @brentdodell wrote out above. Once @ttwo32 and I come to an agreement on a few small nitpicks I had I'll merge it and get this out in a minor point release.

Great to hear! Thanks @ptrimble & @ttwo32.

This feature has been merged, I will get a release out that contains the additional functionality sometime this week.