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

Exclude certain holidays

UnConundrum opened this issue · comments

It would be nice if the custom list of holidays could also override or exclude standard holidays, or change their type.

@UnConundrum Ooooh, interesting! I think I understand what you mean, but could you provide a simple use case of what you are talking about? I think this is doable if I am understanding correctly but I don't want to muck things up by getting your suggestion wrong.

I use a combination of Holidays and Business_Hours in a rails application to track employees' sick and vacation days. When a sick day fell on Veteran's Day, the app failed to include the day in the calculations because it was non-business hours. We remain open on Veteran's Day, so, for us, it was business hours or a non-holiday. I fixed the situation by manually changing us.rb and northamerica.rb and adding :type => :informal to the two definitions. Obviously, that will work until there's a new release of Holidays or I move to a new server. A permanent fix, where I could either ignore Veteran's Day, or mark it :informal in a config file (or db) would be much better.

Thanks for considering it :)

Ah! Totally get it. This is very similar to the use case I had when I first started contributing to this gem. The company I worked for had special company-only holidays, that's why I added the 'load_custom' method. The difference is that I wasn't 'overriding' existing definitions but it makes sense to want to do so.

But what you are saying totally makes sense. The issue here is how we load the definitions behind the scenes but I think this is solvable. Let me think about it a bit and get back to you.

Hi @UnConundrum! Thanks for your patience. I haven't had a chance to look at this more but I hope to do it soon. My wife had a baby in December and I am only just now getting back onto some kind of schedule that will allow dev work. I'll get back to you!

We have a need for this very feature! We require a somewhat "stricter" set of holidays for Canada; for example, Civic holiday is considered a holiday by convention in the definitions code, but we want it to be an "informal" holiday as it is not an actual stat holiday by government terms in Ontario.
The key deciding factor is whether an employer is required to pay employees on the holiday. It could be considered a "holiday" by general public, but employers are not required to pay their employees for this day off if it is not considered a statutory holiday.

Thanks for the feedback @slucaskim. For your specific situation I think you could make the argument that you should have a separate holiday listing for Ontario only that is marked :informal. I tested it out locally and I think it does what you want:

- name: Civic Holiday
  week: 1
  regions: [ca_nt, ca_nu, ca_pe]
  wday: 1
- name: Civic Holiday
  week: 1
  regions: [ca_on]
  wday: 1
  type: informal

When I ran this locally I received the following output:

% make console
bundle exec rake console
irb -rubygems -I lib -r holidays.rb
irb(main):001:0> Holidays.on(Date.civil(2017, 8, 7), :ca_on)
=> []
irb(main):002:0> Holidays.on(Date.civil(2017, 8, 7), :ca_on, :informal)
=> [{:date=>#<Date: 2017-08-07 ((2457973j,0s,0n),+0s,2299161j)>, :name=>"Civic Holiday", :regions=>[:ca_on]}]
irb(main):005:0> Holidays.on(Date.civil(2017, 8, 7), :ca_nt)
=> [{:date=>#<Date: 2017-08-07 ((2457973j,0s,0n),+0s,2299161j)>, :name=>"Civic Holiday", :regions=>[:ca_nt, :ca_nu, :ca_pe]}]
irb(main):006:0> Holidays.on(Date.civil(2017, 8, 7), :ca_nt, :informal)
=> [{:date=>#<Date: 2017-08-07 ((2457973j,0s,0n),+0s,2299161j)>, :name=>"Civic Holiday", :regions=>[:ca_nt, :ca_nu, :ca_pe]}]

This looks like what you want? This would be the preferred solution if indeed this is not a 'true' holiday in ontario only. I would gladly merge a PR that made this change and I could get it out with the next release.

@UnConundrum I'm sorry that I haven't gotten to this yet. I swear that I haven't forgotten. I have simplified how the definitions are loaded behind the scenes so I am confident I could come up with a solution, I just have a lot on my plate and I'm just moving slow because I don't have as much dev time since the new kid. Thanks again for your patience. 😃

@ppeble Your solution would be the easiest for all of us, and we did consider it but we thought it might not be what you want because of the comment in this line. However, due to your response, I'll go ahead and put up a PR containing all of the changes we need. I'll also put up all external references backing up those changes!

Any progress on this by chance? Columbus Day caused problems today.

This is also an issue if you want to look for US stockmarket holidays: https://www.nyse.com/markets/hours-calendars

Veterans Day is not a market holiday, but can't easily be excluded

Veteran's Day is coming up again. Any progress or should I stop asking?

I hacked this in our code with the following:

class Date
  include Holidays::CoreExtensions::Date

  # Check if the current date is a holiday.
  # Patched from the original Holidays::CoreExtensions::Date#holiday?
  # to handle overrides that remove holidays
  # e.g. !! Veterans Day
  def holiday?(*options)
    self.holidays(*options).reduce(false) do |_is_hol, hol_def|
      break false if hol_def[:name].start_with?('!!')

      true
    end
  end
end

and in the .yaml

  11:
  - name: '!! Veterans Day'
    regions: [us_allmarkets]
    mday: 11
    observed: to_weekday_if_weekend(date)

The monkeypatch recognises !! on the name as meaning that the holiday is not observed for that region (we have custom config files for each stock market or group of).

For Canada,

National Day for Truth and Reconciliation is added as a Holiday for all provinces in the config.
https://github.com/holidays/definitions/blob/master/ca.yaml#L180-L184

But it is a statutory holiday for federal government employees, not all Canadians.
Recently, Northwest Territories extended the holiday to all workers in the NWT beginning in 2022.

As per the config, the holiday is for all provinces , I need to override this behaviour. I need it to be a holiday for only 2 provinces PEI & NT, but not others. What is the best way to achieve this?

Wanted to add another example here. Texas has a Confederate Heroes Day which is not a statutory holiday, but is technically a recognized holiday by the state. So IMO it does make sense to be a formal holiday as defined by this gem, however for our purposes since most people don't take it off, its not relevant for us.

I think it would be great to have a further holiday definition of something like statutory, which would delineate holidays like this from government-mandated holidays. In lieu of that, having an easy way to exclude it for our configuration without requiring custom definitions would be great.