udfIsLeapYear
bln udfIsLeapYear (int|str)
bln udfIsLeapYearV2 (int|str)
bln udfIsLeapYearV3 (int|str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfIsLeapYear (strYmdHms)
intYear = Int (ItemExtract (1, strYmdHms, ":"))
Return !(intYear mod 4) && (!!(intYear mod 100) || !(intYear mod 400))
;..........................................................................................................................................
; This user defined function "udfIsLeapYear" determines wether the given year is a leap year or not.
; Based on the Gregorian calendar, first established in 1582 by Pope Gregory XIII.
; The function returns a boolean value of @FALSE (0) or @TRUE (1).
;
; Alternative formulas:
; Return (0 == (ch! mod 4)) && (0 != (intYear mod 4000)) && ((0 != (intYear mod 100)) || (0 == (intYear mod 400)))
; Return !(intYear mod 400) || (!(intYear mod 4) && !!(intYear mod 100))
; Return !((intYear mod 400) && ((intYear mod 4) || !(intYear mod 100)))
;
; Detlev Dalitz.20010325.20090725.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfIsLeapYearV2 (strYmdHms)
intYear = Int (ItemExtract (1, strYmdHms, ":"))
Return TimeJulianDay (intYear : ":03:01") - TimeJulianDay (intYear : ":02:28") > 1
;..........................................................................................................................................
; This user defined function "udfIsLeapYearV2" determines wether the given year is a leap year or not.
; Based on the Gregorian calendar, first established in 1582 by Pope Gregory XIII.
; The function returns a boolean value of @FALSE (0) or @TRUE (1).
;
; Detlev Dalitz.20010325.20090725.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfIsLeapYearV3 (strYmdHms)
strYmdHms = ItemExtract (1, strYmdHms, ":") : ":02:29"
intLastErrorMode = ErrorMode (@OFF)
LastError ()
TimeDiff (strYmdHms, strYmdHms) ; Is it a valid DateTime?
ErrorMode (intLastErrorMode)
Return !LastError ()
;..........................................................................................................................................
; This user defined function "udfIsLeapYearV3" determines wether the given year is a leap year or not.
; Based on the Gregorian calendar, first established in 1582 by Pope Gregory XIII.
; The function returns a boolean value of @FALSE (0) or @TRUE (1).
;
; Detlev Dalitz.20010325.20090725.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.
strMsgTitle = "Demo: udfIsLeapYear ()"
strMsgText1 = "udfIsLeapYear"
strMsgText2 = "udfIsLeapYearV2"
strMsgText3 = "udfIsLeapYearV3"

intYear = 1600
strMsgText1 = strMsgText1 : @LF : intYear : @TAB : udfIsLeapYear (intYear)
strMsgText2 = strMsgText2 : @LF : intYear : @TAB : udfIsLeapYearV2 (intYear)
strMsgText3 = strMsgText3 : @LF : intYear : @TAB : udfIsLeapYearV3 (intYear)

intYear = 1900
strMsgText1 = strMsgText1 : @LF : intYear : @TAB : udfIsLeapYear (intYear)
strMsgText2 = strMsgText2 : @LF : intYear : @TAB : udfIsLeapYearV2 (intYear)
strMsgText3 = strMsgText3 : @LF : intYear : @TAB : udfIsLeapYearV3 (intYear)

For intYear = 1996 To 2012
   strMsgText1 = strMsgText1 : @LF : intYear : @TAB : udfIsLeapYear (intYear)
   strMsgText2 = strMsgText2 : @LF : intYear : @TAB : udfIsLeapYearV2 (intYear)
   strMsgText3 = strMsgText3 : @LF : intYear : @TAB : udfIsLeapYearV3 (intYear)
Next

intYear = 2100
strMsgText1 = strMsgText1 : @LF : intYear : @TAB : udfIsLeapYear (intYear)
strMsgText2 = strMsgText2 : @LF : intYear : @TAB : udfIsLeapYearV2 (intYear)
strMsgText3 = strMsgText3 : @LF : intYear : @TAB : udfIsLeapYearV3 (intYear)

intYear = 4000
strMsgText1 = strMsgText1 : @LF : intYear : @TAB : udfIsLeapYear (intYear)
strMsgText2 = strMsgText2 : @LF : intYear : @TAB : udfIsLeapYearV2 (intYear)
strMsgText3 = strMsgText3 : @LF : intYear : @TAB : udfIsLeapYearV3 (intYear)

Message (strMsgTitle, strMsgText1)
Message (strMsgTitle, strMsgText2)
Message (strMsgTitle, strMsgText3)

Exit

;   IsLeapYear        IsLeapYear_2      IsLeapYear_3
;   1600   1          1600   1          1600   1
;   1900   0          1900   0          1900   0
;   1996   1          1996   1          1996   1
;   1997   0          1997   0          1997   0
;   1998   0          1998   0          1998   0
;   1999   0          1999   0          1999   0
;   2000   1          2000   1          2000   1
;   2001   0          2001   0          2001   0
;   2002   0          2002   0          2002   0
;   2003   0          2003   0          2003   0
;   2004   1          2004   1          2004   1
;   2005   0          2005   0          2005   0
;   2006   0          2006   0          2006   0
;   2007   0          2007   0          2007   0
;   2008   1          2008   1          2008   1
;   2009   0          2009   0          2009   0
;   2010   0          2010   0          2010   0
;   2011   0          2011   0          2011   0
;   2012   1          2012   1          2012   1
;   2100   0          2100   0          2100   0
;   4000   1          4000   1          4000   1