From 89985d82a48a41cf16732a2fa85c4855dc9ef637 Mon Sep 17 00:00:00 2001 From: "info@revskills.de" Date: Sat, 9 Dec 2023 21:04:37 +0100 Subject: [PATCH] Add option to set timezone minutes offset & Fix wrong timezone hour offset --- src/gui/MItem_tools.cpp | 39 +++++++++++++ src/gui/MItem_tools.hpp | 25 +++++++- src/gui/print_time_module.cpp | 8 ++- src/gui/screen_menu_lang_and_time.hpp | 2 +- src/gui/screen_menu_tune.hpp | 2 +- src/gui/screen_printing.cpp | 3 +- src/gui/time_tools.cpp | 57 ++++++++++++++++++- src/gui/time_tools.hpp | 39 +++++++++++++ .../src/menu_spin_config_with_units.cpp | 4 +- .../store_instances/config_store/defaults.hpp | 2 + .../config_store/store_definition.hpp | 2 + 11 files changed, 175 insertions(+), 8 deletions(-) diff --git a/src/gui/MItem_tools.cpp b/src/gui/MItem_tools.cpp index 32eaa6956a..b67987131b 100644 --- a/src/gui/MItem_tools.cpp +++ b/src/gui/MItem_tools.cpp @@ -415,6 +415,45 @@ void MI_TIMEZONE::OnClick() { config_store().timezone.set(timezone); } +/*****************************************************************************/ +// MI_TIMEZONE_MIN +MI_TIMEZONE_MIN::MI_TIMEZONE_MIN() + : WI_SWITCH_t<3>(static_cast(time_tools::get_timezone_minutes_offset()), _(label), nullptr, is_enabled_t::yes, is_hidden_t::no, _(str_0min), _(str_30min), _(str_45min)) {} + +void MI_TIMEZONE_MIN::OnChange([[maybe_unused]] size_t old_index) { + switch (index) { + case 0: + time_tools::set_timezone_minutes_offset(time_tools::TimeOffsetMinutes::_0min); + break; + case 1: + time_tools::set_timezone_minutes_offset(time_tools::TimeOffsetMinutes::_30min); + break; + case 2: + time_tools::set_timezone_minutes_offset(time_tools::TimeOffsetMinutes::_45min); + break; + default: + assert(0); + } +} + +/*****************************************************************************/ +// MI_TIMEZONE_SUMMER +MI_TIMEZONE_SUMMER::MI_TIMEZONE_SUMMER() + : WI_SWITCH_t<2>(static_cast(time_tools::get_timezone_summertime_offset()), _(label), nullptr, is_enabled_t::yes, is_hidden_t::no, _(str_wintertime), _(str_summertime)) {} + +void MI_TIMEZONE_SUMMER::OnChange([[maybe_unused]] size_t old_index) { + switch (index) { + case 0: + time_tools::set_timezone_summertime_offset(time_tools::TimeOffsetSummerTime::_wintertime); + break; + case 1: + time_tools::set_timezone_summertime_offset(time_tools::TimeOffsetSummerTime::_summertime); + break; + default: + assert(0); + } +} + /*****************************************************************************/ // MI_TIME_FORMAT MI_TIME_FORMAT::MI_TIME_FORMAT() diff --git a/src/gui/MItem_tools.hpp b/src/gui/MItem_tools.hpp index e4d8680e2a..e5ea738010 100644 --- a/src/gui/MItem_tools.hpp +++ b/src/gui/MItem_tools.hpp @@ -236,13 +236,36 @@ class MI_SOUND_VOLUME : public WiSpinInt { }; class MI_TIMEZONE : public WiSpinInt { - constexpr static const char *const label = N_("Time Zone Offset"); + constexpr static const char *const label = N_("Time Zone Hour Offset"); public: MI_TIMEZONE(); virtual void OnClick() override; }; +class MI_TIMEZONE_MIN : public WI_SWITCH_t<3> { + constexpr static const char *const label = N_("Time Zone Minute Offset"); + + constexpr static const char *str_0min = N_("00 min"); + constexpr static const char *str_30min = N_("30 min"); + constexpr static const char *str_45min = N_("45 min"); + +public: + MI_TIMEZONE_MIN(); + virtual void OnChange(size_t old_index) override; +}; + +class MI_TIMEZONE_SUMMER : public WI_SWITCH_t<2> { + constexpr static const char *const label = N_("Time Zone Summertime"); + + constexpr static const char *str_wintertime = N_("disabled"); + constexpr static const char *str_summertime = N_("enabled"); + +public: + MI_TIMEZONE_SUMMER(); + virtual void OnChange(size_t old_index) override; +}; + class MI_TIME_FORMAT : public WI_SWITCH_t<2> { constexpr static const char *const label = N_("Time Format"); diff --git a/src/gui/print_time_module.cpp b/src/gui/print_time_module.cpp index daf41855d1..d3ed0a789b 100644 --- a/src/gui/print_time_module.cpp +++ b/src/gui/print_time_module.cpp @@ -45,7 +45,9 @@ PT_t PrintTime::update_loop(PT_t screen_format, window_text_t *out_print_end, [[ // Timestamp const int8_t timezone_diff = config_store().timezone.get(); - const time_t local_cur_sec = curr_sec + timezone_diff * 3600; + const int8_t timezone_summertime = time_tools::get_current_timezone_summertime(); + const int8_t timezone_min_diff = time_tools::get_current_timezone_minutes(); + const time_t local_cur_sec = curr_sec + ((timezone_diff + timezone_summertime) * 3600) + (timezone_min_diff * 60); time_end_format = PT_t::timestamp; generate_timestamp_string(local_cur_sec, time_to_end); @@ -119,7 +121,9 @@ bool PrintTime::print_end_time(const uint32_t time_to_end, std::span buffe } const int8_t timezone_diff = config_store().timezone.get(); - curr_sec += timezone_diff * 3600; + const int8_t timezone_summertime = time_tools::get_current_timezone_summertime(); + const int8_t timezone_min_diff = time_tools::get_current_timezone_minutes(); + curr_sec += ((timezone_diff + timezone_summertime) * 3600) + (timezone_min_diff * 60); print_timestamp_string_to_buffer(curr_sec, time_to_end, buffer); return true; diff --git a/src/gui/screen_menu_lang_and_time.hpp b/src/gui/screen_menu_lang_and_time.hpp index fcf9a4b21a..c9b2353bc1 100644 --- a/src/gui/screen_menu_lang_and_time.hpp +++ b/src/gui/screen_menu_lang_and_time.hpp @@ -10,7 +10,7 @@ #include "MItem_menus.hpp" #include "menu_items_languages.hpp" -using ScreenMenuLangAndTime__ = ScreenMenu net_hostname { LAN_HOSTNAME_DEF }; inline constexpr int8_t lan_timezone { 1 }; + inline constexpr time_tools::TimeOffsetMinutes timezone_minutes { time_tools::TimeOffsetMinutes::_0min }; + inline constexpr time_tools::TimeOffsetSummerTime timezone_summer { time_tools::TimeOffsetSummerTime::_wintertime }; inline constexpr std::array wifi_ap_ssid { "" }; inline constexpr std::array wifi_ap_password { "" }; diff --git a/src/persistent_stores/store_instances/config_store/store_definition.hpp b/src/persistent_stores/store_instances/config_store/store_definition.hpp index ad3adc992f..4db974a99f 100644 --- a/src/persistent_stores/store_instances/config_store/store_definition.hpp +++ b/src/persistent_stores/store_instances/config_store/store_definition.hpp @@ -61,6 +61,8 @@ struct CurrentStore : public journal::CurrentStoreConfig, defaults::net_hostname, journal::hash("LAN Hostname")> lan_hostname; StoreItem timezone; // hour difference from UTC + StoreItem timezone_minutes; // minutes offset for hour difference from UTC + StoreItem timezone_summer; // Summertime hour offset // WIFI settings // wifi_flag & 1 -> On = 0/off = 1, lan_flag & 2 -> dhcp = 0/static = 1, wifi_flag & 0b1100 -> reserved, previously ap_sec_t security