diff --git a/init.lua b/init.lua index 7ffeb74..6faa3eb 100644 --- a/init.lua +++ b/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') + diff --git a/system/formspec_creation.lua b/system/formspec_creation.lua index d5621f4..8b87a9f 100644 --- a/system/formspec_creation.lua +++ b/system/formspec_creation.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..[[] ]]) diff --git a/system/get_times.lua b/system/get_times.lua new file mode 100644 index 0000000..7bb1c6e --- /dev/null +++ b/system/get_times.lua @@ -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