POSIX contains the strftime() function, which is used by Date::WeekNumber.ĭateTime provides a week() method, which returns the ISO week number and associated year for a DateTime instance. Version 1.06 provided a mode for giving the output in the same format as this module. As of version 1.05 this return the ISO 8601 week number, prior to that it returned something slightly different you can still request the old week numbering scheme. SEE ALSOĭate::WeekOfYear provides a WeekOfYear() function, which returns the week number and associated year. Week 2006-W53 runs from Sunday 31st December 2006 to Saturday 6th January 2007, and 2007-W01 runs from Sunday 7th January to Saturday 13th January. Week 2012-W01 runs from Sunday 1st January to Saturday 7th January. The cpan_week_number() function returns a string with the week number according to 'CPAN Weeks'.ĬPAN Weeks run from Sunday to Saturday, with week 01 of the year being the week containing the first Sunday in January. In this case 2009-W52 runs runs 28th December 2009 through 3rd January 2010, and 2010-W01 starts on Monday 4th January 2010. So 2014-W01 runs from 30th December 2013 to 5th January 2014. Consider the transition from 2013 to 2014: December 2013 January 2014 ISO 8601 defines week 01 as being the week with the first Thursday in it. The iso_week_number() function returns a string with the week number according to ISO 8601. Plus I sometimes have an epoch and sometimes a date string, so I decided to experiment with a DWIMish interface (Do What I Mean), where you could pass the date in whatever format you have it available, and it'll be handled. There are a number of modules that can be used to calculate the week number, but I wanted a minimalist interface that returned a string format, rather than the year and week number separately. The CPAN week number is the definition used by Chris Madsen's CPAN once a week, every week contest, and my CPAN Regulars Releasers page. A more complete definition of the week naming schemes is given below. There are two functions provided: iso_week_number() returns the week number according to ISO 8601, where the weeks run from Monday through Sunday, and cpan_week_number(), where the weeks run from Sunday through Saturday. Which at the time I'm writing this will print: Today is in week 2014-W09 For example: print "Today is in week ", iso_week_number(time()), "\n" The two functions provided by this module can be used to generate the week number in the year of a given date. # pass parameters as for cpan_week_number() above DESCRIPTION Or to get weeks according to ISO 8601: use Date::WeekNumber qw/ iso_week_number / Date::WeekNumber - calculate week of the year (ISO 8601 weeks, or 'CPAN weeks') SYNOPSIS use Date::WeekNumber qw/ cpan_week_number /
0 Comments
Leave a Reply. |