From acbae572d32b80fd90c9a3465cc88fd72a51f36a Mon Sep 17 00:00:00 2001 From: bunnei Date: Wed, 19 Aug 2020 18:27:31 -0400 Subject: [PATCH] Revert "common/time_zone: Simplify GetOsTimeZoneOffset()" --- src/common/time_zone.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common/time_zone.cpp b/src/common/time_zone.cpp index 7aa1b59ea..ce239eb63 100644 --- a/src/common/time_zone.cpp +++ b/src/common/time_zone.cpp @@ -3,9 +3,8 @@ // Refer to the license.txt file included. #include -#include - -#include +#include +#include #include "common/logging/log.h" #include "common/time_zone.h" @@ -17,8 +16,13 @@ std::string GetDefaultTimeZone() { } static std::string GetOsTimeZoneOffset() { - // Get the current timezone offset, e.g. "-400", as a string - return fmt::format("%z", fmt::localtime(std::time(nullptr))); + const std::time_t t{std::time(nullptr)}; + const std::tm tm{*std::localtime(&t)}; + + std::stringstream ss; + ss << std::put_time(&tm, "%z"); // Get the current timezone offset, e.g. "-400", as a string + + return ss.str(); } static int ConvertOsTimeZoneOffsetToInt(const std::string& timezone) {