Modul:Age: Unterschied zwischen den Versionen

439 Bytes hinzugefügt ,  vor 11 Jahren
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)
K (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))
Zeile 38: Zeile 38:
local function is_leap_year(year)
local function is_leap_year(year)
     -- Return true if year is a leap year, assuming Gregorian calendar.
     -- Return true if year is a leap year, assuming Gregorian calendar.
     return (year % 4 == 0 and year % 100 ~= 0) or year % 400 == 0
     return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)
end
end


Zeile 128: Zeile 128:
     if self.year < rhs.year then
     if self.year < rhs.year then
         return true
         return true
     end
     elseif self.year == rhs.year then
    if self.year == rhs.year then
         if self.month < rhs.month then
         if self.month < rhs.month then
             return true
             return true
         end
         elseif self.month == rhs.month then
        if self.month == rhs.month then
             return self.day < rhs.day
             return self.day < rhs.day
         end
         end
     end
     end
     return false
     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
end


Anonymer Benutzer