Jump to content

Module:DatesWD and Module:DatesWD/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
No edit summary
 
Slight simplifications
 
Line 7: Line 7:
if str == "" or str == nil then
if str == "" or str == nil then
return nil
return nil
elseif type(tonumber(str)) == "number" then
elseif tonumber(str) then
return math.floor(tonumber(str))
return math.floor(tonumber(str))
else
else
Line 16: Line 16:


local function inbord(val, down, up)
local function inbord(val, down, up)
if type(up) ~= "number" or type(down) ~= "number" or type(val) ~= "number" or up < down or val < down or val > up then
return not (type(up) ~= "number" or type(down) ~= "number" or type(val) ~= "number" or up < down or val < down or val > up)
return false
else
return true
end
end
end


local function isdate ( chain )
local function isdate ( chain )
if (not type(chain) == "table")
return (type(chain == "table")
or (not inbord(chain.year,-9999,9999))
and inbord(chain.year,-9999,9999)
or (not inbord(chain.month,1,12))
and inbord(chain.month,1,12)
or (not inbord(chain.day,1,31))
and inbord(chain.day,1,31))
then return false
else return true end
-- more detailed check for 31.02.0000 needed
-- more detailed check for 31.02.0000 needed
-- check for other calendars needed
-- check for other calendars needed