Module:Age: Difference between revisions

439 bytes added ,  10 years ago
Change order of calculation of is_leap_year for tine efficiency tweak (tested with some manual code returns), and some if/else's on mutually exclusive combinations of neg year/month/day (tested with :Australian_Labor_Party)
m (Documented unusual plural/singular handling (no code changes were made, only comments); tested with :Australian_Labor_Party)
(Change order of calculation of is_leap_year for tine efficiency tweak (tested with some manual code returns), and some if/else's on mutually exclusive combinations of neg year/month/day (tested with :Australian_Labor_Party))
Line 38:
local function is_leap_year(year)
-- Return true if year is a leap year, assuming Gregorian calendar.
return (year % 4 == 0 and (year % 100 ~= 0) or year % 400 == 0)
end
 
Line 128:
if self.year < rhs.year then
return true
ifelseif self.year == rhs.year then
end
if self.year == rhs.year then
if self.month < rhs.month then
return true
ifelseif self.month == rhs.month then
end
if self.month == rhs.month then
return self.day < rhs.day
end
end
return false
-- probably simplify to return (self.year < rhs.year) or ((self.year == rhs.year) and ((self.month < rhs.month) or ((self.month == rhs.month) and (self.day < rhs.day))))
-- would be just as efficient, as lua does not evaluate second argument of (true or second_argument)
-- or similarly return self.year < rhs.year ? true : self.year > rhs.year ? false : self.month < rhs.month ? true : self.month > rhs.month ? false : self.day < rhs.day
end
 
Anonymous user