diff options
author | petrk <petrk@yandex-team.ru> | 2022-02-10 16:47:26 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:26 +0300 |
commit | 1fe4b402b38f476dbe36f650c3049c92ae496d38 (patch) | |
tree | 9814fbd1c3effac9b8377c5d604b367b14e2db55 /library/cpp/timezone_conversion/convert.cpp | |
parent | af66956edf116b93d5a07894ccb61dd4447d0b34 (diff) | |
download | ydb-1fe4b402b38f476dbe36f650c3049c92ae496d38.tar.gz |
Restoring authorship annotation for <petrk@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/timezone_conversion/convert.cpp')
-rw-r--r-- | library/cpp/timezone_conversion/convert.cpp | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/library/cpp/timezone_conversion/convert.cpp b/library/cpp/timezone_conversion/convert.cpp index d668362788c..490bb4e2700 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>; + 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()); - 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)) { + 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)); } } |