Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Calculating Number Of Pay Periods

by thanos1983 (Parson)
on Oct 09, 2017 at 14:07 UTC ( [id://1200994]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Calculating Number Of Pay Periods
in thread Calculating Number Of Pay Periods

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

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^4: Calculating Number Of Pay Periods
by soonix (Canon) on Oct 09, 2017 at 14:40 UTC

    For the OP, weeks are not relevant (FWIW, I'd countcalculate months, double that number, and check for partial months at beginning and end of the concerning period).

    If payment were weekly, however, and retirement more than 6 years away, you would want to keep the correct amount of those additional weeks - or countcalculate "paydays" (Mondays, or whatever) which might start at a date different from January 1st, anyway.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-25 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found