diff options
author | svshevtsov <svshevtsov@yandex-team.ru> | 2022-02-10 16:49:37 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:37 +0300 |
commit | 657337012a264721d58c470b4e9e796611f3c492 (patch) | |
tree | 82753fd92cf7cc2dea4e522a945ed570131f920b /util/datetime | |
parent | 44f31b316af517a4fbc6a82ebed8a1c51807deac (diff) | |
download | ydb-657337012a264721d58c470b4e9e796611f3c492.tar.gz |
Restoring authorship annotation for <svshevtsov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/datetime')
-rw-r--r-- | util/datetime/base.h | 18 | ||||
-rw-r--r-- | util/datetime/base_ut.cpp | 44 |
2 files changed, 31 insertions, 31 deletions
diff --git a/util/datetime/base.h b/util/datetime/base.h index 5e902b8f63..4239ce2e6b 100644 --- a/util/datetime/base.h +++ b/util/datetime/base.h @@ -148,9 +148,9 @@ public: } constexpr TValue Days() const noexcept { - return Hours() / 24; - } - + return Hours() / 24; + } + constexpr TValue NanoSeconds() const noexcept { return MicroSeconds() >= (Max<TValue>() / (TValue)1000) ? Max<TValue>() : MicroSeconds() * (TValue)1000; } @@ -270,7 +270,7 @@ public: return MicroSeconds((ui64)(typename NDateTimeHelpers::TPrecisionHelper<T>::THighPrecision(ms) * 1000)); } - using TBase::Days; + using TBase::Days; using TBase::Hours; using TBase::MicroSeconds; using TBase::MilliSeconds; @@ -376,7 +376,7 @@ public: return TInstant::MicroSeconds(::MicroSeconds()); } - using TBase::Days; + using TBase::Days; using TBase::Hours; using TBase::MicroSeconds; using TBase::MilliSeconds; @@ -416,11 +416,11 @@ public: return Minutes(h * 60); } - /// days since epoch + /// days since epoch static constexpr TInstant Days(ui64 d) noexcept { - return Hours(d * 24); - } - + return Hours(d * 24); + } + constexpr time_t TimeT() const noexcept { return (time_t)Seconds(); } diff --git a/util/datetime/base_ut.cpp b/util/datetime/base_ut.cpp index afc3f802eb..7eb7adccef 100644 --- a/util/datetime/base_ut.cpp +++ b/util/datetime/base_ut.cpp @@ -459,38 +459,38 @@ Y_UNIT_TEST_SUITE(DateTimeTest) { UNIT_ASSERT_VALUES_EQUAL(value.MicroSeconds(), 1234567); } - template <class T> - void TestTimeUnits() { + template <class T> + void TestTimeUnits() { T withTime = T::MicroSeconds(1249571946000000L); T onlyMinutes = T::MicroSeconds(1249571940000000L); T onlyHours = T::MicroSeconds(1249570800000000L); T onlyDays = T::MicroSeconds(1249516800000000L); - ui64 minutes = 20826199; + ui64 minutes = 20826199; ui64 hours = 347103; - ui64 days = 14462; - - UNIT_ASSERT_VALUES_EQUAL(withTime.Minutes(), minutes); - UNIT_ASSERT_VALUES_EQUAL(onlyMinutes, T::Minutes(minutes)); - UNIT_ASSERT_VALUES_EQUAL(onlyMinutes.Minutes(), minutes); - + ui64 days = 14462; + + UNIT_ASSERT_VALUES_EQUAL(withTime.Minutes(), minutes); + UNIT_ASSERT_VALUES_EQUAL(onlyMinutes, T::Minutes(minutes)); + UNIT_ASSERT_VALUES_EQUAL(onlyMinutes.Minutes(), minutes); + UNIT_ASSERT_VALUES_EQUAL(withTime.Hours(), hours); - UNIT_ASSERT_VALUES_EQUAL(onlyMinutes.Hours(), hours); - UNIT_ASSERT_VALUES_EQUAL(onlyHours, T::Hours(hours)); + UNIT_ASSERT_VALUES_EQUAL(onlyMinutes.Hours(), hours); + UNIT_ASSERT_VALUES_EQUAL(onlyHours, T::Hours(hours)); UNIT_ASSERT_VALUES_EQUAL(onlyHours.Hours(), hours); - - UNIT_ASSERT_VALUES_EQUAL(withTime.Days(), days); - UNIT_ASSERT_VALUES_EQUAL(onlyHours.Days(), days); - UNIT_ASSERT_VALUES_EQUAL(onlyDays, T::Days(days)); - UNIT_ASSERT_VALUES_EQUAL(onlyDays.Days(), days); + + UNIT_ASSERT_VALUES_EQUAL(withTime.Days(), days); + UNIT_ASSERT_VALUES_EQUAL(onlyHours.Days(), days); + UNIT_ASSERT_VALUES_EQUAL(onlyDays, T::Days(days)); + UNIT_ASSERT_VALUES_EQUAL(onlyDays.Days(), days); } - + Y_UNIT_TEST(TestInstantUnits) { - TestTimeUnits<TInstant>(); - } - + TestTimeUnits<TInstant>(); + } + Y_UNIT_TEST(TestDurationUnits) { - TestTimeUnits<TDuration>(); - } + TestTimeUnits<TDuration>(); + } Y_UNIT_TEST(TestNoexceptConstruction) { UNIT_ASSERT_EXCEPTION(TDuration::MilliSeconds(FromString(TStringBuf("not a number"))), yexception); |