M module-apps/application-settings/windows/system/ChangeTimeZone.cpp => module-apps/application-settings/windows/system/ChangeTimeZone.cpp +24 -2
@@ 11,15 11,37 @@
#include <service-time/service-time/TimeMessage.hpp>
#include <time/TimeZone.hpp>
+#include <algorithm>
+
namespace gui
{
+ namespace
+ {
+ constexpr auto NegativeOffsetPrefix = "UTC-";
+ } // namespace
+
ChangeTimeZone::ChangeTimeZone(app::ApplicationCommon *app)
- : BaseSettingsWindow(app, window::name::change_date_and_time),
- timeZonesList(utils::time::getAvailableTimeZonesWithOffset())
+ : BaseSettingsWindow(app, window::name::change_date_and_time), timeZonesList(sortTimeZones(getTimeZones()))
{
setTitle(utils::translate("app_settings_date_and_time_time_zone"));
}
+ auto ChangeTimeZone::getTimeZones() -> std::vector<std::string>
+ {
+ return utils::time::getAvailableTimeZonesWithOffset();
+ }
+
+ auto ChangeTimeZone::sortTimeZones(std::vector<std::string> &&timeZones) -> std::vector<std::string>
+ {
+ std::vector<std::string> zones = std::move(timeZones);
+ auto pivot = std::partition(zones.begin(), zones.end(), [](const auto &tz) {
+ return tz.rfind(NegativeOffsetPrefix, 0) == 0; // starts with NegativeOffsetPrefix
+ });
+ std::sort(zones.begin(), pivot, std::greater<std::string>{});
+ std::sort(pivot, zones.end());
+ return zones;
+ }
+
void ChangeTimeZone::onBeforeShow(ShowMode mode, SwitchData *data)
{
selectedTimeZone = stm::api::getCurrentTimezoneName();
M module-apps/application-settings/windows/system/ChangeTimeZone.hpp => module-apps/application-settings/windows/system/ChangeTimeZone.hpp +4 -1
@@ 13,12 13,15 @@ namespace gui
public:
explicit ChangeTimeZone(app::ApplicationCommon *app);
- protected:
+ private:
[[nodiscard]] auto buildOptionsList() -> std::list<Option> override;
void onBeforeShow(ShowMode mode, SwitchData *data) override;
[[nodiscard]] auto setTimeZoneIndex() -> unsigned int;
[[nodiscard]] auto extractTimeZoneName(const std::string &name) const noexcept -> std::string;
+ [[nodiscard]] static auto getTimeZones() -> std::vector<std::string>;
+ [[nodiscard]] static auto sortTimeZones(std::vector<std::string> &&timeZones) -> std::vector<std::string>;
+
const std::vector<std::string> timeZonesList;
std::string selectedTimeZone;
};
M module-utils/time/time/TimeZone.cpp => module-utils/time/time/TimeZone.cpp +2 -0
@@ 54,6 54,8 @@ namespace utils::time
[[nodiscard]] auto getAvailableTimeZonesWithOffset() -> std::vector<std::string>
{
std::vector<std::string> timeZonesNames;
+ timeZonesNames.reserve(NUM_ZONE_NAMES);
+
char zoneToDisplay[maxZoneToDisplayLength];
auto zonePointer = reinterpret_cast<const char *>(zone_names);
uzone_t zoneOut;