FANDOM


--<pre>Description: Wrapper/invocable for [[Module:Date]]
--Syntax : based on http://tieske.github.io/date/ Use YYYY-MM-DD if possible
--{{#invoke:Datecalc|main|funcname|date|arg1|arg2...}}
--Example:
--{{#invoke:Datecalc|main|diff|2013/12/10|2013/12/11}},{{#invoke:Datecalc|main|adddays|2013/12/10|5}}
local p ={}
local getArgs = require("Dev:Arguments").getArgs
local gDate = require("Dev:Date")
local l = require("Module:Utility").log
function p.main(frame)
   local args = getArgs(frame)
 
   return p._main(args)
end
 
function p._main(args)
    args = mw.clone(args)
    if not args[1] then 
       return
    end
 
    local func = args[1]
    local tDateFuncs = {diff=1,epoch=1,isleapyear=1}
 
    if tDateFuncs[func] then
       local arg2 = args[2]
       local arg3 = args[3] or os.date("%x")
 
       if func =="diff" and arg2 and arg3 then
            return gDate[func](arg2,arg3):spandays()     
       end
 
       return gDate[func](arg2)
    else
        local currDate = args[2] or os.date("%x")
        local objDate = gDate(currDate)
        local dateParams = {}
 
        if args[1] or args[2] then
            --Excludes function, date, leaves rest of parameters
            for i,v in ipairs(args) do
                if i>2 then
                    table.insert(dateParams,args[i])
                end
            end
        end
 
        return objDate[func](objDate,unpack(dateParams))
    end
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.