implement time getting function

This commit is contained in:
Dirk Sohler 2019-02-21 14:37:58 +01:00
parent fbca7a64fa
commit e84fa467db
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
3 changed files with 27 additions and 8 deletions

@ -19,3 +19,5 @@ dofile(syspath..'formspec_creation.lua')
dofile(syspath..'timer_update.lua')
dofile(syspath..'on_receive_fields.lua')
dofile(syspath..'on_joinplayer.lua')
dofile(syspath..'get_times.lua')

@ -100,13 +100,9 @@ end
mtimer.show_formspec.timezone_offset = 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()
local local_timestamp = server_timestamp + ((offset*60)*60)
local server_time = os.date('%Y-%m-%dT%T', server_timestamp)
local local_time = os.date('%Y-%m-%dT%T', local_timestamp)
local time_data = mtimer.get_times(player_name).real_time
local server_time = os.date('%Y-%m-%dT%T', time_data.server_timestamp)
local local_time = os.date('%Y-%m-%dT%T', time_data.local_timestamp)
local format_information = table.concat({
S('30 minutes @= 0.5, 60 minutes @= 1'),
@ -121,7 +117,7 @@ mtimer.show_formspec.timezone_offset = function (player_name)
minetest.show_formspec(player_name, 'mtimer:timezone_offset',
build_frame(7, 3, S('mTimer Timezone Offset'))..[[
field_close_on_enter[offset;false]
field[0.25,0.75;3,1;offset;;]]..offset..[[]
field[0.25,0.75;3,1;offset;;]]..time_data.offset..[[]
label[3,0.425;]]..format_information..[[]
label[0,1.45;]]..time_information..[[]
]])

21
system/get_times.lua Normal file

@ -0,0 +1,21 @@
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
mtimer.get_times = function (player_name)
return {
real_time = get_real_time(player_name)
}
end