Leap year detection
September 25th, 2009
A year will be a leap year if it is divisible by 4 but not by 100. If a year is divisible by 4 and by 100, it is not a leap year unless it is also divisible by 400.
Translated into Actionscript 3.0, that looks like this:
function getIsLeapyear(year:int):Boolean{
var result:Boolean = false;
var divBy4:Boolean = (year % 4 == 0);
var divBy100:Boolean = (year % 100 == 0);
var divBy400:Boolean = (year % 400 == 0);
if(divBy4){
if(divBy100){
if(divBy400){
result = true;
} else {
result = false;
}
} else {
result = true;
}
} else {
result = false;
}
return result;
}
September 25th, 2009 at 16:58
Thanks for the post, I had no idea it was so complicated. I thought it was just a simple %4 job. Go figure!