diff options
author | qrort <qrort@yandex-team.com> | 2022-12-02 11:31:25 +0300 |
---|---|---|
committer | qrort <qrort@yandex-team.com> | 2022-12-02 11:31:25 +0300 |
commit | b1f4ffc9c8abff3ba58dc1ec9a9f92d2f0de6806 (patch) | |
tree | 2a23209faf0fea5586a6d4b9cee60d1b318d29fe /library/cpp/eventlog/dumper/common.cpp | |
parent | 559174a9144de40d6bb3997ea4073c82289b4974 (diff) | |
download | ydb-b1f4ffc9c8abff3ba58dc1ec9a9f92d2f0de6806.tar.gz |
remove kikimr/driver DEPENDS
Diffstat (limited to 'library/cpp/eventlog/dumper/common.cpp')
-rw-r--r-- | library/cpp/eventlog/dumper/common.cpp | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/library/cpp/eventlog/dumper/common.cpp b/library/cpp/eventlog/dumper/common.cpp deleted file mode 100644 index eebe3b6ee33..00000000000 --- a/library/cpp/eventlog/dumper/common.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include "common.h" - -#include <contrib/libs/re2/re2/re2.h> - -#include <util/datetime/base.h> -#include <util/datetime/parser.h> -#include <util/string/cast.h> - -static time_t RecentTime(int h, int m, int s) { - time_t now = time(nullptr); - tm tmTmp; - localtime_r(&now, &tmTmp); - tmTmp.tm_hour = h; - tmTmp.tm_min = m; - tmTmp.tm_sec = s; - time_t today = mktime(&tmTmp); - tmTmp.tm_mday -= 1; - time_t yesterday = mktime(&tmTmp); - return today <= now ? today : yesterday; -} - -static bool ParseRecentTime(const TString& str, time_t& result) { - RE2 RecentTimePattern("(\\d{1,2}):(\\d{2})(?::(\\d{2}))?"); - re2::StringPiece hStr, mStr, sStr; - if (!RE2::FullMatch({str.data(), str.size()}, RecentTimePattern, &hStr, &mStr, &sStr)) { - return false; - } - int h = FromString<int>(hStr.data(), hStr.length()); - int m = FromString<int>(mStr.data(), mStr.length()); - int s = FromString<int>(sStr.data(), sStr.length(), 0); - if (h > 23 || m > 59 || s > 59) { - return false; - } - result = RecentTime(h, m, s); - return true; -} - -namespace { - class TDefaultOffset8601Parser: public TIso8601DateTimeParser { - public: - TDefaultOffset8601Parser(int offsetHours) { - DateTimeFields.ZoneOffsetMinutes = offsetHours * 60; - } - }; -} // namespace - -static bool ParseISO8601DateTimeWithDefaultOffset(TStringBuf str, int offsetHours, time_t& result) { - TDefaultOffset8601Parser parser{offsetHours}; - - if (!parser.ParsePart(str.data(), str.size())) { - return false; - } - - const TInstant instant = parser.GetResult(TInstant::Max()); - if (instant == TInstant::Max()) { - return false; - } - - result = instant.TimeT(); - return true; -} - -ui64 ParseTime(const TString& str, ui64 defValue, int offset) { - if (!str) { - return defValue; - } - - time_t utcTime; - - if (ParseISO8601DateTimeWithDefaultOffset(str, offset, utcTime)) { - return (ui64)utcTime * 1000000; - } - - if (ParseRecentTime(str, utcTime)) { - return (ui64)utcTime * 1000000; - } - - // if conversion fails, TryFromString leaves defValue unchanged - TryFromString<ui64>(str, defValue); - return defValue; -} |