<cfscript>
//-------------------------------------------------------------------------------------------------------------->
//------- Algorithme pour Convertir une Date Gregorienne en Date de semaine ISO 8601 ----------------------->
//-------------------------------------------------------------------------------------------------------------->
//-- 1. Convert input to Y M D
Y = Annee; //(full specification; input 98 = year 0098)
M = Mois; //(1 through 12)
D = Jour; //(1 through 31)
//-- 2. Find if Y is LeapYear IsLeapYear(année)
if(IsLeapYear(Y))
{
LeapYear = true;
}
else
{
LeapYear = false;
}
//-- 3. Find if Y-1 is LeapYear
if(IsLeapYear(Y-1))
{
LeapYear_1 = true;
}
else
{
LeapYear_1 = false;
}
//-- 4. Find the DayOfYearNumber for Y M D
Mnth = ArrayNew(1);
Mnth[1] = 0;
Mnth[2] = 31;
Mnth[3] = 59;
Mnth[4] = 90;
Mnth[5] = 120;
Mnth[6] = 151;
Mnth[7] = 181;
Mnth[8] = 212;
Mnth[9] = 243;
Mnth[10] = 273;
Mnth[11] = 304;
Mnth[12] = 334;
DayOfYearNumber = D + Mnth[M];
if (LeapYear EQ true AND M GT 2)
{
DayOfYearNumber = DayOfYearNumber + 1;
}
//-- 5. Find the Jan1Weekday for Y (Monday=1, Sunday=7)
YY = ( Y - 1 ) MOD 100;
C = ( Y - 1 ) - YY;
G = YY + YY / 4;
Jan1Weekday = 1 + ((((( C / 100 ) MOD 4 ) * 5 ) + G ) MOD 7 );
//-- 6. Find the Weekday for Y M D
H = DayOfYearNumber + (Jan1Weekday - 1);
Weekday = 1 + (( H - 1 ) MOD 7 );
//-- 7. Find if Y M D falls in YearNumber Y-1, WeekNumber 52 or 53
if ( DayOfYearNumber LE ( 8 - Fix(Jan1Weekday) ) AND Jan1Weekday GE 5 )
{
YearNumber = Y - 1;
if (Fix(Jan1Weekday) EQ 5 OR (Fix(Jan1Weekday) EQ 6 AND LeapYear_1 EQ true))
{
WeekNumber = 53;
}
else
{
WeekNumber = 52;
}
}
else
{
YearNumber = Y;
}
//-- 8. Find if Y M D falls in YearNumber Y+1, WeekNumber 1
if (YearNumber EQ Y)
{
if ( LeapYear EQ true )
{
I = 366;
}
else
{
I = 365;
}
if ( (I - DayOfYearNumber) LT (4 - Weekday) )
{
YearNumber = Y + 1;
WeekNumber = 1;
}
}
//-- 9. Find if Y M D falls in YearNumber Y, WeekNumber 1 through 53
if (YearNumber EQ Y)
{
J = DayOfYearNumber + (7 - Weekday) + (Jan1Weekday -1);
WeekNumber = J / 7;
if (Jan1Weekday GT 4)
{
WeekNumber = WeekNumber - 1;
}
}
Weekday = Fix(Weekday);
</cfscript>