Module:Sandbox/DixonD/DateTemplates explained

local DateTime = require("Module:Sandbox/DixonD/Datetime");local Math = require("Module:Math");local Error = require('Module:Error')

local z =

-- utility functionslocal function getArgs(frame) local args = frame.args; -- if there are any arguments, then assume that we've got proper ones for k,v in pairs(args) do return args end -- otherwise, return args from the parent local parent = frame:getParent; return parent.args;end

local function isError(response) return type(response)

'string' and string.find(response, 'error');end

--template implementations

-- function z.julianDay(frame) local args = getArgs(frame); return DateTime.julianDay(Math._cleanNumber(args[1]), Math._cleanNumber(args[2]), Math._cleanNumber(args[3]), Math._cleanNumber(args[4]), Math._cleanNumber(args[5]), Math._cleanNumber(args[6]), 'g');end

-- function z.yearOfJulianDay(frame) local args = getArgs(frame); return DateTime.yearOfJulianDay(Math._cleanNumber(args[1]), 'g');end

-- function z.monthOfJulianDay(frame) local args = getArgs(frame); return DateTime.monthOfJulianDay(Math._cleanNumber(args[1]), 'g');end

-- function z.dayOfJulianDay(frame) local args = getArgs(frame); return DateTime.dayOfJulianDay(Math._cleanNumber(args[1]), 'g');end

-- function z.hourOfJulianDay(frame) local args = getArgs(frame); return DateTime.hourOfJulianDay(Math._cleanNumber(args[1]), 'g');end

-- function z.minuteOfJulianDay(frame) local args = getArgs(frame); return DateTime.minuteOfJulianDay(Math._cleanNumber(args[1]), 'g');end

-- function z.secondOfJulianDay(frame) local args = getArgs(frame); return DateTime.secondOfJulianDay(Math._cleanNumber(args[1]), 'g');end

-- function z.julianDayJulian(frame) local args = getArgs(frame); return DateTime.julianDay(Math._cleanNumber(args[1]), Math._cleanNumber(args[2]), Math._cleanNumber(args[3]), Math._cleanNumber(args[4]), Math._cleanNumber(args[5]), Math._cleanNumber(args[6]), 'j');end

-- function z.gregorianSerialDate(frame) local args = getArgs(frame); local currentDate = os.date('!*t'); local year = args.year

nil and currentDate.year or Math._cleanNumber(args.year); if year

nil then return Error.error; end; local month = args.month

nil and currentDate.month or Math._cleanNumber(args.month); if month

nil then return Error.error; end; local day = args.day

nil and currentDate.day or Math._cleanNumber(args.day); if day

nil then return Error.error; end; local julianDay = DateTime.julianDay(year, month, day, nil, nil, nil, 'g'); if isError(julianDay) then return julianDay; end; return julianDay - 1721425;end

return z