implement timezone offset configuration

This commit is contained in:
Dirk Sohler 2019-02-19 13:40:19 +01:00
parent 4c5de1fb42
commit fbca7a64fa
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
4 changed files with 53 additions and 0 deletions

@ -9,6 +9,7 @@ mtimer = {
visible = { key = 'mtimer:visible', default = 'true' },
position = { key = 'mtimer:position', default = 'bl' },
color = { key = 'mtimer:color', default = '#ffffffFF' },
timezone_offset = { key = 'mtimer:timezone_offset', default = '0' },
}
}

@ -24,6 +24,13 @@ Click the position you want to place the timer at.=Auf die Stelle klicken, an de
mTimer Color=mTimer-Farbe
Use `@1` format only!=Ausschließlich `@1`-Format benutzen!
# Timezone Offset
mTimer Timezone Offset=mTimer-Zeitzonenunterschied
30 minutes @= 0.5, 60 minutes @= 1=30 Minuten @= 0.5, 60 Minuten @= 1
“Arbitrary” values are possible.=Es sind „beliebige“ Werte möglich.
Server Time: @1=Serverzeit: @1
Local Time: @1=Lokale Zeit: @1
# Generic Formspec Strings
Default=Standard
Exit=Verlassen

@ -12,6 +12,9 @@ local build_frame = function (width, height, title)
container_end[]
]]
local width = width < 6 and 6 or width
local height = height < 2 and 2 or height
return formspec_frame:gsub('%+%a+', {
['+width'] = width,
['+height'] = height,
@ -94,3 +97,32 @@ mtimer.show_formspec.set_color = function (player_name)
label[-0.05,1.45;]]..S('Use `@1` format only!', hexcolor)..[[]
]])
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 format_information = table.concat({
S('30 minutes @= 0.5, 60 minutes @= 1'),
S('“Arbitrary” values are possible.')
}, '\n')
local time_information = table.concat({
S('Server Time: @1', server_time),
S('Local Time: @1', local_time)
}, '\n')
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..[[]
label[3,0.425;]]..format_information..[[]
label[0,1.45;]]..time_information..[[]
]])
end

@ -11,6 +11,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.set_visibility then f.set_visibility(name) end
if fields.set_position then f.set_position(name) end
if fields.set_color then f.set_color(name) end
if fields.timezone_offset then f.timezone_offset(name) end
end
@ -53,6 +54,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
-- Configure timezone offset
if formname == 'mtimer:timezone_offset' then
local attr = m.meta.timezone_offset
local value = tonumber(fields.offset) or attr.default
if math.abs(value) > os.time() then value = 0 end
meta:set_string(attr.key, value)
if fields.default then meta:set_string(attr.key, attr.default) end
if not fields.quit then mtimer.show_formspec.timezone_offset(name) end
end
-- Back to menu from all formspecs
if fields.main_menu then f.main_menu(name) end