in reply to Re: Calculating Number Of Pay Periods (UPDATED)
in thread Calculating Number Of Pay Periods

53 weeks in a year?


The way forward always starts with a minimal test.
  • Comment on Re^2: Calculating Number Of Pay Periods

Replies are listed 'Best First'.
Re^3: Calculating Number Of Pay Periods
by pryrt (Abbot) on Oct 09, 2017 at 13:13 UTC

    Yes. The year is 365-366 days, depending, whereas weeks are 7 days (where 52 weeks is only 364 days: not a full year). Businesses often use "work weeks", and every once in a while, there is a "leap-week", to get the calendar back in sync, so the first work week of a year re-aligns with the start of the business's fiscal or calendar year. See more at ISO_week_date and ISO_8601.

      Yes, calenders have some strange rules. Our common Gregorian calendar has a lot of legacy, e.g. the short february that has to be compensated by making other months longer. 12 months of 30 days each are obviously too short, leaving five or six days that have to be spread over the 12 months. Easy for leap years, choose every even or odd month. In non-leap years, remove the extra day from one of the months.

      J. R. R. Tolkien had different ideas for Middle-earth. The stories of Middle-earth are fictional history for our real planet, so Middle-earth calendars also work for planet earth. The Shire calendar, used by the Hobbits, splits the year into 12 months of 30 days each. The remaining five or six days are not assigned to a month, they stay outside of the months. The year is split into two halves. Each of the halves is wrapped in two day of the remaining days. The middle of the year is marked by the fifth remaining day, and in case of a leap year, the leap day is inserted afther the mid-year's day. So there are two days outside the months in winter, when the year is incremented (compare to New Year's Eve and New Year) and three or four days in summer (no equivalent). A clever trick is that the mid-year's day and the leap day are not assigned a week day. This way, only 364 days are assigned a weekday, and because 364 is a multiple of seven, each year starts with the same weekday, and therefore, every day of the year has a fixed weekday.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      Or depending on which flavor of weirdness you like, you can use a 360-day calendar.
Re^3: Calculating Number Of Pay Periods
by soonix (Chancellor) on Oct 09, 2017 at 13:15 UTC

    Yup, if the year starts on a thursday (if you use ISO reckoning).

    365 days are 52 weeks + 1 day. Every 6 years or so, you have 7 of these remaining days, and they, too, belong to a certain year…
Re^3: Calculating Number Of Pay Periods
by thanos1983 (Parson) on Oct 09, 2017 at 14:07 UTC

    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!

      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.