2019-02-21 14:37:58 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2019-02-21 16:16:10 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2019-02-21 14:37:58 +01:00
|
|
|
mtimer.get_times = function (player_name)
|
|
|
|
return {
|
2019-02-21 16:16:10 +01:00
|
|
|
real_time = get_real_time(player_name),
|
|
|
|
ingame_time = get_ingame_time(player_name)
|
2019-02-21 14:37:58 +01:00
|
|
|
}
|
|
|
|
end
|