Module:IxTime: Difference between revisions
Jump to navigation
Jump to search
Created page with "local p = {} local EPOCH = os.time({year=2020, month=10, day=4, hour=0, minute=0, second=0}) function p.convertToIxTime(frame) local args = frame.args local year = tonumber(args[1]) local month = tonumber(args[2]) local day = tonumber(args[3]) local hour = tonumber(args[4] or "0") local minute = tonumber(args[5] or "0") local second = tonumber(args[6] or "0") if not year or not month or not day then return "Error: Invalid date f..." |
mNo edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local | local function getTemplateVar(varName) | ||
local frame = mw.getCurrentFrame() | |||
return tonumber(frame:expandTemplate{ title = 'PAGEVAR', args = { 'IxTime', varName } }) | |||
end | |||
local EPOCH = getTemplateVar('ixtime_epoch') | |||
local MULTIPLIER = getTemplateVar('ixtime_multiplier') | |||
function p.convertToIxTime(frame) | function p.convertToIxTime(frame) | ||
Line 18: | Line 24: | ||
local inputTime = os.time({year=year, month=month, day=day, hour=hour, minute=minute, second=second}) | local inputTime = os.time({year=year, month=month, day=day, hour=hour, minute=minute, second=second}) | ||
local secondsSinceEpoch = inputTime - EPOCH | local secondsSinceEpoch = inputTime - EPOCH | ||
local ixTime = math.floor(secondsSinceEpoch * | local ixTime = math.floor(secondsSinceEpoch * MULTIPLIER + EPOCH) | ||
local ixDate = os.date("!%A, %B %d, %Y %H:%M:%S", ixTime) | local ixDate = os.date("!%A, %B %d, %Y %H:%M:%S", ixTime) |
Revision as of 19:39, 3 August 2024
Documentation for this module may be created at Module:IxTime/doc
local p = {}
local function getTemplateVar(varName)
local frame = mw.getCurrentFrame()
return tonumber(frame:expandTemplate{ title = 'PAGEVAR', args = { 'IxTime', varName } })
end
local EPOCH = getTemplateVar('ixtime_epoch')
local MULTIPLIER = getTemplateVar('ixtime_multiplier')
function p.convertToIxTime(frame)
local args = frame.args
local year = tonumber(args[1])
local month = tonumber(args[2])
local day = tonumber(args[3])
local hour = tonumber(args[4] or "0")
local minute = tonumber(args[5] or "0")
local second = tonumber(args[6] or "0")
if not year or not month or not day then
return "Error: Invalid date format"
end
local inputTime = os.time({year=year, month=month, day=day, hour=hour, minute=minute, second=second})
local secondsSinceEpoch = inputTime - EPOCH
local ixTime = math.floor(secondsSinceEpoch * MULTIPLIER + EPOCH)
local ixDate = os.date("!%A, %B %d, %Y %H:%M:%S", ixTime)
return ixDate .. " IX"
end
return p