Extends tells the IDE that I’m adding a method to an object, in this case a DateTime object called Value. Because I’m adding that method to every DateTime object in the project the method needs to have global scope and be in a module.
Another method is the one for determining if a DateTime object value is a leap year which you’ve seen before.
Public Function LeapYear(Extends Value As DateTime) as Boolean
Var dt As New DateTime(Value.Year, 12, 31, 12, 0, 0, 0, TimeZone.Current)
Return dt.DayOfYear = 366
End Function
Which returns true if the 31st of December in the year of the date at midday has a day of year number of 366. I chose midday so the calculation wouldn’t be affected by day light savings adjustments.
I have dozens of these methods in various modules and once you are proficient with the concept you’ll never stop using them.
Okay, since I want to understand this. The current hour, min, second and nanosecond are passed to the function to be subtracted from the current DateTime.now which leaves the current year, month and day and everything else is now 0. Am I following this correctly?