mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-03 10:19:59 +00:00
common/time_zone: Simplify GetOsTimeZoneOffset()
We can simplify this function down into a single line with the use of fmt. A benefit with the fmt approach is that the fmt variant of localtime is thread-safe as well, making GetOsTimeZoneOffset() thread-safe as well.
This commit is contained in:
parent
db96034ea4
commit
fe97d34156
1 changed files with 5 additions and 9 deletions
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue