aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/timezone_conversion
diff options
context:
space:
mode:
authorgotmanov <gotmanov@yandex-team.ru>2022-02-10 16:49:26 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:26 +0300
commitb3c1a086292c74ed88830693f15a96ddeadc6b9a (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/timezone_conversion
parent243edeedfd2c5152b5c7812e0af471e1bb0232e8 (diff)
downloadydb-b3c1a086292c74ed88830693f15a96ddeadc6b9a.tar.gz
Restoring authorship annotation for <gotmanov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/timezone_conversion')
-rw-r--r--library/cpp/timezone_conversion/civil-inl.h122
-rw-r--r--library/cpp/timezone_conversion/civil.cpp102
-rw-r--r--library/cpp/timezone_conversion/civil.h132
-rw-r--r--library/cpp/timezone_conversion/ut/civil_ut.cpp86
-rw-r--r--library/cpp/timezone_conversion/ya.make4
5 files changed, 223 insertions, 223 deletions
diff --git a/library/cpp/timezone_conversion/civil-inl.h b/library/cpp/timezone_conversion/civil-inl.h
index 5181c97b7d..32afbccb64 100644
--- a/library/cpp/timezone_conversion/civil-inl.h
+++ b/library/cpp/timezone_conversion/civil-inl.h
@@ -1,63 +1,63 @@
-#pragma once
-
-#include "civil.h"
-
-namespace NDatetime {
- namespace NDetail {
- template <typename T>
- struct TGetCivilUnit;
-
- template <>
- struct TGetCivilUnit<TCivilSecond> {
- static constexpr ECivilUnit Value = ECivilUnit::Second;
- };
- template <>
- struct TGetCivilUnit<TCivilMinute> {
- static constexpr ECivilUnit Value = ECivilUnit::Minute;
- };
- template <>
- struct TGetCivilUnit<TCivilHour> {
- static constexpr ECivilUnit Value = ECivilUnit::Hour;
- };
- template <>
- struct TGetCivilUnit<TCivilDay> {
- static constexpr ECivilUnit Value = ECivilUnit::Day;
- };
- template <>
- struct TGetCivilUnit<TCivilMonth> {
- static constexpr ECivilUnit Value = ECivilUnit::Month;
- };
- template <>
- struct TGetCivilUnit<TCivilYear> {
- static constexpr ECivilUnit Value = ECivilUnit::Year;
- };
-
- template <ECivilUnit Unit>
- struct TGetCivilTime;
-
- template <>
- struct TGetCivilTime<ECivilUnit::Second> {
- using TResult = TCivilSecond;
- };
- template <>
- struct TGetCivilTime<ECivilUnit::Minute> {
- using TResult = TCivilMinute;
- };
- template <>
- struct TGetCivilTime<ECivilUnit::Hour> {
- using TResult = TCivilHour;
- };
- template <>
- struct TGetCivilTime<ECivilUnit::Day> {
- using TResult = TCivilDay;
- };
- template <>
- struct TGetCivilTime<ECivilUnit::Month> {
- using TResult = TCivilMonth;
- };
- template <>
- struct TGetCivilTime<ECivilUnit::Year> {
- using TResult = TCivilYear;
- };
+#pragma once
+
+#include "civil.h"
+
+namespace NDatetime {
+ namespace NDetail {
+ template <typename T>
+ struct TGetCivilUnit;
+
+ template <>
+ struct TGetCivilUnit<TCivilSecond> {
+ static constexpr ECivilUnit Value = ECivilUnit::Second;
+ };
+ template <>
+ struct TGetCivilUnit<TCivilMinute> {
+ static constexpr ECivilUnit Value = ECivilUnit::Minute;
+ };
+ template <>
+ struct TGetCivilUnit<TCivilHour> {
+ static constexpr ECivilUnit Value = ECivilUnit::Hour;
+ };
+ template <>
+ struct TGetCivilUnit<TCivilDay> {
+ static constexpr ECivilUnit Value = ECivilUnit::Day;
+ };
+ template <>
+ struct TGetCivilUnit<TCivilMonth> {
+ static constexpr ECivilUnit Value = ECivilUnit::Month;
+ };
+ template <>
+ struct TGetCivilUnit<TCivilYear> {
+ static constexpr ECivilUnit Value = ECivilUnit::Year;
+ };
+
+ template <ECivilUnit Unit>
+ struct TGetCivilTime;
+
+ template <>
+ struct TGetCivilTime<ECivilUnit::Second> {
+ using TResult = TCivilSecond;
+ };
+ template <>
+ struct TGetCivilTime<ECivilUnit::Minute> {
+ using TResult = TCivilMinute;
+ };
+ template <>
+ struct TGetCivilTime<ECivilUnit::Hour> {
+ using TResult = TCivilHour;
+ };
+ template <>
+ struct TGetCivilTime<ECivilUnit::Day> {
+ using TResult = TCivilDay;
+ };
+ template <>
+ struct TGetCivilTime<ECivilUnit::Month> {
+ using TResult = TCivilMonth;
+ };
+ template <>
+ struct TGetCivilTime<ECivilUnit::Year> {
+ using TResult = TCivilYear;
+ };
}
}
diff --git a/library/cpp/timezone_conversion/civil.cpp b/library/cpp/timezone_conversion/civil.cpp
index c712f88748..5986318b9a 100644
--- a/library/cpp/timezone_conversion/civil.cpp
+++ b/library/cpp/timezone_conversion/civil.cpp
@@ -122,57 +122,57 @@ namespace NDatetime {
return Calc<TCivilSecond>(tp, diff);
}
- TCivilSecond AddCivil(const TCivilSecond& tp, TCivilDiff diff) {
- switch (diff.Unit) {
- case ECivilUnit::Second: {
- return AddSeconds(tp, diff.Value);
- }
- case ECivilUnit::Minute: {
- return AddMinutes(tp, diff.Value);
- }
- case ECivilUnit::Hour: {
- return AddHours(tp, diff.Value);
- }
- case ECivilUnit::Day: {
- return AddDays(tp, diff.Value);
- }
- case ECivilUnit::Month: {
- return AddMonths(tp, diff.Value);
- }
- case ECivilUnit::Year: {
- return AddYears(tp, diff.Value);
- }
- default: {
- ythrow yexception() << "Unexpected civil unit value " << static_cast<int>(diff.Unit);
- }
- }
- }
-
- TCivilDiff GetCivilDiff(const TCivilSecond& tpX, const TCivilSecond& tpY, ECivilUnit unit) {
- switch (unit) {
- case ECivilUnit::Second: {
- return {tpX - tpY, unit};
- }
- case ECivilUnit::Minute: {
- return {static_cast<TCivilMinute>(tpX) - static_cast<TCivilMinute>(tpY), unit};
- }
- case ECivilUnit::Hour: {
- return {static_cast<TCivilHour>(tpX) - static_cast<TCivilHour>(tpY), unit};
- }
- case ECivilUnit::Day: {
- return {static_cast<TCivilDay>(tpX) - static_cast<TCivilDay>(tpY), unit};
- }
- case ECivilUnit::Month: {
- return {static_cast<TCivilMonth>(tpX) - static_cast<TCivilMonth>(tpY), unit};
- }
- case ECivilUnit::Year: {
- return {static_cast<TCivilYear>(tpX) - static_cast<TCivilYear>(tpY), unit};
- }
- default: {
- ythrow yexception() << "Unexpected civil unit value " << static_cast<int>(unit);
- }
- }
- }
+ TCivilSecond AddCivil(const TCivilSecond& tp, TCivilDiff diff) {
+ switch (diff.Unit) {
+ case ECivilUnit::Second: {
+ return AddSeconds(tp, diff.Value);
+ }
+ case ECivilUnit::Minute: {
+ return AddMinutes(tp, diff.Value);
+ }
+ case ECivilUnit::Hour: {
+ return AddHours(tp, diff.Value);
+ }
+ case ECivilUnit::Day: {
+ return AddDays(tp, diff.Value);
+ }
+ case ECivilUnit::Month: {
+ return AddMonths(tp, diff.Value);
+ }
+ case ECivilUnit::Year: {
+ return AddYears(tp, diff.Value);
+ }
+ default: {
+ ythrow yexception() << "Unexpected civil unit value " << static_cast<int>(diff.Unit);
+ }
+ }
+ }
+
+ TCivilDiff GetCivilDiff(const TCivilSecond& tpX, const TCivilSecond& tpY, ECivilUnit unit) {
+ switch (unit) {
+ case ECivilUnit::Second: {
+ return {tpX - tpY, unit};
+ }
+ case ECivilUnit::Minute: {
+ return {static_cast<TCivilMinute>(tpX) - static_cast<TCivilMinute>(tpY), unit};
+ }
+ case ECivilUnit::Hour: {
+ return {static_cast<TCivilHour>(tpX) - static_cast<TCivilHour>(tpY), unit};
+ }
+ case ECivilUnit::Day: {
+ return {static_cast<TCivilDay>(tpX) - static_cast<TCivilDay>(tpY), unit};
+ }
+ case ECivilUnit::Month: {
+ return {static_cast<TCivilMonth>(tpX) - static_cast<TCivilMonth>(tpY), unit};
+ }
+ case ECivilUnit::Year: {
+ return {static_cast<TCivilYear>(tpX) - static_cast<TCivilYear>(tpY), unit};
+ }
+ default: {
+ ythrow yexception() << "Unexpected civil unit value " << static_cast<int>(unit);
+ }
+ }
+ }
}
template <>
diff --git a/library/cpp/timezone_conversion/civil.h b/library/cpp/timezone_conversion/civil.h
index 51983e73b2..0e95b807ed 100644
--- a/library/cpp/timezone_conversion/civil.h
+++ b/library/cpp/timezone_conversion/civil.h
@@ -43,53 +43,53 @@ namespace NDatetime {
using TYear = cctz::year_t;
using TMonth = cctz::detail::month_t;
- enum class ECivilUnit : int {
- Second = 0,
- Minute = 1,
- Hour = 2,
- Day = 3,
- Month = 4,
- Year = 5
- };
-
- namespace NDetail {
- template <typename T>
- struct TGetCivilUnit;
-
- template <ECivilUnit Unit>
- struct TGetCivilTime;
+ enum class ECivilUnit : int {
+ Second = 0,
+ Minute = 1,
+ Hour = 2,
+ Day = 3,
+ Month = 4,
+ Year = 5
+ };
+
+ namespace NDetail {
+ template <typename T>
+ struct TGetCivilUnit;
+
+ template <ECivilUnit Unit>
+ struct TGetCivilTime;
+ }
+
+ template <typename T>
+ CONSTEXPR_M ECivilUnit GetCivilUnit(const T& = {}) {
+ return NDetail::TGetCivilUnit<T>::Value;
}
-
- template <typename T>
- CONSTEXPR_M ECivilUnit GetCivilUnit(const T& = {}) {
- return NDetail::TGetCivilUnit<T>::Value;
- }
-
- template <ECivilUnit Unit>
- using TCivilTime = typename NDetail::TGetCivilTime<Unit>::TResult;
-
+
+ template <ECivilUnit Unit>
+ using TCivilTime = typename NDetail::TGetCivilTime<Unit>::TResult;
+
+ /**
+ * Class with variable unit diff.
+ */
+ struct TCivilDiff {
+ TDiff Value = 0;
+ ECivilUnit Unit = ECivilUnit::Second;
+
+ TCivilDiff() = default;
+ TCivilDiff(TDiff value, ECivilUnit unit)
+ : Value(value)
+ , Unit(unit)
+ {
+ }
+
+ /**
+ * Straightfoward implementation of operators <, == and unit conversions
+ * can be potentially misleading (e.g. 1 month == 30 days?);
+ * we leave it to user to implement it properly for each application.
+ */
+ };
+
/**
- * Class with variable unit diff.
- */
- struct TCivilDiff {
- TDiff Value = 0;
- ECivilUnit Unit = ECivilUnit::Second;
-
- TCivilDiff() = default;
- TCivilDiff(TDiff value, ECivilUnit unit)
- : Value(value)
- , Unit(unit)
- {
- }
-
- /**
- * Straightfoward implementation of operators <, == and unit conversions
- * can be potentially misleading (e.g. 1 month == 30 days?);
- * we leave it to user to implement it properly for each application.
- */
- };
-
- /**
* Gets the time zone by an IANA name.
* @param name A name in IANA format (e.g., "Europe/Moscow").
* @note After you request a time zone for the first time, it is cached
@@ -150,7 +150,7 @@ namespace NDatetime {
* @return the calculated T type
*/
template <typename T, typename S>
- inline T Calc(const S& tp, TDiff diff) {
+ inline T Calc(const S& tp, TDiff diff) {
return T(tp) + diff;
}
@@ -166,24 +166,24 @@ namespace NDatetime {
TCivilSecond AddMinutes(const TCivilSecond& tp, TDiff diff);
TCivilSecond AddSeconds(const TCivilSecond& tp, TDiff diff);
- /** Method to add TCivilDiff
- * @param[in] tp is a timepoint with which calc will be
- * @param[in] diff is quantity of which will be added to the tp
- * @return the calculated TCivilSecond object
- */
- TCivilSecond AddCivil(const TCivilSecond& tp, TCivilDiff diff);
-
- /** Method to subtract to civil dates/times and get TCivilDiff.
- * First casts to unit, then subtracts;
- * e.g. GetCivilDiff(2017-10-01, 2017-09-30, Month) = 1.
- *
- * @param[in] tpX is a timepoint
- * @param[in] tpY is a timepoint to subtract from tpX
- * @param[in] unit is a civil time unit to use in subtraction
- * @return the calculated diff as TCivilDiff object
- */
- TCivilDiff GetCivilDiff(const TCivilSecond& tpX, const TCivilSecond& tpY, ECivilUnit unit);
-
+ /** Method to add TCivilDiff
+ * @param[in] tp is a timepoint with which calc will be
+ * @param[in] diff is quantity of which will be added to the tp
+ * @return the calculated TCivilSecond object
+ */
+ TCivilSecond AddCivil(const TCivilSecond& tp, TCivilDiff diff);
+
+ /** Method to subtract to civil dates/times and get TCivilDiff.
+ * First casts to unit, then subtracts;
+ * e.g. GetCivilDiff(2017-10-01, 2017-09-30, Month) = 1.
+ *
+ * @param[in] tpX is a timepoint
+ * @param[in] tpY is a timepoint to subtract from tpX
+ * @param[in] unit is a civil time unit to use in subtraction
+ * @return the calculated diff as TCivilDiff object
+ */
+ TCivilDiff GetCivilDiff(const TCivilSecond& tpX, const TCivilSecond& tpY, ECivilUnit unit);
+
/** Formats the given TimePoint in the given TTimeZone according to
* the provided format string. Uses strftime()-like formatting options,
* with the following extensions:
@@ -333,6 +333,6 @@ namespace NDatetime {
}
}
-#include "civil-inl.h"
-
+#include "civil-inl.h"
+
#undef CONSTEXPR_M
diff --git a/library/cpp/timezone_conversion/ut/civil_ut.cpp b/library/cpp/timezone_conversion/ut/civil_ut.cpp
index a4e45879af..a21bd4bd7d 100644
--- a/library/cpp/timezone_conversion/ut/civil_ut.cpp
+++ b/library/cpp/timezone_conversion/ut/civil_ut.cpp
@@ -4,17 +4,17 @@
#include <util/stream/str.h>
-namespace NDatetime {
+namespace NDatetime {
inline bool operator==(const NDatetime::TCivilDiff& x, const NDatetime::TCivilDiff& y) {
- return x.Unit == y.Unit && x.Value == y.Value;
- }
+ return x.Unit == y.Unit && x.Value == y.Value;
+ }
+}
+
+template <>
+inline void Out<NDatetime::TCivilDiff>(IOutputStream& out, const NDatetime::TCivilDiff& diff) {
+ out << "(" << diff.Value << "," << diff.Unit << ")";
}
-
-template <>
-inline void Out<NDatetime::TCivilDiff>(IOutputStream& out, const NDatetime::TCivilDiff& diff) {
- out << "(" << diff.Value << "," << diff.Unit << ")";
-}
-
+
Y_UNIT_TEST_SUITE(DateTime) {
Y_UNIT_TEST(Calc) {
NDatetime::TCivilSecond s(2017, 2, 1, 10, 12, 9);
@@ -83,40 +83,40 @@ Y_UNIT_TEST_SUITE(DateTime) {
UNIT_ASSERT_VALUES_EQUAL(NDatetime::WeekdayOnTheWeek(d, NDatetime::TWeekday::friday), NDatetime::TCivilDay(2013, 1, 4));
}
Y_UNIT_TEST(CivilUnit) {
- using namespace NDatetime;
-
- UNIT_ASSERT_VALUES_EQUAL(GetCivilUnit<TCivilMonth>(), ECivilUnit::Month);
- UNIT_ASSERT_VALUES_EQUAL(GetCivilUnit(TCivilHour{}), ECivilUnit::Hour);
-
- UNIT_ASSERT_VALUES_EQUAL(TCivilTime<ECivilUnit::Day>(2017, 1, 11), TCivilDay(2017, 1, 11));
-
- NDatetime::TCivilSecond s(2017, 2, 1, 10, 12, 9);
-
- UNIT_ASSERT_VALUES_EQUAL(
- NDatetime::AddCivil(s, TCivilDiff{2, ECivilUnit::Day}),
- NDatetime::AddDays(s, 2));
- UNIT_ASSERT_VALUES_EQUAL(
- NDatetime::AddCivil(s, TCivilDiff{-2, ECivilUnit::Month}),
- NDatetime::AddMonths(s, -2));
- UNIT_ASSERT_VALUES_EQUAL(
- NDatetime::AddCivil(s, TCivilDiff{-55, ECivilUnit::Year}),
- NDatetime::AddYears(s, -55));
- UNIT_ASSERT_VALUES_EQUAL(
- NDatetime::AddCivil(s, TCivilDiff{40, ECivilUnit::Hour}),
- NDatetime::AddHours(s, 40));
-
- UNIT_ASSERT_VALUES_EQUAL(
- GetCivilDiff(TCivilSecond(2017, 10), TCivilSecond(2017, 7), ECivilUnit::Month),
- TCivilDiff(3, ECivilUnit::Month));
-
- UNIT_ASSERT_VALUES_EQUAL(
- GetCivilDiff(TCivilSecond(2017, 10, 1), TCivilSecond(2017, 9, 30), ECivilUnit::Month),
- TCivilDiff(1, ECivilUnit::Month));
-
- UNIT_ASSERT_VALUES_EQUAL(
- GetCivilDiff(TCivilSecond(2017, 10, 1), TCivilSecond(2017, 9, 31), ECivilUnit::Month),
- TCivilDiff(0, ECivilUnit::Month));
- }
+ using namespace NDatetime;
+
+ UNIT_ASSERT_VALUES_EQUAL(GetCivilUnit<TCivilMonth>(), ECivilUnit::Month);
+ UNIT_ASSERT_VALUES_EQUAL(GetCivilUnit(TCivilHour{}), ECivilUnit::Hour);
+
+ UNIT_ASSERT_VALUES_EQUAL(TCivilTime<ECivilUnit::Day>(2017, 1, 11), TCivilDay(2017, 1, 11));
+
+ NDatetime::TCivilSecond s(2017, 2, 1, 10, 12, 9);
+
+ UNIT_ASSERT_VALUES_EQUAL(
+ NDatetime::AddCivil(s, TCivilDiff{2, ECivilUnit::Day}),
+ NDatetime::AddDays(s, 2));
+ UNIT_ASSERT_VALUES_EQUAL(
+ NDatetime::AddCivil(s, TCivilDiff{-2, ECivilUnit::Month}),
+ NDatetime::AddMonths(s, -2));
+ UNIT_ASSERT_VALUES_EQUAL(
+ NDatetime::AddCivil(s, TCivilDiff{-55, ECivilUnit::Year}),
+ NDatetime::AddYears(s, -55));
+ UNIT_ASSERT_VALUES_EQUAL(
+ NDatetime::AddCivil(s, TCivilDiff{40, ECivilUnit::Hour}),
+ NDatetime::AddHours(s, 40));
+
+ UNIT_ASSERT_VALUES_EQUAL(
+ GetCivilDiff(TCivilSecond(2017, 10), TCivilSecond(2017, 7), ECivilUnit::Month),
+ TCivilDiff(3, ECivilUnit::Month));
+
+ UNIT_ASSERT_VALUES_EQUAL(
+ GetCivilDiff(TCivilSecond(2017, 10, 1), TCivilSecond(2017, 9, 30), ECivilUnit::Month),
+ TCivilDiff(1, ECivilUnit::Month));
+
+ UNIT_ASSERT_VALUES_EQUAL(
+ GetCivilDiff(TCivilSecond(2017, 10, 1), TCivilSecond(2017, 9, 31), ECivilUnit::Month),
+ TCivilDiff(0, ECivilUnit::Month));
+ }
Y_UNIT_TEST(TestYearWeekNmb) {
diff --git a/library/cpp/timezone_conversion/ya.make b/library/cpp/timezone_conversion/ya.make
index b0412c6932..f99ebe73ee 100644
--- a/library/cpp/timezone_conversion/ya.make
+++ b/library/cpp/timezone_conversion/ya.make
@@ -15,8 +15,8 @@ SRCS(
civil.cpp
)
-GENERATE_ENUM_SERIALIZATION(civil.h)
-
+GENERATE_ENUM_SERIALIZATION(civil.h)
+
END()
RECURSE_FOR_TESTS(ut)