HowTo: get Calendar Week from flash.utils.date Object

For my actual project (a Camel Race for Philips) i had to search for a function which translates a flash.utils.date object into a calendar-week int. After a while of searching i found a coole one and i translated it into AS3. Maybe someone can use this one ;)

function getCW(target:Date):int {
	var a = target.getFullYear();
	var m = target.getMonth()+1;
	var j = target.getDate();
	var S = Math.floor(a/100);
	var A = a%100;
	var aB = (a%4 == 0 && a%100 != 0) || (a%1000 == 0) ? 1 : 0;
	var jNA = (5*S+Math.floor(S/4)+A+Math.floor(A/4)+aB*6)%7;
	var w = Math.floor((jNA+(m == 1 ? j : m == 2 ? 31+j : Math.floor((30.6*m)-32.3)+j+aB*1)+5)/7)-Math.floor(jNA/5);
	return w == 0 || w == 53?1:w;
}
                                         Flash / Actionscript | GSDH | News & Random

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>