Leap year code

I’m learning Xojo by reading documentation, watching webinars and short videos and trying to understand code examples.

For Feedback case #50283 I found the following code (isLeapYear method (extends myDate as Xojo.Core.Date, year as int32) As boolean).:

#PRAGMA unused myDate const LEAPYEAR_INTERVAL as int32 = 4 const CENTUARY as int32 = 100 const QUAD_CENTUARY as int32 = 400 dim isLeap as boolean = False if not((year mod LEAPYEAR_INTERVAL) = 0) then isLeap = False elseif not((year mod CENTUARY) = 0) then isLeap = True elseif not((year mod QUAD_CENTUARY) = 0) then isLeap = False else isLeap = True end if return isLeap

I haven’t used the “If not() Then” for more than 25 years, so it took me some time and tests to figure the code. Now it is clear what the code does and I know with a little practice I may use something like that in my code.

I’m working on a program but I’m using the old framework date. It was easier to understand (for me), and I did some leap year check also (completely different than the code above). Now I changed the code above with my code but using the Xojo.Core.Date. Changing the code above results in this:

#PRAGMA unused myDate Dim isLeap As Boolean = False Dim biDate As New Xojo.core.Date(year,12,31, Xojo.Core.TimeZone.Current) If biDate.DayOfYear = 366 Then isLeap = True Return isLeap

I get the same results with both.
My question to more experienced Xojo programmers, is this code ok? Any comments about it are really welcome.

Yup, that seems like fine code and a great way to do it.

Here’s another way with the old framework:

dim d as new Date( testYear, 2, 29 )
isLeap = d.Day = 29

Since the Date will never be initialized to a nonexistent date, this works too.