Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: Date::Manip Sunday Holidays

by SBECK (Hermit)
on Nov 28, 2015 at 19:20 UTC ( #1148774=note: print w/replies, xml ) Need Help??


in reply to Re^3: Date::Manip Sunday Holidays
in thread Date::Manip Sunday Holidays

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).

To define the true New Years, just add (to your 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.

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

    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.

        There was definitely a bug. I fixed it today and it will be in the next release (originally scheduled for tomorrow 12/1, but it will probably get pushed back a day or two to allow me to complete the work to get this working).

        In the next release (6.52 which should be released tomorrow after a bit more testing), you will be able to define New Years the way you are asking in a couple of ways:

        # Saturday 1*1:0:1:0:0:0*NBD,BD1,IBD,FD1 = New Year's Day # Sunday (observed Monday) 1*1:0:1:0:0:0*NBD,BD1,NBD,FD2 = New Year's Day # M-F 1*1:0:1:0:0:0*IBD = New Year's Day

        or

        # Saturday 1*1:0:1:0:0:0*IW6 = New Year's Day # Sunday (observed Monday) 1*1:0:1:0:0:0*IW7,FD1 = New Year's Day # M-F 1*1:0:1:0:0:0*IBD = New Year's Day

        It's important to name the holiday the same for all definitions.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1148774]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2020-10-22 04:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (225 votes). Check out past polls.

    Notices?