Module:Systime

From Post-Self
Revision as of 05:18, 3 February 2024 by Fireheart& (talk | contribs) (Fix output ternary operator.)

Documentation for this module may be created at Module:Systime/doc

-- This module implements {{Systime}}.

local p = {}

function p.toSystime(frame)
	year = frame.args.year
	month = frame.args.month
	day = frame.args.day
	hour = frame.args.hour
	min = frame.args.min
	sec = frame.args.sec

	time = os.time({year = year, month = month ~= "" and month or 1, day = day ~= "" and day or 1, hour = hour, min = min, sec = sec})
	date = os.date("*t", time)
	yday = month ~= "" and day ~= "" and "+" .. date.yday or ""
	tdec = date.hour / 24 + date.min / 60 / 24 + date.sec / 60 / 60 / 24
	tdec = hour ~= "" and string.sub(math.floor(tdec * 100 + 0.5) / 100, 2) or ""
	year = date.year - 2124
	return year .. yday .. tdec
end

function p.toTimestamp(frame)
	year = frame.args.year
	month = frame.args.month
	day = frame.args.day
	hour = frame.args.hour
	min = frame.args.min
	sec = frame.args.sec

	time = os.time({year = year, month = month ~= "" and month or 1, day = day ~= "" and day or 1, hour = hour, min = min, sec = sec})

	return hour ~= "" and os.date("%H:%M ", time) or "" .. month ~= "" and day ~= "" and os.date("%d %B %Y", time) or os.date("%Y", time)
end

return p