implement meridiem indicator

implements https://gitlab.com/4w/mtimer/-/issues/20
This commit is contained in:
Dirk Sohler 2021-10-16 22:07:33 +02:00
parent f90cba8852
commit 91c967cf4f
No known key found for this signature in database
GPG Key ID: B9751241BD7D4E1A
4 changed files with 56 additions and 27 deletions

@ -99,7 +99,7 @@ Stop stop custom timer=Individuellen Timer anhalten
Restart the custom timer=Individuellen Timer neu starten Restart the custom timer=Individuellen Timer neu starten
# Custonm timer status messages # Default custom timer status messages
The custom timer is already running=Der individuelle Timer läuft bereits The custom timer is already running=Der individuelle Timer läuft bereits
The custom timer is not running=Der individuelle Timer läuft nicht The custom timer is not running=Der individuelle Timer läuft nicht
The custom timer was started=Der individuelle Timer wurde gestartet The custom timer was started=Der individuelle Timer wurde gestartet
@ -188,3 +188,10 @@ September=September
Oktober=Oktober Oktober=Oktober
November=November November=November
December=Dezember December=Dezember
# Related to the meridiem indicator
Meridiem Indicator=Tageshälftenhinweis
am=vorm.
pm=nachm.
(ERROR)=(FEHLER)

@ -54,14 +54,15 @@ mtimer.dialog.ingame_time_format = function (player_name)
'field_close_on_enter[format;false]', 'field_close_on_enter[format;false]',
'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']', 'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']',
'container[0,1.5]', 'container[0,1.5]',
line(0, '', S('Variable'), S('Current Value')), line(0, '', S('Variable'), S('Current Value')),
line(1, '-'), line(1, '-'),
line(2, S('Hours (24h)'), '{24h}', time_data.hours_24), line(2, S('Hours (24h)'), '{24h}', time_data.hours_24),
line(3, S('Hours (12h)'), '{12h}', time_data.hours_12), line(3, S('Hours (12h)'), '{12h}', time_data.hours_12),
line(4, S('Minutes'), '{min}', time_data.minutes), line(4, S('Minutes'), '{min}', time_data.minutes),
line(5, S('Ingame Timestamp'), '{its}', time_data.ingame_timestamp), line(5, S('Meridiem Indicator'),'{mi}', time_data.indicator),
line(6, '-'), line(6, S('Ingame Timestamp'), '{its}', time_data.ingame_timestamp),
line(7, S('Current Result'), esc(time_data.formatted), ''), line(7, '-'),
line(8, S('Current Result'), esc(time_data.formatted), ''),
'container_end[]' 'container_end[]'
} }
}) })

@ -22,30 +22,31 @@ mtimer.dialog.real_time_universal = function (player_name, config)
mtimer.show_formspec(config.formspec_name, { mtimer.show_formspec(config.formspec_name, {
title = config.title, title = config.title,
show_to = player_name, show_to = player_name,
height = 8.75, height = 9,
formspec = { formspec = {
'field_close_on_enter[format;false]', 'field_close_on_enter[format;false]',
'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']', 'field[0,0;+contentWidth,0.5;format;;'..esc(time_data.format)..']',
'container[0,1.5]', 'container[0,1.5]',
line(0, '', S('Variable'), S('Current Value')), line(0, '', S('Variable'), S('Current Value')),
line(1, '-'), line(1, '-'),
line(2, S('Hours (24h)'), '{24h}', vars.hours_24), line(2, S('Hours (24h)'), '{24h}', vars.hours_24),
line(3, S('Hours (12h)'), '{12h}', vars.hours_12), line(3, S('Hours (12h)'), '{12h}', vars.hours_12),
line(4, S('Minutes'), '{min}', vars.minutes), line(4, S('Minutes'), '{min}', vars.minutes),
line(5, S('Seconds'), '{sec}', vars.seconds), line(5, S('Seconds'), '{sec}', vars.seconds),
line(6, '-'), line(6, S('Meridiem Indicator'), '{mi}', vars.indicator),
line(7, S('Day Name'), '{dname}', vars.dayname), line(7, '-'),
line(8, S('Month Name'), '{mname}', vars.monthname), line(8, S('Day Name'), '{dname}', vars.dayname),
line(9, '-'), line(9, S('Month Name'), '{mname}', vars.monthname),
line(10, S('Year'), '{year}', vars.year), line(10, '-'),
line(11, S('Month'), '{month}', vars.month), line(11, S('Year'), '{year}', vars.year),
line(12, S('Day'), '{day}', vars.day), line(12, S('Month'), '{month}', vars.month),
line(13, '-'), line(13, S('Day'), '{day}', vars.day),
line(14, S('ISO 8601 Date'), '{isodate}', vars.iso8601_date), line(14, '-'),
line(15, S('ISO 8601 Time'), '{isotime}', vars.iso8601_time), line(15, S('ISO 8601 Date'), '{isodate}', vars.iso8601_date),
line(16, S('Timestamp'), '{timestamp}', vars.timestamp), line(16, S('ISO 8601 Time'), '{isotime}', vars.iso8601_time),
line(17, '-'), line(17, S('Timestamp'), '{timestamp}', vars.timestamp),
line(18, S('Current Result'), esc(time_data.formatted), ''), line(18, '-'),
line(19, S('Current Result'), esc(time_data.formatted), ''),
'container_end[]' 'container_end[]'
} }
}) })

