aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/timezone_conversion/convert.cpp
diff options
context:
space:
mode:
authorpetrk <petrk@yandex-team.ru>2022-02-10 16:47:26 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:26 +0300
commitaf66956edf116b93d5a07894ccb61dd4447d0b34 (patch)
tree7b4cde47a2b3630f5a3048855949c4d46b893fc0 /library/cpp/timezone_conversion/convert.cpp
parentdc5feacd15e76abe98d23fe0d4ea3c02cb8de60f (diff)
downloadydb-af66956edf116b93d5a07894ccb61dd4447d0b34.tar.gz
Restoring authorship annotation for <petrk@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/timezone_conversion/convert.cpp')
-rw-r--r--library/cpp/timezone_conversion/convert.cpp82
1 files changed, 41 insertions, 41 deletions
diff --git a/library/cpp/timezone_conversion/convert.cpp b/library/cpp/timezone_conversion/convert.cpp
index 490bb4e2700..d668362788c 100644
--- a/library/cpp/timezone_conversion/convert.cpp
+++ b/library/cpp/timezone_conversion/convert.cpp
@@ -1,7 +1,7 @@
#include "convert.h"
#include <contrib/libs/cctz/include/cctz/civil_time.h>
-
+
#include <util/generic/yexception.h>
#include <chrono>
@@ -9,23 +9,23 @@
namespace NDatetime {
static constexpr i64 TM_YEAR_OFFSET = 1900;
using TSystemClock = std::chrono::system_clock;
- using TTimePoint = std::chrono::time_point<TSystemClock>;
-
- static TSimpleTM CivilToTM(const cctz::civil_second& cs, const cctz::time_zone::absolute_lookup& al) {
- cctz::civil_day cd(cs);
- TSimpleTM tm;
- tm.GMTOff = al.offset;
- tm.Year = cs.year() - TM_YEAR_OFFSET;
- tm.YDay = cctz::get_yearday(cd);
- tm.Mon = cs.month() - 1;
- tm.MDay = cs.day();
- tm.Hour = cs.hour();
- tm.Min = cs.minute();
- tm.Sec = cs.second();
- tm.IsDst = al.is_dst;
- tm.IsLeap = LeapYearAD(cs.year());
+ using TTimePoint = std::chrono::time_point<TSystemClock>;
- switch (cctz::get_weekday(cd)) {
+ static TSimpleTM CivilToTM(const cctz::civil_second& cs, const cctz::time_zone::absolute_lookup& al) {
+ cctz::civil_day cd(cs);
+ TSimpleTM tm;
+ tm.GMTOff = al.offset;
+ tm.Year = cs.year() - TM_YEAR_OFFSET;
+ tm.YDay = cctz::get_yearday(cd);
+ tm.Mon = cs.month() - 1;
+ tm.MDay = cs.day();
+ tm.Hour = cs.hour();
+ tm.Min = cs.minute();
+ tm.Sec = cs.second();
+ tm.IsDst = al.is_dst;
+ tm.IsLeap = LeapYearAD(cs.year());
+
+ switch (cctz::get_weekday(cd)) {
case cctz::weekday::monday:
tm.WDay = 1;
break;
@@ -47,47 +47,47 @@ namespace NDatetime {
case cctz::weekday::sunday:
tm.WDay = 0;
break;
- }
-
- return tm;
- }
-
- /*
+ }
+
+ return tm;
+ }
+
+ /*
TTimeZone GetTimeZone(const TString& name) {
TTimeZone result;
- if (!cctz::load_time_zone(name, &result)) {
- ythrow yexception() << "Failed to load time zone " << name << ", " << result.name();
+ if (!cctz::load_time_zone(name, &result)) {
+ ythrow yexception() << "Failed to load time zone " << name << ", " << result.name();
}
return result;
}
- */
+ */
TTimeZone GetUtcTimeZone() {
- return cctz::utc_time_zone();
+ return cctz::utc_time_zone();
}
TTimeZone GetLocalTimeZone() {
- return cctz::local_time_zone();
+ return cctz::local_time_zone();
}
TSimpleTM ToCivilTime(const TInstant& absoluteTime, const TTimeZone& tz) {
- TTimePoint tp = TSystemClock::from_time_t(absoluteTime.TimeT());
- return CivilToTM(cctz::convert(tp, tz), tz.lookup(tp));
- }
+ TTimePoint tp = TSystemClock::from_time_t(absoluteTime.TimeT());
+ return CivilToTM(cctz::convert(tp, tz), tz.lookup(tp));
+ }
- TSimpleTM CreateCivilTime(const TTimeZone& tz, ui32 year, ui32 mon, ui32 day, ui32 h, ui32 m, ui32 s) {
- cctz::civil_second cs(year, mon, day, h, m, s);
- return CivilToTM(cs, tz.lookup(tz.lookup(cs).pre));
+ TSimpleTM CreateCivilTime(const TTimeZone& tz, ui32 year, ui32 mon, ui32 day, ui32 h, ui32 m, ui32 s) {
+ cctz::civil_second cs(year, mon, day, h, m, s);
+ return CivilToTM(cs, tz.lookup(tz.lookup(cs).pre));
}
TInstant ToAbsoluteTime(const TSimpleTM& civilTime, const TTimeZone& tz) {
- cctz::civil_second cs(
- civilTime.Year + TM_YEAR_OFFSET,
- civilTime.Mon + 1,
- civilTime.MDay,
- civilTime.Hour,
- civilTime.Min,
+ cctz::civil_second cs(
+ civilTime.Year + TM_YEAR_OFFSET,
+ civilTime.Mon + 1,
+ civilTime.MDay,
+ civilTime.Hour,
+ civilTime.Min,
civilTime.Sec);
- return TInstant::Seconds(TSystemClock::to_time_t(tz.lookup(cs).pre));
+ return TInstant::Seconds(TSystemClock::to_time_t(tz.lookup(cs).pre));
}
}