Skip Menu |

This queue is for tickets about the Date-Manip CPAN distribution.

Report information
The Basics
Id: 38208
Status: resolved
Priority: 0/
Queue: Date-Manip

People
Owner: Nobody in particular
Requestors: bressers [...] redhat.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: UnixDate format issue
Date: Tue, 05 Aug 2008 13:56:44 -0400
To: bug-Date-Manip [...] rt.cpan.org
From: Josh Bressers <bressers [...] redhat.com>
I would expect the below demo to print 2013-53 but it prints 2013-01. #!/usr/bin/perl use Date::Manip; $date = ParseDate("Dec 30 2013"); print UnixDate($date, ('%Y-%W')), "\n"; If you change the year to 2009, it does print the week as 53, so the library seems to be able to understand 53 weeks, I suspect it should be printing 2014-01, but the year is being rendered incorrectly. Thanks. -- JB
Please read the docs more carefully. You are using %W incorrectly. You cannot use %W with %Y and reliably get useful results. %W MUST be used in conjuction with %G. From the docs: The %U, %W, %L, %G, and %J formats are used to support the ISO-8601 format: YYYY-wWW-D. In this format, a date is written as a year, the week of the year, and the day of the week. Technically, the week may be considered to start on any day of the week, but Sunday and Monday are the both common choices, so both are supported. The %W and %G formats return the week-of-year and the year treating weeks as starting on Monday. The %U and %L formats return the week-of-year and the year treating weeks as starting on Sunday. Most of the time, the %L and %G formats returns the same value as the %Y format, but there is a problem with days occurring in the first or last week of the year. The ISO-8601 representation of Jan 1, 1993 written in the YYYY-wWW-D format is actually 1992-W53-5. In other words, Jan 1 is treated as being in the last week of the preceding year. Depending on the year, days in the first week of a year may belong to the previous year, and days in the final week of a year may belong to the next year. The week is assigned to the year which has most of the days. For example, if the week starts on Sunday, then the last week of 2003 is 2003-12-28 to 2004-01-03. This week is assigned to 2003 since 4 of the days in it are in 2003 and only 3 of them are in 2004. The first week of 2004 starts on 2004-01-04. The %U and %W formats return a week-of-year number from 01 to 53. %L and %G return the corresponding year, and to get this type of information, you should always use the (%W,%G) combination or (%U,%L) combination. %Y should not be used as it will yield incorrect results. %J returns the full ISO-8601 format (%G-W%W-%w).