Archive: Here are 2 useful date functions


Here are 2 useful date functions
I created 2 date functions: IsLeapYear and DaysInMonth:

To use it:
Push "year"
Call IsLeapYear
Pop $0 ;returns 0 or 1

Push "month"
Push "year"
Call DaysInMonth
Pop $0 ; returns 28, 29, 30 or 31

Function IsLeapYear

Pop $0
IntOp $1 $0 % 4
IntCmp $1 0 test2 ;si divisible par 4, on passe au test 2 (début de siècle)
Goto ko ;sinon, retourne FAUX
test2:
IntOp $1 $0 % 100
IntCmp $1 0 test3
Goto ok
test3:
;l'année est un siècle rond
;on vérifie si ce siècle est impair
IntOp $1 $0 % 200
IntCmp $1 0 ok
Goto ko
ok:
Push 1
Goto end
ko:
Push 0
end:
FunctionEnd
Function DaysInMonth
Pop $0 ;annee
Pop $1 ;mois

IntCmp $1 1 m31
IntCmp $1 2 m28
IntCmp $1 3 m31
IntCmp $1 4 m30
IntCmp $1 5 m31
IntCmp $1 6 m30
IntCmp $1 7 m31
IntCmp $1 8 m31
IntCmp $1 9 m30
IntCmp $1 10 m31
IntCmp $1 11 m30
IntCmp $1 12 m31

m31:
Push 31
Goto end
m30:
Push 30
Goto end
m28:
Push $0
Call IsLeapYear
Pop $0
IntCmp $0 1 m29
Push 28
Goto end
m29:
Push 29
end:
FunctionEnd

Maybe you based "Bissext" year from one of my functions, the correct name is "Leap" year.

And second, you can know if a year is a leap year using the simple calculation:

Year % 4

If the rest is 0, it is a leap year.

I should fix those two in my function but I didn't have time to do that.


Leap and not Bissext : corrected

No: Year / 4 is not enough : years 1700, 1900, 2100, 2300 (each 200 years) are not leap.

Effectively, I called it Bissext because I first tried to use your Seconds2Date function which doesn't work for me (see my other thread of this day)


Yes, all of them are leap years. Why did Atlanta celebrated the 100th Olimpiada in 1996?


Fabiochelly is correct.

Every year divisible by 4 is a leap year.

However, every year divisible by 100 is not a leap year.
However, every year divisible by 400 is a leap year after all.

So, 1700, 1800, 1900, 2100, and 2200 are not leap years. But 1600, 2000, and 2400 are leap years.


see http://www.galactic-guide.com/articles/6R87.html

The explanation here:
http://www.multicians.org/jhs-clock.html

or here:
http://www.timeanddate.com/date/leapyear.html

In fact:
1. Every year divisible by 4 is a leap year.
2. But every year divisible by 100 is NOT a leap year
3. Unless the year is also divisible by 400, then it is still a leap year.


Bah, I have to fix my function anyways...