Jump to content

Module:Date: Difference between revisions

update from sandbox: ranges of more time units
m (Protected "Module:Date": High risk module ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
(update from sandbox: ranges of more time units)
Line 1,329: Line 1,329:
local function choose(v)
local function choose(v)
if type(v) == 'table' then
if type(v) == 'table' then
if not wantrange then
if not wantrange or v[1] == v[2] then
-- Example: Date('partial', 2005) - Date('partial', 2001) gives
-- Example: Date('partial', 2005) - Date('partial', 2001) gives
-- diff.years = { 3, 4 } to show the range of possible results.
-- diff.years = { 3, 4 } to show the range of possible results.
Line 1,350: Line 1,350:
if code == 'y' then
if code == 'y' then
return choose(diff.partial.years)
return choose(diff.partial.years)
end
if code == 'm' or code == 'w' or code == 'd' then
return choose({ diff.partial.mindiff:age(code), diff.partial.maxdiff:age(code) })
end
end
return nil
return nil
Line 1,571: Line 1,574:
local diff = date1 - date2
local diff = date1 - date2
if diff.isnegative then
if diff.isnegative then
return { years = 0, months = 0 }
return date1 - date1  -- a valid diff in case we call its methods
end
end
return diff
return diff
Line 1,594: Line 1,597:
date1 = date1,
date1 = date1,
date2 = date2,
date2 = date2,
partial = { years = years, months = months },
partial = {
years = years,
months = months,
maxdiff = maxdiff,
mindiff = mindiff,
},
isnegative = isnegative,
isnegative = isnegative,
iszero = iszero,
iszero = iszero,
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.