raku-community-modules / Date-WorkdayCalendar

Raku class that handles workdate calculations considering workdays, holidays and weekends
Artistic License 2.0
3 stars 4 forks source link

What if first provided date isn't working day? #7

Open olorin37 opened 4 years ago

olorin37 commented 4 years ago

If I understand correctly purpose of the function. It should always returns working days. So now programmer is forced to provide working day as the first one of the range to get correct answer.

User can workaround it by

# taking the first working day counting from "today" 
my $first-woking-day = $cal.workdays-away(Date.today - 1, 1);

# This should work already:
my $first-working-day = $cal.workdays-away(Date.today, 0);

Problematic line: https://github.com/raku-community-modules/Date-WorkdayCalendar/blob/d5adbdad6bb74707f7cb817c3c5de2d337595125/lib/Date/WorkdayCalendar.pm#L87

olorin37 commented 4 years ago

Another example how it doesn't work (here in case of Workdate class):

# 2020-10-17 is Saturday, and we get:
❯ raku -e 'use Date::WorkdayCalendar; Workdate.new(Date.new("2020-10-17")).say'
2020-10-17

# With WA applied:
❯ raku -e 'use Date::WorkdayCalendar; Workdate.new(Date.new("2020-10-17") -1 ).succ.say'
2020-10-19