mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 10:13:50 +01:00
implement time getting function
This commit is contained in:
parent
fbca7a64fa
commit
e84fa467db
2
init.lua
2
init.lua
@ -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
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
|
Loading…
Reference in New Issue
Block a user