Merge pull request #4537 from lioncash/tz

common/time_zone: Simplify GetOsTimeZoneOffset()
This commit is contained in:
bunnei 2020-08-17 14:27:02 -04:00 committed by GitHub
commit 0c885249df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,8 +3,9 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <chrono> #include <chrono>
#include <iomanip> #include <ctime>
#include <sstream>
#include <fmt/chrono.h>
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/time_zone.h" #include "common/time_zone.h"
@ -16,13 +17,8 @@ std::string GetDefaultTimeZone() {
} }
static std::string GetOsTimeZoneOffset() { static std::string GetOsTimeZoneOffset() {
const std::time_t t{std::time(nullptr)}; // Get the current timezone offset, e.g. "-400", as a string
const std::tm tm{*std::localtime(&t)}; return fmt::format("%z", fmt::localtime(std::time(nullptr)));
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) { static int ConvertOsTimeZoneOffsetToInt(const std::string& timezone) {