Hello 1nickt,
You are right the year has 52 weeks and 1 or 2 day(s) depending upon the number of days in the year.
Sample of calculation on calendar common year 365 days:
1 common year = 365 days = (365 days) / (7 days/week) = 52.143 weeks = + 52 weeks + 1 day
Sample of calculation on leap year has 366 days, when February has 29 days:
1 leap year = 366 days = (366 days) / (7 days/week) = 52.286 weeks = 5 +2 weeks + 2 days
I was counting the remaining days as a week. So the solution is to remove the last input and count in total the remaining weeks:
Sample bellow before and after:
#!/usr/bin/perl use strict; use warnings; use Date::Manip; use Data::Dumper; my ($start, $end) = qw(2017-01-01 2017-12-31); # y:m:w:d:h:m:s my @weeks = ParseRecur('0:0:1::0:0:0', $start, $start, $end); print Dumper \@weeks; =sample $VAR1 = [ '2017010100:00:00', '2017010800:00:00', '2017011500:00:00', '2017012200:00:00', . . . '2017121700:00:00', '2017122400:00:00', '2017123100:00:00' # Not a week (remaining days) ]; =cut pop @weeks; say "Number of weeks: " . scalar @weeks; print Dumper \@weeks; =output $VAR1 = [ '2017010100:00:00', '2017010800:00:00', '2017011500:00:00', '2017012200:00:00', . . . '2017121000:00:00', '2017121700:00:00', '2017122400:00:00' # Last week on 2017 ]; =cut
BR / Thanos
In reply to Re^3: Calculating Number Of Pay Periods
by thanos1983
in thread Calculating Number Of Pay Periods
by Anonymous Monk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |