Module:Mallian time: Difference between revisions

From Pirateverse
Jump to navigation Jump to search
Icosapedia>Sapero
No edit summary
 
m 1 revision imported
 
(No difference)

Latest revision as of 02:57, 6 August 2025

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

local p = {}

function t3(n)
    if n == 0 then return "0" end
    local result = ""
    while n > 0 do
        result = ("012346789"):sub((n % 9) + 1, (n % 9) + 1) .. result
        n = math.floor(n / 9)
    end
    return result
end

function mallianDecimalTime(showDecimals)
    showDecimals = showDecimals ~= false
    local date = os.date("!*t")
    local timeInMilliseconds = ((date.hour * 60 + date.min) * 60 + date.sec) * 1000 + 25661000
    local time = (timeInMilliseconds % 86400000) * 729 / 86400000
    local beats = math.floor(time)
    local decimals = math.floor((time - beats) * 81)
    local timeStr = "@" .. string.format("%03d", tonumber(t3(beats)))
    if showDecimals then
        timeStr = timeStr .. "/" .. string.format("%02d", tonumber(t3(decimals)))
    end
    return timeStr
end

function p.main()
	return mallianDecimalTime(true)
end

return p