Hey all,
because of the daylight savings time going on across the world I was
having trouble with the world clocks I setup for a client. I tried to
implement the code below but was un succesful to do it correctly
apparently. Does anyone have any working examples of this. And if so
do you mind sharing? Thanks ALL!!
Code via: Keith Reinsfield (I think* sorry...)
dstPolicies = {
USADLS:new DstPolicy(1,0,4, -1,0,10),
EUDLS:new DstPolicy(-1,0,3, -1,0,10),
AU2003DLS:new DstPolicy(-1,0,10, -1,0,3),
AUTDLS:new DstPolicy(1,1,10, -1,0,3),
RUDLS:new DstPolicy(-1,0,3, -1,0,10),
EGDLS:new DstPolicy(-1,5,4, -1,4,9),
IRDLS:new DstPolicy(-1,6,3, -1,1,9),
IQDLS:new DstPolicy(255, 1,4, 255, 1,10),
ILDLS:new DstPolicy(-1,4,3, 1,4,10),
JODLS:new DstPolicy(-1,3,3, -1,4,10),
NADLS:new DstPolicy(1,0,9, 1,0,4),
PKDLS:new DstPolicy(1,6,4, 1,6,10),
SYDLS:new DstPolicy(255,30,3, 255,21,9),
CLDLS:new DstPolicy(2,0,10, 2,0,3),
CLEDLS:new DstPolicy(2,5,10, 2,6,3),
NZDLS:new DstPolicy(1,0,10, 3,0,3),
PYDLS:new DstPolicy(1,0,9, 1,0,4),
FKDLS:new DstPolicy(1,0,9, -1,0,4)
};
/*Where the first number is the position (1: first, -1:last, 255: straight
date), the second and the third are the day/month.
If the position is 255, the date is a straight day/month date, so for
example for IRAQ the start date is April 1.
The formulas for the calcs are:*/
/**
* @param y:int Year
* @param m:int Month (0 - 11)
* @param n:int Day of the week (0 for a Sunday, 1 for
a Monday, 2 for a
Tuesday, etc)
* @param w:int Occurence (1:first, 2:second, 3:third,
4:fourth, -1:last)
* @return real day of the month where the DST starts/ends
*
* first friday = w:1, n:5
* third monday = w:3, n:1
* last monday = w:-1, n:1
*/
function calcStartEnd(y:Number, m:Number, n:Number, w:Number):Number {
if (w<0) {
var nd:Number = (new Date(y, m, 0)).getDate();
var diff:Number = (getDayOfWeek(y, m+1, nd)-n)%7;
if (diff<0) {
diff += 7;
}
return nd-diff;
}
var nq:Number = 7*w-6+(n-getDayOfWeek(y, m+1, 1))%7;
if (nq<1) {
nq += 7;
}
return nq;
}
/**
* @param y:int Year
* @param m:int Month (1 - 12)
* @param d:int Day (1 - 31)
* @return 0 for a Sunday, 1 for a Monday, 2 for a Tuesday, etc.
*/
function getDayOfWeek(y:Number, m:Number, d:Number):Number {
var a:Number = Number((14-m)/12);
y -= a;
m += 12*a-2;
var r:Number =
(d+y+Number(y/4)-Number(y/100)+Number(y/400)+int((31*m)/12))%7;
if (r<0) {
return 7+r;
} else {
return r;
}
}
--
Corban Baxter
http://www.projectx4.com
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders