diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-03-13 10:33:47 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-03-13 10:33:47 +0000 |
commit | 1df54be5538361db7f33afc618d1597272414294 (patch) | |
tree | bb39e4b75db0b0a9722468eacef91ffd1388eb8d /library/cpp | |
parent | 7a673cf01feefbe95bf5e7396d9179a5f283aeba (diff) | |
parent | 01aef806626b16e9817e07f718f10e151f52e400 (diff) | |
download | ydb-1df54be5538361db7f33afc618d1597272414294.tar.gz |
Merge branch 'rightlib' into mergelibs-240313-1032
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/timezone_conversion/civil.cpp | 19 | ||||
-rw-r--r-- | library/cpp/yt/misc/cast-inl.h | 14 |
2 files changed, 24 insertions, 9 deletions
diff --git a/library/cpp/timezone_conversion/civil.cpp b/library/cpp/timezone_conversion/civil.cpp index 0a9b6acaa6f..fe8d10bfc54 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; diff --git a/library/cpp/yt/misc/cast-inl.h b/library/cpp/yt/misc/cast-inl.h index ceacda91bd6..59be41ac1cf 100644 --- a/library/cpp/yt/misc/cast-inl.h +++ b/library/cpp/yt/misc/cast-inl.h @@ -9,7 +9,6 @@ #include <util/string/cast.h> #include <util/string/printf.h> -#include <concepts> #include <type_traits> namespace NYT { @@ -78,6 +77,8 @@ inline TString FormatInvalidCastValue(char8_t value) } // namespace NDetail +//////////////////////////////////////////////////////////////////////////////// + template <class T, class S> bool TryIntegralCast(S value, T* result) { @@ -93,8 +94,12 @@ T CheckedIntegralCast(S value) { T result; if (!TryIntegralCast<T>(value, &result)) { - throw TSimpleException(Sprintf("Argument value %s is out of expected range", - NYT::NDetail::FormatInvalidCastValue(value).c_str())); + throw TSimpleException(Sprintf("Error casting %s value \"%s\" to %s: value is out of expected range [%s; %s]", + TypeName<S>().c_str(), + NYT::NDetail::FormatInvalidCastValue(value).c_str(), + TypeName<T>().c_str(), + ::ToString(std::numeric_limits<T>::min()).c_str(), + ::ToString(std::numeric_limits<T>::max()).c_str())); } return result; } @@ -119,7 +124,8 @@ T CheckedEnumCast(S value) { T result; if (!TryEnumCast<T>(value, &result)) { - throw TSimpleException(Sprintf("Invalid value %d of enum type %s", + throw TSimpleException(Sprintf("Error casting %s value \"%d\" to enum %s", + TypeName<S>().c_str(), static_cast<int>(value), TEnumTraits<T>::GetTypeName().data())); } |