Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Date::Manip how to set FirstDay to Sunday

by Lena2018 (Initiate)
on Dec 24, 2018 at 13:28 UTC ( #1227660=perlquestion: print w/replies, xml ) Need Help??

Lena2018 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I'm trying to calculate the business days between two dates using Date::Manip VERSION='6.75'.
I want to configure the first day of the week to be Sunday. My business days are Sunday to Thursday.
I'm running this code but I'm not getting the desired output. The code considers Friday as a business day - which is not what I want.

use strict; use warnings; use Date::Manip; my $task_start = new Date::Manip::Date; my $task_end = new Date::Manip::Date; my $err = $task_start->parse('2018-12-07 02:52:05'); $err = $task_end->parse('2018-12-09 04:27:00'); $task_start->config('workday24hr',1); $task_end->config('workday24hr', 1); $task_start->config('FirstDay', 7); $task_end->config('FirstDay', 7); my $delta = $task_start->calc($task_end,"business"); print $delta->value()."\n"; 0:0:0:0:21:7:55

What changes should I do to get the following output: 0:0:0:0:04:27:00 ?

Replies are listed 'Best First'.
Re: Date::Manip how to set FirstDay to Sunday
by soonix (Abbot) on Dec 24, 2018 at 13:51 UTC
    Hi Lena2018!

    Your workdays seem to be special :-)

    In Date::Manip::Config it says under BUSINESS CONFIGURATION VARIABLES:
    … WorkWeekBeg must come before WorkWeekEnd numerically so there is no way to handle a work week of Sunday to Thursday using these variables.

    To handle a work week of Sunday to Thursday, just set WorkWeekBeg=1 and WorkWeekEnd=7 and defined a holiday that occurs every Friday and Saturday.
    … can be done using recurrences. Refer to the Date::Manip::Recur documentation for details.
Re: Date::Manip how to set FirstDay to Sunday
by kschwab (Vicar) on Dec 24, 2018 at 13:51 UTC

    Edit: Dupe...guess I should check for replies between mashing the preview button.

    "My business days are Sunday to Thursday"

    Funny, that example is specifically mentioned in the Date::Manip::Config docs:

    WorkWeekBeg must come before WorkWeekEnd numerically so there is no way to handle a work week of Sunday to Thursday using these variables...However...can be handled using a fairly simple workaround. To handle a work week of Sunday to Thursday, just set WorkWeekBeg=1 and WorkWeekEnd=7 and defined a holiday that occurs every Friday and Saturday.

    It suggests using Date::Manip::Recur for the Friday/Saturday holidays.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1227660]
Approved by haukex
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2019-06-26 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (110 votes). Check out past polls.

    Notices?