summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/time_zone.cpp14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/common/time_zone.cpp b/src/common/time_zone.cpp
index ce239eb63..7aa1b59ea 100644
--- a/src/common/time_zone.cpp
+++ b/src/common/time_zone.cpp
@@ -3,8 +3,9 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <chrono> 5#include <chrono>
6#include <iomanip> 6#include <ctime>
7#include <sstream> 7
8#include <fmt/chrono.h>
8 9
9#include "common/logging/log.h" 10#include "common/logging/log.h"
10#include "common/time_zone.h" 11#include "common/time_zone.h"
@@ -16,13 +17,8 @@ std::string GetDefaultTimeZone() {
16} 17}
17 18
18static std::string GetOsTimeZoneOffset() { 19static std::string GetOsTimeZoneOffset() {
19 const std::time_t t{std::time(nullptr)}; 20 // Get the current timezone offset, e.g. "-400", as a string
20 const std::tm tm{*std::localtime(&t)}; 21 return fmt::format("%z", fmt::localtime(std::time(nullptr)));
21
22 std::stringstream ss;
23 ss << std::put_time(&tm, "%z"); // Get the current timezone offset, e.g. "-400", as a string
24
25 return ss.str();
26} 22}
27 23
28static int ConvertOsTimeZoneOffsetToInt(const std::string& timezone) { 24static int ConvertOsTimeZoneOffsetToInt(const std::string& timezone) {