@ -3,6 +3,22 @@ local S = m.translator
local ds = minetest.deserialize local ds = minetest.deserialize
-- Manually calculate am/pm
--
-- Because %p returns am/pm or nothing depending on current locale it is not
-- reliable to use it. This function takes a 24h hours value and returns the
-- correct meridiem indicator.
--
-- @param hour The hour to get the indicator for in 24h format
-- @return string The meridiem indicator for that hour
local get_mi = function (hour)
local s_hour = tonumber(hour)
if s_hour >= 0 and s_hour <= 11 then return S('am') end -- midnight->noon
if s_hour >= 12 and s_hour <= 23 then return S('pm') end -- noon->midnight
return S('(ERROR)')
end
-- Get translated date names -- Get translated date names
-- --
-- This helper function takes a table containing a numerical month and a -- This helper function takes a table containing a numerical month and a
@ -111,6 +127,7 @@ local get_real_time_universal = function (player_name, time_type)
hours_12 = os.date(force_utc..'%I', local_timestamp), hours_12 = os.date(force_utc..'%I', local_timestamp),
minutes = os.date(force_utc..'%M', local_timestamp), minutes = os.date(force_utc..'%M', local_timestamp),
seconds = os.date(force_utc..'%S', local_timestamp), seconds = os.date(force_utc..'%S', local_timestamp),
indicator = get_mi(os.date(force_utc..'%H', local_timestamp)),
dayname = date_names.day, dayname = date_names.day,
monthname = date_names.month, monthname = date_names.month,
year = os.date(force_utc..'%Y', local_timestamp), year = os.date(force_utc..'%Y', local_timestamp),
@ -128,6 +145,7 @@ local get_real_time_universal = function (player_name, time_type)
['{12h}'] = values.variables.hours_12, ['{12h}'] = values.variables.hours_12,
['{min}'] = values.variables.minutes, ['{min}'] = values.variables.minutes,
['{sec}'] = values.variables.seconds, ['{sec}'] = values.variables.seconds,
['{mi}'] = values.variables.indicator,
['{dname}'] = values.variables.dayname, ['{dname}'] = values.variables.dayname,
['{mname}'] = values.variables.monthname, ['{mname}'] = values.variables.monthname,
['{year}'] = values.variables.year, ['{year}'] = values.variables.year,
@ -182,6 +200,7 @@ local get_ingame_time = function (player_name)
hours_24 = os.date('!%H', ingame_timestamp), hours_24 = os.date('!%H', ingame_timestamp),
hours_12 = os.date('!%I', ingame_timestamp), hours_12 = os.date('!%I', ingame_timestamp),
minutes = os.date('!%M', ingame_timestamp), minutes = os.date('!%M', ingame_timestamp),
indicator = get_mi(os.date(os.date('!%H', ingame_timestamp))),
ingame_timestamp = ingame_timestamp, ingame_timestamp = ingame_timestamp,
format = format format = format
} }
@ -190,6 +209,7 @@ local get_ingame_time = function (player_name)
['{24h}'] = values.hours_24, ['{24h}'] = values.hours_24,
['{12h}'] = values.hours_12, ['{12h}'] = values.hours_12,
['{min}'] = values.minutes, ['{min}'] = values.minutes,
['{mi}'] = values.indicator,
['{its}'] = values.ingame_timestamp ['{its}'] = values.ingame_timestamp
}) })