Just another Perl shrine PerlMonks

### Re^3: Date::Manip Sunday Holidays

by u65 (Chaplain)
 on Nov 28, 2015 at 12:23 UTC ( #1148752=note: print w/replies, xml ) Need Help??

in reply to Re^2: Date::Manip Sunday Holidays

Oops, my bad. Looks like a bug to me.

Replies are listed 'Best First'.
Re^4: Date::Manip Sunday Holidays
by SBECK (Chaplain) on Nov 28, 2015 at 19:20 UTC

In general, you probably don't want to include both the definition of New Years and New Years observed (though you can but you have to be careful of the ordering if you add both... this is talked about in the documentation on Date::Manip::Holidays).

```  Jan 1  = New Years

To define an observed New Years (where you observe it on Friday Dec 31 if Jan 1 falls on Saturday, or on Mon Jan 2 if Jan 1 falls on a Sunday), use the following:

```   1*1:0:1:0:0:0*DWD               = New Year's Day

NOTE: this is straight from the documentation on Date::Manip::Holidays which is a better source of information on defining holidays than the Date::Manip::Recur document.

Other definitions are also possible, but these cover the most commonly desired definitions.

Excellent, the solution right from the author. Thanks, SBECK!

Unfortunately, it appears that I didn't get the right answer. Going back and rereading it (more carefully this time around), the desired date of New Years is:

```  1/1  if 1/1 is Mon-Fri OR Sat
1/2  if 1/1 is Sun

That's much more complicated. I found something that I thought would work...

``` 1*1:0:1:0:0:0*NBD,BD1,IBD,FD1   = New Year's Day (Saturday)
1*1:0:1:0:0:0*NBD,BD1,NBD,FD2   = New Year's Day (Sunday observed Mon
+day)
1*1:0:1:0:0:0*IBD               = New Year's Day (real)

but it is failing on some years. I actually think it might be a bug. I'll check into it tomorrow.

I have definitely decided that I need to add a couple more modifiers similar to IBD and NBD which will check if it is a given day of the week. That would make this much simpler. I hadn't been aware of the complexity of the holiday definition used here.

Create A New User
Node Status?
node history
Node Type: note [id://1148752]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2021-05-12 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Perl 7 will be out ...

Results (125 votes). Check out past polls.

Notices?