mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 10:13:50 +01:00
89cd1f6212
Convert ingame time to millihours and calculate the timestamp from this. It results in a default timestampo that is parsed by default date and time functions. Replacement variables: {24h} = 24 hours time {12h} = 12 hours time {min} = minutes {its} = ingame timestamp For some reason I was not able to get the am/pm indicator (`%p`) so 12 hours format is only the time and no optional indicator.
48 lines
1.4 KiB
Lua
48 lines
1.4 KiB
Lua
local m = mtimer
|
|
|
|
|
|
local get_real_time = function (player_name)
|
|
local player = minetest.get_player_by_name(player_name)
|
|
local _offset = player:get_meta():get_string(m.meta.timezone_offset.key)
|
|
local _server_timestamp = os.time()
|
|
|
|
return {
|
|
offset = _offset,
|
|
server_timestamp = _server_timestamp,
|
|
local_timestamp = _server_timestamp + ((_offset*60)*60)
|
|
}
|
|
end
|
|
|
|
|
|
local get_ingame_time = function (player_name)
|
|
local player = minetest.get_player_by_name(player_name)
|
|
local format = player:get_meta():get_string(m.meta.ingame_time.key)
|
|
local time_of_day = tostring((minetest.get_timeofday() * 24000) * 3.6)
|
|
local ingame_timestamp = tonumber(string.format("%.0f", time_of_day))
|
|
|
|
local values = {
|
|
hours_24 = os.date('!%H', ingame_timestamp),
|
|
hours_12 = os.date('!%I', ingame_timestamp),
|
|
minutes = os.date('!%M', ingame_timestamp),
|
|
ingame_timestamp = ingame_timestamp,
|
|
format = format
|
|
}
|
|
|
|
values['formatted'] = format:gsub('{[a-z0-9]+}', {
|
|
['{24h}'] = values.hours_24,
|
|
['{12h}'] = values.hours_12,
|
|
['{min}'] = values.minutes,
|
|
['{its}'] = values.ingame_timestamp
|
|
})
|
|
|
|
return values
|
|
end
|
|
|
|
|
|
mtimer.get_times = function (player_name)
|
|
return {
|
|
real_time = get_real_time(player_name),
|
|
ingame_time = get_ingame_time(player_name)
|
|
}
|
|
end
|