diff options
author | barricade <barricade@yandex-team.ru> | 2022-02-10 16:49:32 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:32 +0300 |
commit | 4e57e39ab016cac0037c9ed5f9e5c351bbd238d6 (patch) | |
tree | 2cfe0a4abe9e132a0562fbae5557c486fe905379 /library/cpp/timezone_conversion/civil.cpp | |
parent | 45bb4d590636539e023f206c8c1724c6388355ba (diff) | |
download | ydb-4e57e39ab016cac0037c9ed5f9e5c351bbd238d6.tar.gz |
Restoring authorship annotation for <barricade@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/timezone_conversion/civil.cpp')
-rw-r--r-- | library/cpp/timezone_conversion/civil.cpp | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/library/cpp/timezone_conversion/civil.cpp b/library/cpp/timezone_conversion/civil.cpp index 5986318b9a..caab115186 100644 --- a/library/cpp/timezone_conversion/civil.cpp +++ b/library/cpp/timezone_conversion/civil.cpp @@ -2,73 +2,73 @@ #include <util/stream/output.h> #include <util/stream/format.h> -#include <util/string/ascii.h> - -namespace { - bool TryParseInt(TStringBuf& s, int& dst, size_t maxDigits) { - int res = 0; - size_t i = 0; - while (i < maxDigits && !s.empty() && IsAsciiDigit(s[0])) { - res = res * 10 + (s[0] - '0'); - ++i; - s.Skip(1); - } - if (i == 0) { - return false; - } - dst = res; - return true; - } - +#include <util/string/ascii.h> + +namespace { + bool TryParseInt(TStringBuf& s, int& dst, size_t maxDigits) { + int res = 0; + size_t i = 0; + while (i < maxDigits && !s.empty() && IsAsciiDigit(s[0])) { + res = res * 10 + (s[0] - '0'); + ++i; + s.Skip(1); + } + if (i == 0) { + return false; + } + dst = res; + return true; + } + bool TryParseUTCOffsetTimezone(TStringBuf name, int& offset) { - static constexpr TStringBuf OFFSET_PREFIX = "UTC"; - if (!name.SkipPrefix(OFFSET_PREFIX)) { - return false; - } - if (name.empty()) { - return false; - } - bool negative; - if (name[0] == '+') { - negative = false; - } else if (name[0] == '-') { - negative = true; - } else { - return false; - } - name.Skip(1); - int hour; - int minute = 0; - if (!TryParseInt(name, hour, 2) || hour > 24) { - return false; - } - if (!name.empty()) { - if (name[0] == ':') { - name.Skip(1); - } - if (!TryParseInt(name, minute, 2) || minute >= 60) { - return false; - } - if (!name.empty()) { - return false; - } - } - if (hour == 24 && minute != 0) { - return false; - } - offset = (hour * 60 + minute) * 60; - if (negative) - offset = -offset; - return true; - } -} // anonymous namespace - + static constexpr TStringBuf OFFSET_PREFIX = "UTC"; + if (!name.SkipPrefix(OFFSET_PREFIX)) { + return false; + } + if (name.empty()) { + return false; + } + bool negative; + if (name[0] == '+') { + negative = false; + } else if (name[0] == '-') { + negative = true; + } else { + return false; + } + name.Skip(1); + int hour; + int minute = 0; + if (!TryParseInt(name, hour, 2) || hour > 24) { + return false; + } + if (!name.empty()) { + if (name[0] == ':') { + name.Skip(1); + } + if (!TryParseInt(name, minute, 2) || minute >= 60) { + return false; + } + if (!name.empty()) { + return false; + } + } + if (hour == 24 && minute != 0) { + return false; + } + offset = (hour * 60 + minute) * 60; + if (negative) + offset = -offset; + return true; + } +} // anonymous namespace + namespace NDatetime { TTimeZone GetTimeZone(TStringBuf name) { - int offset; - if (TryParseUTCOffsetTimezone(name, offset)) { - return GetFixedTimeZone(offset); - } + int offset; + if (TryParseUTCOffsetTimezone(name, offset)) { + return GetFixedTimeZone(offset); + } TTimeZone result; if (!cctz::load_time_zone(static_cast<std::string>(name), &result)) { ythrow TInvalidTimezone() << "Failed to load time zone " << name << ", " << result.name(); |