From cb9a3b683063bd6bcfe49d8af8b34e3ab08c7ffe Mon Sep 17 00:00:00 2001 From: schrom01 Date: Sat, 27 Aug 2022 19:41:01 +0200 Subject: [PATCH] implemented Time formating solved #5 --- Webserver/Templates/dashboard/irrigationJob.html | 2 +- Webserver/Templates/dashboard/zone.html | 2 +- Webserver/Translater.py | 15 ++++++++++++++- Webserver/static/js/dashboard.js | 2 +- Zone.py | 1 + 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Webserver/Templates/dashboard/irrigationJob.html b/Webserver/Templates/dashboard/irrigationJob.html index d552487..662ac50 100644 --- a/Webserver/Templates/dashboard/irrigationJob.html +++ b/Webserver/Templates/dashboard/irrigationJob.html @@ -2,6 +2,6 @@ {{ job.zone.number|string}} {{job.zone.name }} - {{ ((job.duration/60)|int)|string + " " + translater.getTranslation("minutes")}} + {{ ((job.duration/60))|string + " " + translater.getTranslation("minutes")}} \ No newline at end of file diff --git a/Webserver/Templates/dashboard/zone.html b/Webserver/Templates/dashboard/zone.html index 6c4c044..3cfe7d6 100644 --- a/Webserver/Templates/dashboard/zone.html +++ b/Webserver/Templates/dashboard/zone.html @@ -36,7 +36,7 @@ - {{translater.getTranslation("irragation is planed for") }}

{{ translater.getTranslation("minutes") + "." }} + {{translater.getTranslation("irrigation is planed.") }}
{{ translater.getTranslation("planed duration")}}:

{{ translater.getTranslation("minutes") + "." }} diff --git a/Webserver/Translater.py b/Webserver/Translater.py index c973bc2..7f79400 100644 --- a/Webserver/Translater.py +++ b/Webserver/Translater.py @@ -1,4 +1,6 @@ from enum import Enum +from time import strftime +from time import gmtime class Language(Enum): ENGLISH = 1 GERMAN = 2 @@ -27,7 +29,7 @@ class Translater: "switch to automatic mode": "Auf Automatikbetrieb umstellen", "minutes": "Minuten", "until": "bis", - "irragation is planed for": "Bewässerung ist geplant für", + "irrigation is planed.": "Bewässerung ist geplant.", "planed irrigationjobs": "geplante Bewässerungsaufträge", "planed duration": "geplante Dauer", "cancel": "abbrechen", @@ -45,3 +47,14 @@ class Translater: return self.dict_german[english_String] case _: return "no translations for these language" + + def formatTime(self, timeInt): + format = "" + match self.language: + case Language.ENGLISH: + format = "%I.%S %p" + case Language.GERMAN: + format = "%H:%M:%S" + case _: + format = "" + return strftime(format, gmtime(timeInt)) diff --git a/Webserver/static/js/dashboard.js b/Webserver/static/js/dashboard.js index b62e95f..2d5e15b 100644 --- a/Webserver/static/js/dashboard.js +++ b/Webserver/static/js/dashboard.js @@ -4,7 +4,7 @@ function refreshZone(zone_json) { document.getElementById("inner_icon_state_zone_" + zone.number).className = 'inner_icon ' + (zone.state ? 'dot_green' : 'dot_red'); document.getElementById("state_text_zone_" + zone.number).innerHTML = zone.state_text; document.getElementById("end_time_row_zone_" + zone.number).style.display = ((zone.setState == 1 || zone.setState == 2) ? 'table-row' : 'none'); - document.getElementById("end_time_zone_" + zone.number).innerHTML = zone.endTimeSetState; + document.getElementById("end_time_zone_" + zone.number).innerHTML = zone.endTimeSetStateFormated; document.getElementById("planed_duration_row_zone_" + zone.number).style.display = ((zone.planedDuration > 0) ? 'table-row' : 'none'); document.getElementById("planed_duration_zone" + zone.number).innerHTML = zone.planedDuration/60; document.getElementById("inner_icon_mode_zone_" + zone.number).innerHTML = zone.autoMode ? 'A' : 'M'; diff --git a/Zone.py b/Zone.py index 17eaa1d..b03ae5a 100644 --- a/Zone.py +++ b/Zone.py @@ -26,6 +26,7 @@ class Zone: "state_text": translater.getTranslation("switched on" if self.state else "switched off"), "setState": self.setState, "endTimeSetState" : self.endTimeSetState, + "endTimeSetStateFormated" : translater.formatTime(self.endTimeSetState), "planedDuration": self.planedDuration, }