From fa154da83ba3e539720697f71f633d06213d3abd Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Tue, 12 Aug 2025 19:24:05 +0200 Subject: [PATCH] Update main.lua --- .../[tools]/nordi_infopoint/client/main.lua | 82 ++++++++----------- 1 file changed, 32 insertions(+), 50 deletions(-) diff --git a/resources/[tools]/nordi_infopoint/client/main.lua b/resources/[tools]/nordi_infopoint/client/main.lua index d9f7c4f61..012f71f0b 100644 --- a/resources/[tools]/nordi_infopoint/client/main.lua +++ b/resources/[tools]/nordi_infopoint/client/main.lua @@ -202,13 +202,7 @@ function showEvents() }) else for _, event in pairs(events) do - local eventDate = event.event_date and os.date('%d.%m.%Y %H:%M', os.time({ - year = tonumber(string.sub(event.event_date, 1, 4)), - month = tonumber(string.sub(event.event_date, 6, 7)), - day = tonumber(string.sub(event.event_date, 9, 10)), - hour = tonumber(string.sub(event.event_date, 12, 13)), - min = tonumber(string.sub(event.event_date, 15, 16)) - })) or 'Kein Datum' + local eventDate = formatDate(event.event_date) table.insert(eventOptions, { title = event.title, @@ -241,13 +235,7 @@ end -- Event Details anzeigen function showEventDetails(event) - local eventDate = event.event_date and os.date('%d.%m.%Y %H:%M', os.time({ - year = tonumber(string.sub(event.event_date, 1, 4)), - month = tonumber(string.sub(event.event_date, 6, 7)), - day = tonumber(string.sub(event.event_date, 9, 10)), - hour = tonumber(string.sub(event.event_date, 12, 13)), - min = tonumber(string.sub(event.event_date, 15, 16)) - })) or 'Kein Datum' + local eventDate = formatDate(event.event_date) lib.alertDialog({ header = event.title, @@ -304,13 +292,7 @@ function showIncidents() else for _, incident in pairs(incidents) do local statusColor = incident.status == 'open' and '🔴' or '🟢' - local createdDate = os.date('%d.%m.%Y %H:%M', os.time({ - year = tonumber(string.sub(incident.created_at, 1, 4)), - month = tonumber(string.sub(incident.created_at, 6, 7)), - day = tonumber(string.sub(incident.created_at, 9, 10)), - hour = tonumber(string.sub(incident.created_at, 12, 13)), - min = tonumber(string.sub(incident.created_at, 15, 16)) - })) + local createdDate = formatDate(incident.created_at) table.insert(incidentOptions, { title = statusColor .. ' ' .. incident.title, @@ -343,13 +325,7 @@ end -- Vorfall Details anzeigen function showIncidentDetails(incident) - local createdDate = os.date('%d.%m.%Y %H:%M', os.time({ - year = tonumber(string.sub(incident.created_at, 1, 4)), - month = tonumber(string.sub(incident.created_at, 6, 7)), - day = tonumber(string.sub(incident.created_at, 9, 10)), - hour = tonumber(string.sub(incident.created_at, 12, 13)), - min = tonumber(string.sub(incident.created_at, 15, 16)) - })) + local createdDate = formatDate(incident.created_at) lib.alertDialog({ header = incident.title, @@ -437,13 +413,7 @@ end -- Job-Angebot Details anzeigen function showJobOfferDetails(offer) - local createdDate = os.date('%d.%m.%Y %H:%M', os.time({ - year = tonumber(string.sub(offer.created_at, 1, 4)), - month = tonumber(string.sub(offer.created_at, 6, 7)), - day = tonumber(string.sub(offer.created_at, 9, 10)), - hour = tonumber(string.sub(offer.created_at, 12, 13)), - min = tonumber(string.sub(offer.created_at, 15, 16)) - })) + local createdDate = formatDate(offer.created_at) lib.alertDialog({ header = offer.title, @@ -713,11 +683,7 @@ function showGeneralInfo() importanceIcon = '🟠' end - local createdDate = os.date('%d.%m.%Y', os.time({ - year = tonumber(string.sub(info.created_at, 1, 4)), - month = tonumber(string.sub(info.created_at, 6, 7)), - day = tonumber(string.sub(info.created_at, 9, 10)) - })) + local createdDate = formatDateOnly(info.created_at) table.insert(infoOptions, { title = importanceIcon .. ' ' .. info.title, @@ -819,19 +785,11 @@ end -- Function to show just the content function showInfoContent(info) - local createdDate = os.date('%d.%m.%Y', os.time({ - year = tonumber(string.sub(info.created_at, 1, 4)), - month = tonumber(string.sub(info.created_at, 6, 7)), - day = tonumber(string.sub(info.created_at, 9, 10)) - })) + local createdDate = formatDateOnly(info.created_at) local expiryInfo = '' if info.expires_at then - local expiryDate = os.date('%d.%m.%Y', os.time({ - year = tonumber(string.sub(info.expires_at, 1, 4)), - month = tonumber(string.sub(info.expires_at, 6, 7)), - day = tonumber(string.sub(info.expires_at, 9, 10)) - })) + local expiryDate = formatDateOnly(info.expires_at) expiryInfo = 'Gültig bis: ' .. expiryDate .. '\n\n' end @@ -948,6 +906,30 @@ function deleteGeneralInfo(infoId) end) end +-- Helper function for date formatting without using os.time +function formatDate(dateString) + if not dateString then return 'Kein Datum' end + + local year = tonumber(string.sub(dateString, 1, 4)) + local month = tonumber(string.sub(dateString, 6, 7)) + local day = tonumber(string.sub(dateString, 9, 10)) + local hour = tonumber(string.sub(dateString, 12, 13)) or 0 + local min = tonumber(string.sub(dateString, 15, 16)) or 0 + + return string.format('%02d.%02d.%04d %02d:%02d', day, month, year, hour, min) +end + +-- Helper function for date formatting without time +function formatDateOnly(dateString) + if not dateString then return 'Kein Datum' end + + local year = tonumber(string.sub(dateString, 1, 4)) + local month = tonumber(string.sub(dateString, 6, 7)) + local day = tonumber(string.sub(dateString, 9, 10)) + + return string.format('%02d.%02d.%04d', day, month, year) +end + -- Hilfsfunktion für table.contains function table.contains(table, element) for _, value in pairs(table) do