aboutsummaryrefslogtreecommitdiffstats
path: root/util/datetime
diff options
context:
space:
mode:
authoryazevnul <yazevnul@yandex-team.ru>2022-02-10 16:46:48 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:48 +0300
commit9abfb1a53b7f7b791444d1378e645d8fad9b06ed (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /util/datetime
parent8cbc307de0221f84c80c42dcbe07d40727537e2c (diff)
downloadydb-9abfb1a53b7f7b791444d1378e645d8fad9b06ed.tar.gz
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/datetime')
-rw-r--r--util/datetime/base.cpp18
-rw-r--r--util/datetime/base.h108
-rw-r--r--util/datetime/base_ut.cpp40
-rw-r--r--util/datetime/cputimer.cpp12
-rw-r--r--util/datetime/cputimer.h4
-rw-r--r--util/datetime/parser.rl692
-rw-r--r--util/datetime/parser_ut.cpp94
7 files changed, 184 insertions, 184 deletions
diff --git a/util/datetime/base.cpp b/util/datetime/base.cpp
index 39c49b7133..38ecc3ab96 100644
--- a/util/datetime/base.cpp
+++ b/util/datetime/base.cpp
@@ -42,7 +42,7 @@ namespace {
return {i};
}
- inline IOutputStream& operator<<(IOutputStream& o, const TPad<2>& p) {
+ inline IOutputStream& operator<<(IOutputStream& o, const TPad<2>& p) {
if (p.I < 10) {
if (p.I >= 0) {
o << '0';
@@ -52,7 +52,7 @@ namespace {
return o << p.I;
}
- inline IOutputStream& operator<<(IOutputStream& o, const TPad<4>& p) {
+ inline IOutputStream& operator<<(IOutputStream& o, const TPad<4>& p) {
if (p.I < 1000) {
if (p.I >= 0) {
if (p.I < 10) {
@@ -68,7 +68,7 @@ namespace {
return o << p.I;
}
- inline IOutputStream& operator<<(IOutputStream& o, const TPad<6>& p) {
+ inline IOutputStream& operator<<(IOutputStream& o, const TPad<6>& p) {
if (p.I < 100000) {
if (p.I >= 0) {
if (p.I < 10) {
@@ -88,11 +88,11 @@ namespace {
return o << p.I;
}
- void WriteMicroSecondsToStream(IOutputStream& os, ui32 microSeconds) {
+ void WriteMicroSecondsToStream(IOutputStream& os, ui32 microSeconds) {
os << '.' << Pad<6>(microSeconds);
}
- void WriteTmToStream(IOutputStream& os, const struct tm& theTm) {
+ void WriteTmToStream(IOutputStream& os, const struct tm& theTm) {
os << Pad<4>(theTm.tm_year + 1900) << '-' << Pad<2>(theTm.tm_mon + 1) << '-' << Pad<2>(theTm.tm_mday) << 'T'
<< Pad<2>(theTm.tm_hour) << ':' << Pad<2>(theTm.tm_min) << ':' << Pad<2>(theTm.tm_sec);
}
@@ -134,20 +134,20 @@ namespace {
}
template <>
-void Out<TDuration>(IOutputStream& os, TTypeTraits<TDuration>::TFuncParam duration) {
+void Out<TDuration>(IOutputStream& os, TTypeTraits<TDuration>::TFuncParam duration) {
os << duration.Seconds();
WriteMicroSecondsToStream(os, duration.MicroSecondsOfSecond());
os << 's';
}
template <>
-void Out<TInstant>(IOutputStream& os, TTypeTraits<TInstant>::TFuncParam instant) {
+void Out<TInstant>(IOutputStream& os, TTypeTraits<TInstant>::TFuncParam instant) {
char buf[64];
auto len = FormatDate8601(buf, sizeof(buf), instant.TimeT());
-
+
// shouldn't happen due to current implementation of FormatDate8601() and GmTimeR()
Y_ENSURE(len, TStringBuf("Out<TInstant>: year does not fit into an integer"));
-
+
os.Write(buf, len - 1 /* 'Z' */);
WriteMicroSecondsToStream(os, instant.MicroSecondsOfSecond());
os << 'Z';
diff --git a/util/datetime/base.h b/util/datetime/base.h
index 11666de71e..5e902b8f63 100644
--- a/util/datetime/base.h
+++ b/util/datetime/base.h
@@ -49,7 +49,7 @@ constexpr long seconds(const struct tm& theTm) {
return 60 * (60 * theTm.tm_hour + theTm.tm_min) + theTm.tm_sec;
}
-void sprint_gm_date(char* buf, time_t when, long* sec = nullptr);
+void sprint_gm_date(char* buf, time_t when, long* sec = nullptr);
bool sscan_date(const char* date, struct tm& theTm);
const int DATE_8601_LEN = 21; // strlen("YYYY-MM-DDThh:mm:ssZ") = 20 + '\0'
@@ -120,7 +120,7 @@ public:
}
constexpr double SecondsFloat() const noexcept {
- return Value_ * (1 / 1000000.0);
+ return Value_ * (1 / 1000000.0);
}
constexpr double MillisecondsFloat() const noexcept {
@@ -152,7 +152,7 @@ public:
}
constexpr TValue NanoSeconds() const noexcept {
- return MicroSeconds() >= (Max<TValue>() / (TValue)1000) ? Max<TValue>() : MicroSeconds() * (TValue)1000;
+ return MicroSeconds() >= (Max<TValue>() / (TValue)1000) ? Max<TValue>() : MicroSeconds() * (TValue)1000;
}
constexpr ui32 MicroSecondsOfSecond() const noexcept {
@@ -308,11 +308,11 @@ public:
}
/// parses strings like 10s, 15ms, 15.05s, 20us, or just 25 (s). See parser_ut.cpp for details
- static TDuration Parse(const TStringBuf input);
+ static TDuration Parse(const TStringBuf input);
- static bool TryParse(const TStringBuf input, TDuration& result);
+ static bool TryParse(const TStringBuf input, TDuration& result);
- // note global Out method is defined for TDuration, so it could be written to IOutputStream as text
+ // note global Out method is defined for TDuration, so it could be written to IOutputStream as text
template <class T>
inline TDuration& operator+=(const T& t) noexcept {
@@ -337,7 +337,7 @@ public:
TString ToString() const;
};
-Y_DECLARE_PODTYPE(TDuration);
+Y_DECLARE_PODTYPE(TDuration);
template <>
struct THash<TDuration> {
@@ -447,7 +447,7 @@ public:
* Formats the instant using the UTC time zone, with microsecond precision.
*
* @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27.991669Z'.
- * @note Global Out method is defined to TInstant, so it can be written as text to IOutputStream.
+ * @note Global Out method is defined to TInstant, so it can be written as text to IOutputStream.
*/
TString ToString() const;
@@ -507,45 +507,45 @@ public:
TString FormatLocalTime(const char* format) const noexcept;
TString FormatGmTime(const char* format) const noexcept;
- /// See #TryParseIso8601.
- static TInstant ParseIso8601(TStringBuf);
- /// See #TryParseRfc822.
+ /// See #TryParseIso8601.
+ static TInstant ParseIso8601(TStringBuf);
+ /// See #TryParseRfc822.
static TInstant ParseRfc822(TStringBuf);
- /// See #TryParseHttp.
- static TInstant ParseHttp(TStringBuf);
- /// See #TryParseX509.
- static TInstant ParseX509Validity(TStringBuf);
-
- /// ISO 8601 Representation of Dates and Times
- ///
- /// @link https://www.iso.org/standard/40874.html Description of format.
- static bool TryParseIso8601(TStringBuf input, TInstant& instant);
-
- /// RFC 822 Date and Time specification
- ///
- /// @link https://tools.ietf.org/html/rfc822#section-5 Description of format.
- static bool TryParseRfc822(TStringBuf input, TInstant& instant);
-
- /// RFC 2616 3.3.1 Full Date
- ///
- /// @link https://tools.ietf.org/html/rfc2616#section-3.3.1 Description of format.
- static bool TryParseHttp(TStringBuf input, TInstant& instant);
-
- /// X.509 certificate validity time (see rfc5280 4.1.2.5.*)
- ///
- /// @link https://tools.ietf.org/html/rfc5280#section-4.1.2.5 Description of format.
- static bool TryParseX509(TStringBuf input, TInstant& instant);
-
- static TInstant ParseIso8601Deprecated(TStringBuf);
- static TInstant ParseRfc822Deprecated(TStringBuf);
- static TInstant ParseHttpDeprecated(TStringBuf);
- static TInstant ParseX509ValidityDeprecated(TStringBuf);
-
- static bool TryParseIso8601Deprecated(TStringBuf input, TInstant& instant);
- static bool TryParseRfc822Deprecated(TStringBuf input, TInstant& instant);
- static bool TryParseHttpDeprecated(TStringBuf input, TInstant& instant);
- static bool TryParseX509Deprecated(TStringBuf input, TInstant& instant);
-
+ /// See #TryParseHttp.
+ static TInstant ParseHttp(TStringBuf);
+ /// See #TryParseX509.
+ static TInstant ParseX509Validity(TStringBuf);
+
+ /// ISO 8601 Representation of Dates and Times
+ ///
+ /// @link https://www.iso.org/standard/40874.html Description of format.
+ static bool TryParseIso8601(TStringBuf input, TInstant& instant);
+
+ /// RFC 822 Date and Time specification
+ ///
+ /// @link https://tools.ietf.org/html/rfc822#section-5 Description of format.
+ static bool TryParseRfc822(TStringBuf input, TInstant& instant);
+
+ /// RFC 2616 3.3.1 Full Date
+ ///
+ /// @link https://tools.ietf.org/html/rfc2616#section-3.3.1 Description of format.
+ static bool TryParseHttp(TStringBuf input, TInstant& instant);
+
+ /// X.509 certificate validity time (see rfc5280 4.1.2.5.*)
+ ///
+ /// @link https://tools.ietf.org/html/rfc5280#section-4.1.2.5 Description of format.
+ static bool TryParseX509(TStringBuf input, TInstant& instant);
+
+ static TInstant ParseIso8601Deprecated(TStringBuf);
+ static TInstant ParseRfc822Deprecated(TStringBuf);
+ static TInstant ParseHttpDeprecated(TStringBuf);
+ static TInstant ParseX509ValidityDeprecated(TStringBuf);
+
+ static bool TryParseIso8601Deprecated(TStringBuf input, TInstant& instant);
+ static bool TryParseRfc822Deprecated(TStringBuf input, TInstant& instant);
+ static bool TryParseHttpDeprecated(TStringBuf input, TInstant& instant);
+ static bool TryParseX509Deprecated(TStringBuf input, TInstant& instant);
+
template <class T>
inline TInstant& operator+=(const T& t) noexcept {
return (*this = (*this + t));
@@ -557,7 +557,7 @@ public:
}
};
-Y_DECLARE_PODTYPE(TInstant);
+Y_DECLARE_PODTYPE(TInstant);
template <>
struct THash<TInstant> {
@@ -578,9 +578,9 @@ namespace NPrivate {
};
}
-/** @name Helpers for printing local times to `IOutputStream`s.
+/** @name Helpers for printing local times to `IOutputStream`s.
* The FormatLocal* functions create an opaque object that, when written to
- * a `IOutputStream`, outputs this instant as an ISO 8601 formatted string
+ * a `IOutputStream`, outputs this instant as an ISO 8601 formatted string
* using the system time zone.
*
* @note The only reason behind this set of functions is to avoid excessive
@@ -634,14 +634,14 @@ static constexpr bool operator>=(const TTimeBase<S>& l, const TTimeBase<S>& r) n
namespace NDateTimeHelpers {
template <typename T>
static constexpr T SumWithSaturation(T a, T b) {
- static_assert(!std::numeric_limits<T>::is_signed, "expect !std::numeric_limits<T>::is_signed");
+ static_assert(!std::numeric_limits<T>::is_signed, "expect !std::numeric_limits<T>::is_signed");
return Max<T>() - a < b ? Max<T>() : a + b;
}
template <typename T>
static constexpr T DiffWithSaturation(T a, T b) {
- static_assert(!std::numeric_limits<T>::is_signed, "expect !std::numeric_limits<T>::is_signed");
+ static_assert(!std::numeric_limits<T>::is_signed, "expect !std::numeric_limits<T>::is_signed");
return a < b ? 0 : a - b;
}
@@ -773,8 +773,8 @@ constexpr TInstant operator-(const TInstant& l, const std::chrono::duration<T, T
template <class T>
inline TDuration operator*(TDuration d, T t) noexcept {
- Y_ASSERT(t >= T());
- Y_ASSERT(t == T() || Max<TDuration::TValue>() / t >= d.GetValue());
+ Y_ASSERT(t >= T());
+ Y_ASSERT(t == T() || Max<TDuration::TValue>() / t >= d.GetValue());
return TDuration::FromValue(d.GetValue() * t);
}
@@ -794,7 +794,7 @@ inline TDuration operator*(T t, TDuration d) noexcept {
return d * t;
}
-template <class T, std::enable_if_t<!std::is_same<TDuration, T>::value, int> = 0>
+template <class T, std::enable_if_t<!std::is_same<TDuration, T>::value, int> = 0>
constexpr TDuration operator/(const TDuration& d, const T& t) noexcept {
return TDuration::FromValue(d.GetValue() / t);
}
diff --git a/util/datetime/base_ut.cpp b/util/datetime/base_ut.cpp
index 605bcfd452..afc3f802eb 100644
--- a/util/datetime/base_ut.cpp
+++ b/util/datetime/base_ut.cpp
@@ -47,8 +47,8 @@ namespace {
}
}
-Y_UNIT_TEST_SUITE(TestSprintDate) {
- Y_UNIT_TEST(Year9999) {
+Y_UNIT_TEST_SUITE(TestSprintDate) {
+ Y_UNIT_TEST(Year9999) {
struct tm t;
t.tm_year = 9999 - 1900;
t.tm_mday = 1;
@@ -61,7 +61,7 @@ Y_UNIT_TEST_SUITE(TestSprintDate) {
UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
}
- Y_UNIT_TEST(YearAfter9999) {
+ Y_UNIT_TEST(YearAfter9999) {
struct tm t;
t.tm_year = 123456 - 1900;
t.tm_mday = 1;
@@ -70,7 +70,7 @@ Y_UNIT_TEST_SUITE(TestSprintDate) {
char buf[DATE_BUF_LEN];
UNIT_ASSERT_EXCEPTION(DateToString(buf, t), yexception);
}
- Y_UNIT_TEST(SmallYear) {
+ Y_UNIT_TEST(SmallYear) {
struct tm t;
t.tm_year = 0 - 1900;
t.tm_mday = 1;
@@ -83,7 +83,7 @@ Y_UNIT_TEST_SUITE(TestSprintDate) {
UNIT_ASSERT_VALUES_EQUAL(expectedDate, ToString(buf));
}
- Y_UNIT_TEST(SmallYearAndMonth) {
+ Y_UNIT_TEST(SmallYearAndMonth) {
struct tm t;
t.tm_year = 99 - 1900;
t.tm_mday = 1;
@@ -338,18 +338,18 @@ Y_UNIT_TEST_SUITE(TDateTimeTest) {
}
}
-Y_UNIT_TEST_SUITE(DateTimeTest) {
- Y_UNIT_TEST(TestDurationFromFloat) {
+Y_UNIT_TEST_SUITE(DateTimeTest) {
+ Y_UNIT_TEST(TestDurationFromFloat) {
UNIT_ASSERT_EQUAL(TDuration::MilliSeconds(500), TDuration::Seconds(0.5));
UNIT_ASSERT_EQUAL(TDuration::MilliSeconds(500), TDuration::Seconds(0.5f));
}
- Y_UNIT_TEST(TestSecondsLargeValue) {
+ Y_UNIT_TEST(TestSecondsLargeValue) {
unsigned int seconds = UINT_MAX;
UNIT_ASSERT_VALUES_EQUAL(((ui64)seconds) * 1000000, TDuration::Seconds(seconds).MicroSeconds());
}
- Y_UNIT_TEST(TestToString) {
+ Y_UNIT_TEST(TestToString) {
#define CHECK_CONVERTIBLE(v) \
do { \
UNIT_ASSERT_VALUES_EQUAL(v, ToString(TDuration::Parse(v))); \
@@ -371,7 +371,7 @@ Y_UNIT_TEST_SUITE(DateTimeTest) {
CHECK_CONVERTIBLE("33.011122s");
}
- Y_UNIT_TEST(TestFromString) {
+ Y_UNIT_TEST(TestFromString) {
static const struct T {
const char* const Str;
const TDuration::TValue MicroSeconds;
@@ -384,7 +384,7 @@ Y_UNIT_TEST_SUITE(DateTimeTest) {
{"x3ms", 0, false},
};
- for (const T* t = tests; t != std::end(tests); ++t) {
+ for (const T* t = tests; t != std::end(tests); ++t) {
// FromString
bool parsed = false;
try {
@@ -403,14 +403,14 @@ Y_UNIT_TEST_SUITE(DateTimeTest) {
}
}
- Y_UNIT_TEST(TestSleep) {
+ Y_UNIT_TEST(TestSleep) {
// check does not throw
Sleep(TDuration::Seconds(0));
Sleep(TDuration::MicroSeconds(1));
Sleep(TDuration::MilliSeconds(1));
}
- Y_UNIT_TEST(TestInstantToString) {
+ Y_UNIT_TEST(TestInstantToString) {
UNIT_ASSERT_VALUES_EQUAL(TString("2009-08-06T15:19:06.023455Z"), ToString(TInstant::Seconds(1249571946) + TDuration::MicroSeconds(23455)));
UNIT_ASSERT_VALUES_EQUAL(TString("2009-08-06T15:19:06.023455Z"), (TInstant::Seconds(1249571946) + TDuration::MicroSeconds(23455)).ToString());
UNIT_ASSERT_VALUES_EQUAL(TString("2009-08-06T15:19:06Z"), (TInstant::Seconds(1249571946) + TDuration::MicroSeconds(23455)).ToStringUpToSeconds());
@@ -420,7 +420,7 @@ Y_UNIT_TEST_SUITE(DateTimeTest) {
UNIT_ASSERT_VALUES_EQUAL(TString("Thu, 06 Aug 2009 15:19:06 GMT"), (TInstant::Seconds(1249571946) + TDuration::MicroSeconds(23455)).ToRfc822String());
}
- Y_UNIT_TEST(TestInstantMath) {
+ Y_UNIT_TEST(TestInstantMath) {
UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(1719), TInstant::Seconds(1700) + TDuration::Seconds(19));
// overflow
UNIT_ASSERT_VALUES_EQUAL(TInstant::Max(), TInstant::Max() - TDuration::Seconds(10) + TDuration::Seconds(19));
@@ -429,7 +429,7 @@ Y_UNIT_TEST_SUITE(DateTimeTest) {
UNIT_ASSERT_VALUES_EQUAL(TDuration::Zero(), TInstant::Seconds(1000) - TInstant::Seconds(2000));
}
- Y_UNIT_TEST(TestDurationMath) {
+ Y_UNIT_TEST(TestDurationMath) {
TDuration empty;
UNIT_ASSERT(!empty);
// ensure that this compiles too
@@ -484,20 +484,20 @@ Y_UNIT_TEST_SUITE(DateTimeTest) {
UNIT_ASSERT_VALUES_EQUAL(onlyDays.Days(), days);
}
- Y_UNIT_TEST(TestInstantUnits) {
+ Y_UNIT_TEST(TestInstantUnits) {
TestTimeUnits<TInstant>();
}
- Y_UNIT_TEST(TestDurationUnits) {
+ Y_UNIT_TEST(TestDurationUnits) {
TestTimeUnits<TDuration>();
}
- Y_UNIT_TEST(TestNoexceptConstruction) {
+ Y_UNIT_TEST(TestNoexceptConstruction) {
UNIT_ASSERT_EXCEPTION(TDuration::MilliSeconds(FromString(TStringBuf("not a number"))), yexception);
UNIT_ASSERT_EXCEPTION(TDuration::Seconds(FromString(TStringBuf("not a number"))), yexception);
}
- Y_UNIT_TEST(TestFromValueForTDuration) {
+ Y_UNIT_TEST(TestFromValueForTDuration) {
// check that FromValue creates the same TDuration
TDuration d1 = TDuration::MicroSeconds(12345);
TDuration d2 = TDuration::FromValue(d1.GetValue());
@@ -505,7 +505,7 @@ Y_UNIT_TEST_SUITE(DateTimeTest) {
UNIT_ASSERT_VALUES_EQUAL(d1, d2);
}
- Y_UNIT_TEST(TestFromValueForTInstant) {
+ Y_UNIT_TEST(TestFromValueForTInstant) {
// check that FromValue creates the same TInstant
TInstant i1 = TInstant::MicroSeconds(12345);
TInstant i2 = TInstant::FromValue(i1.GetValue());
diff --git a/util/datetime/cputimer.cpp b/util/datetime/cputimer.cpp
index 978d41254e..516d372c37 100644
--- a/util/datetime/cputimer.cpp
+++ b/util/datetime/cputimer.cpp
@@ -2,7 +2,7 @@
#include <util/system/defaults.h>
#include <util/system/hp_timer.h>
-#include <util/string/printf.h>
+#include <util/string/printf.h>
#include <util/stream/output.h>
#include <util/generic/singleton.h>
@@ -16,7 +16,7 @@
#include <util/system/winint.h>
#endif
-TTimer::TTimer(const TStringBuf message) {
+TTimer::TTimer(const TStringBuf message) {
static const int SMALL_DURATION_CHAR_LENGTH = 9; // strlen("0.123456s")
Message_.Reserve(message.length() + SMALL_DURATION_CHAR_LENGTH + 1); // +"\n"
Message_ << message;
@@ -77,7 +77,7 @@ TString FormatCycles(ui64 cycles) {
return result;
}
-TFormattedPrecisionTimer::TFormattedPrecisionTimer(const char* message, IOutputStream* out)
+TFormattedPrecisionTimer::TFormattedPrecisionTimer(const char* message, IOutputStream* out)
: Message(message)
, Out(out)
{
@@ -106,7 +106,7 @@ TTimeLogger::TTimeLogger(const TString& message, bool verbose)
: Message(message)
, Verbose(verbose)
, OK(false)
- , Begin(time(nullptr))
+ , Begin(time(nullptr))
, BeginCycles(GetCycleCount())
{
if (Verbose) {
@@ -116,7 +116,7 @@ TTimeLogger::TTimeLogger(const TString& message, bool verbose)
}
double TTimeLogger::ElapsedTime() const {
- return time(nullptr) - Begin;
+ return time(nullptr) - Begin;
}
void TTimeLogger::SetOK() {
@@ -124,7 +124,7 @@ void TTimeLogger::SetOK() {
}
TTimeLogger::~TTimeLogger() {
- time_t tim = time(nullptr);
+ time_t tim = time(nullptr);
ui64 endCycles = GetCycleCount();
if (Verbose) {
const char* prefix = (OK) ? "" : "!";
diff --git a/util/datetime/cputimer.h b/util/datetime/cputimer.h
index 6104240264..7d38d5bdb3 100644
--- a/util/datetime/cputimer.h
+++ b/util/datetime/cputimer.h
@@ -78,10 +78,10 @@ class TFormattedPrecisionTimer {
private:
ui64 Start;
const char* Message;
- IOutputStream* Out;
+ IOutputStream* Out;
public:
- TFormattedPrecisionTimer(const char* message = "took ", IOutputStream* out = &Cout);
+ TFormattedPrecisionTimer(const char* message = "took ", IOutputStream* out = &Cout);
~TFormattedPrecisionTimer();
};
diff --git a/util/datetime/parser.rl6 b/util/datetime/parser.rl6
index 184b646a2d..931f09eae1 100644
--- a/util/datetime/parser.rl6
+++ b/util/datetime/parser.rl6
@@ -395,27 +395,27 @@ bool TX509Validity4yDateTimeParser::ParsePart(const char *input, size_t len) {
}
TInstant TIso8601DateTimeParserDeprecated::GetResult(TInstant defaultValue) const {
- Y_UNUSED(ISO8601DateTimeParser_en_main);
+ Y_UNUSED(ISO8601DateTimeParser_en_main);
return TDateTimeParserBaseDeprecated::GetResult(ISO8601DateTimeParser_first_final, defaultValue);
}
TInstant TRfc822DateTimeParserDeprecated::GetResult(TInstant defaultValue) const {
- Y_UNUSED(RFC822DateParser_en_main);
+ Y_UNUSED(RFC822DateParser_en_main);
return TDateTimeParserBaseDeprecated::GetResult(RFC822DateParser_first_final, defaultValue);
}
TInstant THttpDateTimeParserDeprecated::GetResult(TInstant defaultValue) const {
- Y_UNUSED(HttpDateTimeParserStandalone_en_main);
+ Y_UNUSED(HttpDateTimeParserStandalone_en_main);
return TDateTimeParserBaseDeprecated::GetResult(HttpDateTimeParserStandalone_first_final, defaultValue);
}
TInstant TX509ValidityDateTimeParserDeprecated::GetResult(TInstant defaultValue) const {
- Y_UNUSED(X509ValidityDateTimeParser_en_main);
+ Y_UNUSED(X509ValidityDateTimeParser_en_main);
return TDateTimeParserBaseDeprecated::GetResult(X509ValidityDateTimeParser_first_final, defaultValue);
}
TInstant TX509Validity4yDateTimeParserDeprecated::GetResult(TInstant defaultValue) const {
- Y_UNUSED(X509Validity4yDateTimeParser_en_main);
+ Y_UNUSED(X509Validity4yDateTimeParser_en_main);
return TDateTimeParserBaseDeprecated::GetResult(X509Validity4yDateTimeParser_first_final, defaultValue);
}
@@ -452,10 +452,10 @@ static inline TResult Parse(const char* input, size_t len, TResult defaultValue)
return parser.GetResult(defaultValue);
}
-template<class TParser, class TResult, bool ThrowExceptionOnFailure = true>
+template<class TParser, class TResult, bool ThrowExceptionOnFailure = true>
static inline TResult ParseUnsafe(const char* input, size_t len) {
TResult r = Parse<TParser, TResult>(input, len, TResult::Max());
- if (ThrowExceptionOnFailure && r == TResult::Max())
+ if (ThrowExceptionOnFailure && r == TResult::Max())
ythrow TDateTimeParseException() << "error in datetime parsing. Input data: " << TStringBuf(input, len);
return r;
}
@@ -479,56 +479,56 @@ TInstant TInstant::ParseX509ValidityDeprecated(const TStringBuf input) {
case 15:
return ParseUnsafe<TX509Validity4yDateTimeParserDeprecated, TInstant>(input.data(), 15);
default:
- ythrow TDateTimeParseException();
+ ythrow TDateTimeParseException();
}
}
bool TInstant::TryParseIso8601Deprecated(const TStringBuf input, TInstant& instant) {
const auto parsed = ParseUnsafe<TIso8601DateTimeParserDeprecated, TInstant, false>(input.data(), input.size());
- if (TInstant::Max() == parsed) {
- return false;
- }
- instant = parsed;
- return true;
-}
+ if (TInstant::Max() == parsed) {
+ return false;
+ }
+ instant = parsed;
+ return true;
+}
bool TInstant::TryParseRfc822Deprecated(const TStringBuf input, TInstant& instant) {
const auto parsed = ParseUnsafe<TRfc822DateTimeParserDeprecated, TInstant, false>(input.data(), input.size());
- if (TInstant::Max() == parsed) {
- return false;
- }
- instant = parsed;
- return true;
-}
-
+ if (TInstant::Max() == parsed) {
+ return false;
+ }
+ instant = parsed;
+ return true;
+}
+
bool TInstant::TryParseHttpDeprecated(const TStringBuf input, TInstant& instant) {
const auto parsed = ParseUnsafe<THttpDateTimeParserDeprecated, TInstant, false>(input.data(), input.size());
- if (TInstant::Max() == parsed) {
- return false;
- }
- instant = parsed;
- return true;
-}
-
+ if (TInstant::Max() == parsed) {
+ return false;
+ }
+ instant = parsed;
+ return true;
+}
+
bool TInstant::TryParseX509Deprecated(const TStringBuf input, TInstant& instant) {
- TInstant parsed;
+ TInstant parsed;
switch (input.size()) {
- case 13:
+ case 13:
parsed = ParseUnsafe<TX509ValidityDateTimeParserDeprecated, TInstant, false>(input.data(), 13);
- break;
- case 15:
+ break;
+ case 15:
parsed = ParseUnsafe<TX509Validity4yDateTimeParserDeprecated, TInstant, false>(input.data(), 15);
- break;
- default:
- return false;
- }
- if (TInstant::Max() == parsed) {
- return false;
- }
- instant = parsed;
- return true;
-}
-
+ break;
+ default:
+ return false;
+ }
+ if (TInstant::Max() == parsed) {
+ return false;
+ }
+ instant = parsed;
+ return true;
+}
+
TInstant TInstant::ParseIso8601(const TStringBuf input) {
return ParseUnsafe<TIso8601DateTimeParser, TInstant>(input.data(), input.size());
}
@@ -761,7 +761,7 @@ TDurationParser::TDurationParser()
, FractionPart(0)
, FractionDigits(0)
{
- Y_UNUSED(TDurationParser_en_main);
+ Y_UNUSED(TDurationParser_en_main);
%% write init;
}
@@ -788,7 +788,7 @@ TDuration TDurationParser::GetResult(TDuration defaultValue) const {
return TDuration::MicroSeconds(us);
}
-bool TDuration::TryParse(const TStringBuf input, TDuration& result) {
+bool TDuration::TryParse(const TStringBuf input, TDuration& result) {
TDuration r = ::Parse<TDurationParser, TDuration>(input.data(), input.size(), TDuration::Max());
if (r == TDuration::Max())
return false;
@@ -796,6 +796,6 @@ bool TDuration::TryParse(const TStringBuf input, TDuration& result) {
return true;
}
-TDuration TDuration::Parse(const TStringBuf input) {
+TDuration TDuration::Parse(const TStringBuf input) {
return ParseUnsafe<TDurationParser, TDuration>(input.data(), input.size());
}
diff --git a/util/datetime/parser_ut.cpp b/util/datetime/parser_ut.cpp
index 44834bd0ef..61364af997 100644
--- a/util/datetime/parser_ut.cpp
+++ b/util/datetime/parser_ut.cpp
@@ -5,8 +5,8 @@
static const time_t SECONDS_PER_HOUR = 3600;
static const time_t SECONDS_PER_MINUTE = 60;
-Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
- Y_UNIT_TEST(TestRfc822Correct) {
+Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
+ Y_UNIT_TEST(TestRfc822Correct) {
bool r = false;
time_t t = 0;
@@ -159,14 +159,14 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
}
}
- Y_UNIT_TEST(TestRfc822MilitaryZones) {
+ Y_UNIT_TEST(TestRfc822MilitaryZones) {
DoTestMilitaryZones('A', 'I');
DoTestMilitaryZones('K', 'Z');
DoTestMilitaryZones('a', 'i');
DoTestMilitaryZones('k', 'z');
}
- Y_UNIT_TEST(TestRfc822IncorrectDates) {
+ Y_UNIT_TEST(TestRfc822IncorrectDates) {
bool r = true;
time_t t = 0;
@@ -255,7 +255,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
UNIT_ASSERT(!r);
}
- Y_UNIT_TEST(TestRfc822Partial) {
+ Y_UNIT_TEST(TestRfc822Partial) {
TRfc822DateTimeParser p;
const char* part1 = "Fri, 4 Mar 05 1";
const char* part2 = "9:34:45 +0300";
@@ -268,7 +268,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(1109954086), p.GetResult(TInstant::Zero()));
}
- Y_UNIT_TEST(TestIso8601Partial) {
+ Y_UNIT_TEST(TestIso8601Partial) {
TIso8601DateTimeParser p;
const char* part1 = "1990-03-15T15:1";
const char* part2 = "6:17+0732";
@@ -281,7 +281,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(637487058), p.GetResult(TInstant::Zero()));
}
- Y_UNIT_TEST(TestIso8601Correct) {
+ Y_UNIT_TEST(TestIso8601Correct) {
bool ret;
time_t t;
@@ -361,7 +361,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
UNIT_ASSERT_VALUES_EQUAL(t, 1269775620);
}
- Y_UNIT_TEST(TestIso8601TimeZone) {
+ Y_UNIT_TEST(TestIso8601TimeZone) {
time_t t1, t2, t3, t4;
UNIT_ASSERT(ParseISO8601DateTime("2010-03-28T04:27:00.000+07:00", t1));
UNIT_ASSERT(ParseISO8601DateTime("2010-03-27T21:27:00.000Z", t2));
@@ -372,7 +372,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
UNIT_ASSERT_VALUES_EQUAL(t3, t4);
}
- Y_UNIT_TEST(TestIso8601Incorrect) {
+ Y_UNIT_TEST(TestIso8601Incorrect) {
bool ret;
time_t t;
@@ -406,7 +406,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
UNIT_ASSERT(!ret);
}
- Y_UNIT_TEST(TestIso8601Fractions) {
+ Y_UNIT_TEST(TestIso8601Fractions) {
UNIT_ASSERT_VALUES_EQUAL(
TInstant::ParseIso8601("2009-09-19 03:37:08.1+04:00"),
TInstant::Seconds(1253317028) + TDuration::MilliSeconds(100));
@@ -471,7 +471,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
}
}
- Y_UNIT_TEST(TestHttpDate) {
+ Y_UNIT_TEST(TestHttpDate) {
UNIT_ASSERT_VALUES_EQUAL(
TInstant::ParseHttp("Sun, 06 Nov 1994 08:49:37 GMT"),
TInstant::ParseIso8601("1994-11-06T08:49:37Z"));
@@ -486,14 +486,14 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
TInstant::ParseIso8601("2037-01-19T08:49:37Z"));
}
- Y_UNIT_TEST(TestHttpDateIncorrect) {
+ Y_UNIT_TEST(TestHttpDateIncorrect) {
bool ret;
time_t t = 0;
ret = ParseHTTPDateTime("1990-03-15T15:16:17Z", t);
UNIT_ASSERT(!ret);
}
- Y_UNIT_TEST(TestX509ValidityTime) {
+ Y_UNIT_TEST(TestX509ValidityTime) {
UNIT_ASSERT_VALUES_EQUAL(
TInstant::ParseX509Validity("20091014165533Z"),
TInstant::ParseRfc822("Wed, 14 Oct 2009 16:55:33 GMT"));
@@ -505,7 +505,7 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
TInstant::ParseRfc822("31 Dec 2019 23:59:59 GMT"));
}
- Y_UNIT_TEST(TestX509ValidityTimeIncorrect) {
+ Y_UNIT_TEST(TestX509ValidityTimeIncorrect) {
bool ret;
time_t t = 0;
ret = ParseX509ValidityDateTime("500101000000Z", t);
@@ -513,65 +513,65 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) {
ret = ParseX509ValidityDateTime("091014165533+0300", t);
UNIT_ASSERT(!ret);
}
-
- Y_UNIT_TEST(TestTInstantTryParse) {
- {
+
+ Y_UNIT_TEST(TestTInstantTryParse) {
+ {
const TStringBuf s = "2009-09-19 03:37:08.1+04:00";
const auto i = TInstant::ParseIso8601(s);
- TInstant iTry;
+ TInstant iTry;
UNIT_ASSERT(TInstant::TryParseIso8601(s, iTry));
- UNIT_ASSERT_VALUES_EQUAL(i, iTry);
- }
- {
+ UNIT_ASSERT_VALUES_EQUAL(i, iTry);
+ }
+ {
const TStringBuf s = "2009-09aslkdjfkljasdjfl4:00";
- TInstant iTry;
+ TInstant iTry;
UNIT_ASSERT_EXCEPTION(TInstant::ParseIso8601(s), TDateTimeParseException);
UNIT_ASSERT(!TInstant::TryParseIso8601(s, iTry));
- }
- {
+ }
+ {
const TStringBuf s = "Wed, 14 Oct 2009 16:55:33 GMT";
const auto i = TInstant::ParseRfc822(s);
- TInstant iTry;
+ TInstant iTry;
UNIT_ASSERT(TInstant::TryParseRfc822(s, iTry));
- UNIT_ASSERT_VALUES_EQUAL(i, iTry);
- }
- {
+ UNIT_ASSERT_VALUES_EQUAL(i, iTry);
+ }
+ {
const TStringBuf s = "Wed, alsdjflkasjdfl:55:33 GMT";
- TInstant iTry;
+ TInstant iTry;
UNIT_ASSERT_EXCEPTION(TInstant::ParseRfc822(s), TDateTimeParseException);
UNIT_ASSERT(!TInstant::TryParseRfc822(s, iTry));
- }
- {
+ }
+ {
const TStringBuf s = "20091014165533Z";
const auto i = TInstant::ParseX509Validity(s);
- TInstant iTry;
+ TInstant iTry;
UNIT_ASSERT(TInstant::TryParseX509(s, iTry));
- UNIT_ASSERT_VALUES_EQUAL(i, iTry);
- }
- {
+ UNIT_ASSERT_VALUES_EQUAL(i, iTry);
+ }
+ {
const TStringBuf s = "200asdfasdf533Z";
- TInstant iTry;
+ TInstant iTry;
UNIT_ASSERT_EXCEPTION(TInstant::ParseX509Validity(s), TDateTimeParseException);
UNIT_ASSERT(!TInstant::TryParseX509(s, iTry));
- }
- {
+ }
+ {
const TStringBuf s = "990104074212Z";
const auto i = TInstant::ParseX509Validity(s);
- TInstant iTry;
+ TInstant iTry;
UNIT_ASSERT(TInstant::TryParseX509(s, iTry));
- UNIT_ASSERT_VALUES_EQUAL(i, iTry);
- }
- {
+ UNIT_ASSERT_VALUES_EQUAL(i, iTry);
+ }
+ {
const TStringBuf s = "9901asdf4212Z";
- TInstant iTry;
+ TInstant iTry;
UNIT_ASSERT_EXCEPTION(TInstant::ParseX509Validity(s), TDateTimeParseException);
UNIT_ASSERT(!TInstant::TryParseX509(s, iTry));
- }
- }
+ }
+ }
}
-Y_UNIT_TEST_SUITE(TDurationParseTest) {
- Y_UNIT_TEST(TestParse) {
+Y_UNIT_TEST_SUITE(TDurationParseTest) {
+ Y_UNIT_TEST(TestParse) {
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(60 * 60 * 24 * 7), TDuration::Parse("1w"));
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(60), TDuration::Parse("1m"));
UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(90), TDuration::Parse("1.5m"));