diff options
author | darkk <darkk@yandex-team.ru> | 2022-02-10 16:49:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:49 +0300 |
commit | f772ca38c4a395b911129411c06b2074d69d826f (patch) | |
tree | 76717845f670ca68fd5ebb858eaaf9963032c74e /util/datetime | |
parent | ab4e3e6f0c4354283ce0375c811569c080cbfbc3 (diff) | |
download | ydb-f772ca38c4a395b911129411c06b2074d69d826f.tar.gz |
Restoring authorship annotation for <darkk@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/datetime')
-rw-r--r-- | util/datetime/parser.h | 2 | ||||
-rw-r--r-- | util/datetime/parser.rl6 | 20 | ||||
-rw-r--r-- | util/datetime/parser_ut.cpp | 54 |
3 files changed, 38 insertions, 38 deletions
diff --git a/util/datetime/parser.h b/util/datetime/parser.h index f0c1b4a0c7..4735d41c01 100644 --- a/util/datetime/parser.h +++ b/util/datetime/parser.h @@ -146,7 +146,7 @@ struct TDurationParser { ui32 Dc; i32 MultiplierPower; // 6 for seconds, 0 for microseconds, -3 for nanoseconds - i32 Multiplier; + i32 Multiplier; ui64 IntegerPart; ui32 FractionPart; ui32 FractionDigits; diff --git a/util/datetime/parser.rl6 b/util/datetime/parser.rl6 index 931f09eae1..def64235a1 100644 --- a/util/datetime/parser.rl6 +++ b/util/datetime/parser.rl6 @@ -730,13 +730,13 @@ include DateTimeParserCommon; multiplier = '' # >{ MultiplierPower = 6; } # work around Ragel bugs | 'w' @{ MultiplierPower = 6; Multiplier = 604800; } - | 'd' @{ MultiplierPower = 6; Multiplier = 86400; } - | 'h' @{ MultiplierPower = 6; Multiplier = 3600; } - | 'm' @{ MultiplierPower = 6; Multiplier = 60; } - | 's' @{ MultiplierPower = 6; Multiplier = 1; } - | 'ms' @{ MultiplierPower = 3; Multiplier = 1; } - | 'us' @{ MultiplierPower = 0; Multiplier = 1; } - | 'ns' @{ MultiplierPower = -3; Multiplier = 1; } + | 'd' @{ MultiplierPower = 6; Multiplier = 86400; } + | 'h' @{ MultiplierPower = 6; Multiplier = 3600; } + | 'm' @{ MultiplierPower = 6; Multiplier = 60; } + | 's' @{ MultiplierPower = 6; Multiplier = 1; } + | 'ms' @{ MultiplierPower = 3; Multiplier = 1; } + | 'us' @{ MultiplierPower = 0; Multiplier = 1; } + | 'ns' @{ MultiplierPower = -3; Multiplier = 1; } ; integer = int @{ IntegerPart = I; }; @@ -756,7 +756,7 @@ TDurationParser::TDurationParser() , I(0) , Dc(0) , MultiplierPower(6) - , Multiplier(1) + , Multiplier(1) , IntegerPart(0) , FractionPart(0) , FractionDigits(0) @@ -783,8 +783,8 @@ TDuration TDurationParser::GetResult(TDuration defaultValue) const { if (cs < TDurationParser_first_final) return defaultValue; ui64 us = 0; - us += Multiplier * DecPower(IntegerPart, MultiplierPower); - us += Multiplier * DecPower(FractionPart, MultiplierPower - FractionDigits); + us += Multiplier * DecPower(IntegerPart, MultiplierPower); + us += Multiplier * DecPower(FractionPart, MultiplierPower - FractionDigits); return TDuration::MicroSeconds(us); } diff --git a/util/datetime/parser_ut.cpp b/util/datetime/parser_ut.cpp index 61364af997..fe59b95452 100644 --- a/util/datetime/parser_ut.cpp +++ b/util/datetime/parser_ut.cpp @@ -573,38 +573,38 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) { 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")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(102), TDuration::Parse("1.7m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119400), TDuration::Parse("1.99m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119940), TDuration::Parse("1.999m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119994), TDuration::Parse("1.9999m")); - - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(60), TDuration::Parse("1h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(90), TDuration::Parse("1.5h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(102), TDuration::Parse("1.7h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(7164), TDuration::Parse("1.99h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(7196400), TDuration::Parse("1.999h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(7199640), TDuration::Parse("1.9999h")); - + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(60), TDuration::Parse("1m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(90), TDuration::Parse("1.5m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(102), TDuration::Parse("1.7m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119400), TDuration::Parse("1.99m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119940), TDuration::Parse("1.999m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119994), TDuration::Parse("1.9999m")); + + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(60), TDuration::Parse("1h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(90), TDuration::Parse("1.5h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(102), TDuration::Parse("1.7h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(7164), TDuration::Parse("1.99h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(7196400), TDuration::Parse("1.999h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(7199640), TDuration::Parse("1.9999h")); + UNIT_ASSERT_EQUAL(TDuration::Minutes(15), TDuration::Parse("15m")); UNIT_ASSERT_EQUAL(TDuration::Hours(10), TDuration::Parse("10h")); UNIT_ASSERT_EQUAL(TDuration::Days(365), TDuration::Parse("365d")); UNIT_ASSERT_EQUAL(TDuration::Hours(36), TDuration::Parse("1.5d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(24), TDuration::Parse("1d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(36), TDuration::Parse("1.5d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(2448), TDuration::Parse("1.7d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(171936), TDuration::Parse("1.99d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(172713600), TDuration::Parse("1.999d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(172791360), TDuration::Parse("1.9999d")); - -#if 0 // not implemented - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(90), TDuration::Parse("1m30s")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(90), TDuration::Parse("1h30m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(36), TDuration::Parse("1d12h")); -#endif - + UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(24), TDuration::Parse("1d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(36), TDuration::Parse("1.5d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(2448), TDuration::Parse("1.7d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(171936), TDuration::Parse("1.99d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(172713600), TDuration::Parse("1.999d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(172791360), TDuration::Parse("1.9999d")); + +#if 0 // not implemented + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(90), TDuration::Parse("1m30s")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(90), TDuration::Parse("1h30m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(36), TDuration::Parse("1d12h")); +#endif + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(10), TDuration::Parse("10s")); UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(10), TDuration::Parse("10.000s")); UNIT_ASSERT_VALUES_EQUAL(TDuration::MicroSeconds(4), TDuration::Parse("0.000004s")); |