diff options
Diffstat (limited to 'src/common/Time/Timezone.cpp')
-rw-r--r-- | src/common/Time/Timezone.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/common/Time/Timezone.cpp b/src/common/Time/Timezone.cpp index 5cd80d03232..6c9e58e0c93 100644 --- a/src/common/Time/Timezone.cpp +++ b/src/common/Time/Timezone.cpp @@ -17,13 +17,19 @@ #include "Timezone.h" #include "Hash.h" -#include "Locales.h" #include "MapUtils.h" +#include "Tuples.h" +#include <algorithm> +#include <unordered_map> + +#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS #include "StringConvert.h" +#else +#include "Locales.h" +#include "Util.h" #include <boost/locale/date_time_facet.hpp> -#include <chrono> #include <memory> -#include <unordered_map> +#endif namespace { @@ -163,20 +169,13 @@ std::string GetSystemZoneName() std::string_view FindClosestClientSupportedTimezone(std::string_view currentTimezone, Minutes currentTimezoneOffset) { // try exact match - auto itr = std::find_if(_clientSupportedTimezones.begin(), _clientSupportedTimezones.end(), [currentTimezone](ClientSupportedTimezone const& tz) - { - return tz.second == currentTimezone; - }); + auto itr = std::ranges::find(_clientSupportedTimezones, currentTimezone, Trinity::TupleElement<1>); if (itr != _clientSupportedTimezones.end()) return itr->second; // try closest offset - itr = std::min_element(_clientSupportedTimezones.begin(), _clientSupportedTimezones.end(), [currentTimezoneOffset](ClientSupportedTimezone const& left, ClientSupportedTimezone const& right) - { - Minutes leftDiff = left.first - currentTimezoneOffset; - Minutes rightDiff = right.first - currentTimezoneOffset; - return std::abs(leftDiff.count()) < std::abs(rightDiff.count()); - }); + itr = std::ranges::min_element(_clientSupportedTimezones, std::ranges::less(), + [currentTimezoneOffset](ClientSupportedTimezone const& ctz) { return std::chrono::abs(ctz.first - currentTimezoneOffset); }); return itr->second; } |