diff options
author | d-dima <d-dima@yandex-team.com> | 2024-03-12 14:21:35 +0300 |
---|---|---|
committer | d-dima <d-dima@yandex-team.com> | 2024-03-12 14:41:41 +0300 |
commit | e98c636d759bf6f106a2b90142041bb9d4f1e33f (patch) | |
tree | e100425e8bbdf4bec72855b41ee7ea37a2d392ec | |
parent | e8fb59b11b5486102d179d32155d304b45c26562 (diff) | |
download | ydb-e98c636d759bf6f106a2b90142041bb9d4f1e33f.tar.gz |
Make "GMT+03:00" known timezone format
cd2e9b766cd6579b0124ffe05b23a22513e19a93
-rw-r--r-- | library/cpp/timezone_conversion/civil.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/library/cpp/timezone_conversion/civil.cpp b/library/cpp/timezone_conversion/civil.cpp index 0a9b6acaa6..fe8d10bfc5 100644 --- a/library/cpp/timezone_conversion/civil.cpp +++ b/library/cpp/timezone_conversion/civil.cpp @@ -20,10 +20,15 @@ namespace { return true; } - bool TryParseUTCOffsetTimezone(TStringBuf name, int& offset) { - static constexpr TStringBuf OFFSET_PREFIX = "UTC"; - if (!name.SkipPrefix(OFFSET_PREFIX)) { - return false; + bool TryParseUTCGMTOffsetTimezone(TStringBuf name, int& offset) { + static constexpr TStringBuf OFFSET_PREFIX_UTC = "UTC"; + static constexpr TStringBuf OFFSET_PREFIX_GMT = "GMT"; + if (!name.SkipPrefix(OFFSET_PREFIX_UTC)) { + // Sometimes timezones from client devices look like 'GMT+03:00' + // This format is not standard but can be translated like UTC+xxx + if (!name.SkipPrefix(OFFSET_PREFIX_GMT)) { + return false; + } } return NDatetime::TryParseOffset(name, offset); } @@ -70,7 +75,11 @@ namespace NDatetime { TTimeZone GetTimeZone(TStringBuf name) { int offset; - if (TryParseUTCOffsetTimezone(name, offset)) { + // Try to preparse constant timezones like: + // UTC+03:00 + // GMT+03:00 + // Note constant timezones like 'Etc-03' will be handed in cctz library + if (TryParseUTCGMTOffsetTimezone(name, offset)) { return GetFixedTimeZone(offset); } TTimeZone result; |