Hello Tristan,
Welcome to the MSDN newsgroup.
From your description, I understand you're encountering some inconsistent
behavior between the some custom ISO 8601 weeknum calculate code and the
..net framework's weekofYear calucation, you found that for some end days of
a year, the .net framework's calculation will return "53"(or the last
week's number) while the other calculation code will return "1"(the first
weeknum), correct?
I've performed some tests through T-SQL and the .net framework
functions(use the following code) and the result did conform to your
finding.
=======================
protected void Page_Load(object sender, EventArgs e)
{
DateTime date = DateTime.Parse("1977-01-02 ");
System.Globalization.Calendar cal =
CultureInfo.InvariantCulture.Calendar;
int weekNo = cal.GetWeekOfYear(date,
CalendarWeekRule.FirstFourDayWeek,
DayOfWeek.Monday );
DayOfWeek dayNo = cal.GetDayOfWeek(date);
Response.Write("<br/>WeekOfYear: " + weekNo);
Response.Write("<br/>WeekOfYear: " + dayNo);
}
=================================
After some further review on the ISO 8601 datetime standard, here are some
of my understanding on this problem:
In the ISO 8601 standard, it define the week number in a year as below:
================
Mutually equivalent definitions for week 01 are:
the week with the year's first Thursday in it
the week with 4 January in it
the first week with the majority (four or more) of its days in the starting
year
the week starting with the Monday in the period 29 December - 4 January
If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week
01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53
of the previous year.
==================
Also, the total week index of a year can range from 1 to 52 or 53. Also ISO
8601 only define which start days of a year should be in the frist week of
that year(W01), but not the end days in that year. That means for some end
days in a year, such as 12/31/2007, it is in the first week(W01) of year
2008 , but since the week number of year 2007 can range from 1--52, or
1--53, we can also consdier 12/31/2007 as the 53th week of year 2007.
Therefore, the below expression are both correct:
2007-W53-1
2008-W01-1
ISO 8601 hasn't made forced statement on this. And the .net framework's
implementation choose to use the (2007-W53-1), I think it is because for a
certain day, it is more natural to consider its week number as the value
among its own year's weeknumber range(rather than its next year's
weeknumber).
And as for the T-SQL or other .net custom code on calculating ISO 8601 week
number, they all use their own implementation for such edging cases(the
last days in a year), there is no standards to say which one is correct or
wrong.
This is my understanding on this problem. Hope this helps. If you have
anything unclear or still have any other questions on this, please feel
free to post here.
BTW, here are some web articles describing the ISO 8601 standards:
#ISO 8601
http://en.wikipedia.org/wiki/ISO_8601#Week_dates #A summary of the international standard date and time notation
http://www.cl.cam.ac.uk/~mgk25/iso-time.html
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial
response from the community or a Microsoft Support Engineer within 1
business day is
acceptable. Please note that each follow up response may take approximately
2 business days
as the support professional working with you may need further investigation
to reach the
most efficient resolution. The offering is not appropriate for situations
that require
urgent, real-time or phone-based interactions or complex project analysis
and dump analysis
issues. Issues of this nature are best handled working with a dedicated
Microsoft Support
Engineer by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx. ==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.