ISO Week No's Hi
Just noticed that %ww% is creating the weekno's in American format. Is it possible to also get a option for us Europenans who are forced :) to use ISO standard.
The ISO standard defines a week
as a periode of 7 days starting with Monday and ending with Sunday.
Week 1 in any year is the first such periode that contains at least
4 days from that year. This means for one thing that up to 3 days
at the beginning of a year can be part of the last week (52 or 53)
in the previous year, and up to 3 days at the end of a year can be
part of week 1 in the following year.
I am unsure what lanuage you are developing in but if it is .NET the following will provide a ISO result :
/// <summary>
/// Weeks the number_ entire4 day week rule.
/// </summary>
/// <param name="date">The date.</param>
/// <returns></returns>
private int WeekNumber_Entire4DayWeekRule(DateTime date)
{
// Calculates the ISO 8601 Week Number
// In this scenario the first day of the week is monday,
// and the week rule states that:
// <...> the first calendar week of a year is the one
// that includes the first Thursday of that year and
// <...> the last calendar week of a calendar year is
// the week immediately preceding the first
// calendar week of the next year.
// The first week of the year may thus start in the
// preceding year
const int JAN = 1;
const int DEC = 12;
const int LASTDAYOFDEC = 31;
const int FIRSTDAYOFJAN = 1;
const int THURSDAY = 4;
bool ThursdayFlag = false;
// Get the day number since the beginning of the year
int DayOfYear = date.DayOfYear;
// Get the numeric weekday of the first day of the
// year (using sunday as FirstDay)
int StartWeekDayOfYear =
(int)(new DateTime(date.Year, JAN, FIRSTDAYOFJAN)).DayOfWeek;
int EndWeekDayOfYear =
(int)(new DateTime(date.Year, DEC, LASTDAYOFDEC)).DayOfWeek;
// Compensate for the fact that we are using monday
// as the first day of the week
if( StartWeekDayOfYear == 0)
StartWeekDayOfYear = 7;
if( EndWeekDayOfYear == 0)
EndWeekDayOfYear = 7;
// Calculate the number of days in the first and last week
int DaysInFirstWeek = 8 - (StartWeekDayOfYear );
int DaysInLastWeek = 8 - (EndWeekDayOfYear );
// If the year either starts or ends on a thursday it will have a 53rd week
if (StartWeekDayOfYear == THURSDAY || EndWeekDayOfYear == THURSDAY)
ThursdayFlag = true;
// We begin by calculating the number of FULL weeks between the start of the year and
// our date. The number is rounded up, so the smallest possible value is 0.
int FullWeeks = (int) Math.Ceiling((DayOfYear - (DaysInFirstWeek))/7.0);
int WeekNumber = FullWeeks;
// If the first week of the year has at least four days, then the actual week number for our date
// can be incremented by one.
if (DaysInFirstWeek >= THURSDAY)
WeekNumber = WeekNumber +1;
// If week number is larger than week 52 (and the year doesn't either start or end on a thursday)
// then the correct week number is 1.
if (WeekNumber > 52 && !ThursdayFlag)
WeekNumber = 1;
// If week number is still 0, it means that we are trying to evaluate the week number for a
// week that belongs in the previous year (since that week has 3 days or less in our date's year).
// We therefore make a recursive call using the last day of the previous year.
if (WeekNumber == 0)
WeekNumber = WeekNumber_Entire4DayWeekRule(
new DateTime(date.Year-1, DEC, LASTDAYOFDEC));
return WeekNumber;
}
Thanks
Murtagh
JamesJ- 12-15-2005
This is off topic, but last month you posted a message about getting prompted to enter date parameters when you ran a report from CD. Kevin thought it was because the parameters were DateTime fields and the values from CD didn't include a time, but I'd never had a problem using DateTime parameters. It turns out that this was apparently a problem introduced in version 6.0.0 and, if you haven't already seen it, he has just released a version 6.0.2 that's supposed to fix this (I haven't tried it yet). So if you're still having problems with DateTime parameters, you might want to try the new version.
James
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.