http://www.perlmonks.org?node_id=1227660

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.