sub getWeekStart { #---------------------------------------------------------- # Return the date of the Monday which starts a given week # Required parameters: year (4 digit) and week # # Uses ISO8601 definition of week numbers # # ADSB 21 November 1998 #---------------------------------------------------------- local (@tm,$time,$year,$week,$wday); use POSIX; ($year,$week)=@_; # With ISO8601 week numbers, 4 January is always in week 01 @tm=(0,0,12,4,0,$year-1900,0,0); # Increment the day of the month by 7 times the weeks to add $tm[3] += (($week-1)*7); # Get the number of seconds since the epoch $time=mktime(@tm); # Fill in the struct tm again (because Perl's mktime() doesn't) @tm=localtime($time); # Find out which day of the week it is $wday=$tm[6]; # Move Sunday to the end of the week if ($wday == 0) { $wday = 7;} # Wind day of week back to Monday $tm[3] -= ($wday-1); $time=mktime(@tm); } 1;