Module:IxTime: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 4: | Line 4: | ||
local EPOCH = os.time({year=2020, month=10, day=4, hour=0, minute=0, second=0}) | local EPOCH = os.time({year=2020, month=10, day=4, hour=0, minute=0, second=0}) | ||
function p. | function p.convertToIxTime(inputTime) | ||
local | local secondsSinceEpoch = inputTime - EPOCH | ||
local ixSeconds = secondsSinceEpoch * 4.0 | |||
local | return EPOCH + ixSeconds | ||
return | |||
end | end | ||
Line 16: | Line 15: | ||
end | end | ||
function p. | function p.convertDateToIxTime(frame) | ||
local args = frame.args | local args = frame.args | ||
local year = tonumber(args[1] or args.year) | local year = tonumber(args[1] or args.year) | ||
Line 30: | Line 29: | ||
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 ixTime = p. | local ixTime = p.convertToIxTime(inputTime) | ||
return p.formatIxTime(ixTime) .. " | return p.formatIxTime(ixTime) .. " IX" | ||
end | end | ||
function p.getCurrentIxTime(frame) | function p.getCurrentIxTime(frame) | ||
local ixTime = p. | local currentTime = os.time() | ||
return p.formatIxTime(ixTime) .. " | local ixTime = p.convertToIxTime(currentTime) | ||
return p.formatIxTime(ixTime) .. " IX" | |||
end | end | ||
return p | return p |
Revision as of 20:18, 3 August 2024
Documentation for this module may be created at Module:IxTime/doc
local p = {}
-- Ensure this matches the JavaScript epoch
local EPOCH = os.time({year=2020, month=10, day=4, hour=0, minute=0, second=0})
function p.convertToIxTime(inputTime)
local secondsSinceEpoch = inputTime - EPOCH
local ixSeconds = secondsSinceEpoch * 4.0
return EPOCH + ixSeconds
end
function p.formatIxTime(ixTime)
-- Format the time to match the JavaScript output
return os.date("!%A, %B %d, %Y %I:%M:%S %p", ixTime)
end
function p.convertDateToIxTime(frame)
local args = frame.args
local year = tonumber(args[1] or args.year)
local month = tonumber(args[2] or args.month)
local day = tonumber(args[3] or args.day)
local hour = tonumber(args[4] or args.hour or "0")
local minute = tonumber(args[5] or args.minute or "0")
local second = tonumber(args[6] or args.second 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 ixTime = p.convertToIxTime(inputTime)
return p.formatIxTime(ixTime) .. " IX"
end
function p.getCurrentIxTime(frame)
local currentTime = os.time()
local ixTime = p.convertToIxTime(currentTime)
return p.formatIxTime(ixTime) .. " IX"
end
return p