aboutsummaryrefslogtreecommitdiffstats
path: root/util/draft
diff options
context:
space:
mode:
authorRuslan Kovalev <ruslan.a.kovalev@gmail.com>2022-02-10 16:46:45 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:45 +0300
commit9123176b341b6f2658cff5132482b8237c1416c8 (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /util/draft
parent59e19371de37995fcb36beb16cd6ec030af960bc (diff)
downloadydb-9123176b341b6f2658cff5132482b8237c1416c8.tar.gz
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util/draft')
-rw-r--r--util/draft/date.h6
-rw-r--r--util/draft/datetime.cpp232
-rw-r--r--util/draft/datetime.h150
-rw-r--r--util/draft/datetime_ut.cpp368
-rw-r--r--util/draft/enum.h2
-rw-r--r--util/draft/holder_vector.h2
-rw-r--r--util/draft/matrix.h2
-rw-r--r--util/draft/ya.make2
8 files changed, 382 insertions, 382 deletions
diff --git a/util/draft/date.h b/util/draft/date.h
index 4f7942ed79..e3eb616fe5 100644
--- a/util/draft/date.h
+++ b/util/draft/date.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
#include <util/stream/output.h>
#include <util/stream/input.h>
@@ -7,8 +7,8 @@
#include <ctime>
-// XXX: uses system calls for trivial things. may be very slow therefore.
-
+// XXX: uses system calls for trivial things. may be very slow therefore.
+
time_t GetDateStart(time_t ts);
// Local date (without time zone)
diff --git a/util/draft/datetime.cpp b/util/draft/datetime.cpp
index 401d6eda1e..5cbe7d8847 100644
--- a/util/draft/datetime.cpp
+++ b/util/draft/datetime.cpp
@@ -1,27 +1,27 @@
-#include "datetime.h"
-
+#include "datetime.h"
+
#include <util/ysaveload.h>
-#include <util/system/atomic.h>
-#include <util/system/fasttime.h>
-#include <util/datetime/base.h>
-#include <util/datetime/systime.h>
+#include <util/system/atomic.h>
+#include <util/system/fasttime.h>
+#include <util/datetime/base.h>
+#include <util/datetime/systime.h>
#include <util/stream/output.h>
#include <util/stream/mem.h>
#include <util/string/cast.h>
#include <util/string/printf.h>
-
-namespace NDatetime {
- const ui32 MonthDays[2][12] = {
+
+namespace NDatetime {
+ const ui32 MonthDays[2][12] = {
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, //nleap
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} //leap
- };
-
+ };
+
const ui32 MonthDaysNewYear[2][13] = {
{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, //nleap
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366} //leap
- };
-
+ };
+
void YDayToMonthAndDay(ui32 yday, bool isleap, ui32* month, ui32* mday) {
const ui32* begin = MonthDaysNewYear[isleap] + 1;
const ui32* end = begin + 12;
@@ -36,60 +36,60 @@ namespace NDatetime {
Y_ASSERT((*month < 12) && (1 <= *mday) && (*mday <= MonthDays[isleap][*month]));
}
- struct TTimeData {
- i32 IsDst = 0;
- i32 GMTOff = 0;
-
- TTimeData(time_t t) {
- struct ::tm tt;
- ::localtime_r(&t, &tt);
-#ifndef _win_
- GMTOff = tt.tm_gmtoff;
+ struct TTimeData {
+ i32 IsDst = 0;
+ i32 GMTOff = 0;
+
+ TTimeData(time_t t) {
+ struct ::tm tt;
+ ::localtime_r(&t, &tt);
+#ifndef _win_
+ GMTOff = tt.tm_gmtoff;
#else
- TIME_ZONE_INFORMATION tz;
- switch (GetTimeZoneInformation(&tz)) {
- case TIME_ZONE_ID_UNKNOWN:
- GMTOff = tz.Bias * -60;
- break;
- case TIME_ZONE_ID_STANDARD:
- GMTOff = (tz.Bias + tz.StandardBias) * -60;
- break;
- case TIME_ZONE_ID_DAYLIGHT:
- GMTOff = (tz.Bias + tz.DaylightBias) * -60;
- break;
- default:
- break;
- }
+ TIME_ZONE_INFORMATION tz;
+ switch (GetTimeZoneInformation(&tz)) {
+ case TIME_ZONE_ID_UNKNOWN:
+ GMTOff = tz.Bias * -60;
+ break;
+ case TIME_ZONE_ID_STANDARD:
+ GMTOff = (tz.Bias + tz.StandardBias) * -60;
+ break;
+ case TIME_ZONE_ID_DAYLIGHT:
+ GMTOff = (tz.Bias + tz.DaylightBias) * -60;
+ break;
+ default:
+ break;
+ }
#endif
- IsDst = tt.tm_isdst;
+ IsDst = tt.tm_isdst;
}
};
- TSimpleTM TSimpleTM::CurrentUTC() {
- return New((time_t)TInstant::MicroSeconds(InterpolatedMicroSeconds()).Seconds());
- }
-
- TSimpleTM TSimpleTM::New(time_t t, i32 gmtoff, i8 isdst) {
- time_t tt = t + gmtoff + isdst * 3600;
- struct tm tmSys;
- Zero(tmSys);
- GmTimeR(&tt, &tmSys);
- tmSys.tm_isdst = isdst;
-#ifndef _win_
- tmSys.tm_gmtoff = gmtoff;
-#endif
-
- return New(tmSys);
+ TSimpleTM TSimpleTM::CurrentUTC() {
+ return New((time_t)TInstant::MicroSeconds(InterpolatedMicroSeconds()).Seconds());
}
-
- TSimpleTM TSimpleTM::NewLocal(time_t t) {
- TTimeData d(t);
- return New(t, d.GMTOff, d.IsDst);
+
+ TSimpleTM TSimpleTM::New(time_t t, i32 gmtoff, i8 isdst) {
+ time_t tt = t + gmtoff + isdst * 3600;
+ struct tm tmSys;
+ Zero(tmSys);
+ GmTimeR(&tt, &tmSys);
+ tmSys.tm_isdst = isdst;
+#ifndef _win_
+ tmSys.tm_gmtoff = gmtoff;
+#endif
+
+ return New(tmSys);
+ }
+
+ TSimpleTM TSimpleTM::NewLocal(time_t t) {
+ TTimeData d(t);
+ return New(t, d.GMTOff, d.IsDst);
}
-
+
TSimpleTM TSimpleTM::New(const struct tm& t) {
TSimpleTM res;
- res.IsDst = t.tm_isdst;
+ res.IsDst = t.tm_isdst;
res.Sec = t.tm_sec;
res.Min = t.tm_min;
res.Hour = t.tm_hour;
@@ -98,39 +98,39 @@ namespace NDatetime {
res.MDay = t.tm_mday;
res.Year = t.tm_year;
res.YDay = t.tm_yday;
- res.IsLeap = LeapYearAD(res.Year + 1900);
-#ifndef _win_
+ res.IsLeap = LeapYearAD(res.Year + 1900);
+#ifndef _win_
res.GMTOff = t.tm_gmtoff;
-#endif
+#endif
return res;
}
-
- TSimpleTM& TSimpleTM::SetRealDate(ui32 year, ui32 mon, ui32 mday, ui32 hour, ui32 min, ui32 sec, i32 isdst) {
- mday = ::Max<ui32>(mday, 1);
- mon = ::Min<ui32>(::Max<ui32>(mon, 1), 12);
- year = ::Max<ui32>(year, 1900);
-
- IsLeap = LeapYearAD(year);
- Year = year - 1900;
- Mon = mon - 1;
- MDay = ::Min<ui32>(mday, MonthDays[IsLeap][Mon]);
- Hour = Max<ui32>() == hour ? Hour : ::Min<ui32>(hour, 23);
- Min = Max<ui32>() == min ? Min : ::Min<ui32>(min, 59);
- Sec = Max<ui32>() == sec ? Sec : ::Min<ui32>(sec, 60);
- IsDst = isdst;
-
- return RegenerateFields();
- }
-
- TSimpleTM& TSimpleTM::RegenerateFields() {
+
+ TSimpleTM& TSimpleTM::SetRealDate(ui32 year, ui32 mon, ui32 mday, ui32 hour, ui32 min, ui32 sec, i32 isdst) {
+ mday = ::Max<ui32>(mday, 1);
+ mon = ::Min<ui32>(::Max<ui32>(mon, 1), 12);
+ year = ::Max<ui32>(year, 1900);
+
+ IsLeap = LeapYearAD(year);
+ Year = year - 1900;
+ Mon = mon - 1;
+ MDay = ::Min<ui32>(mday, MonthDays[IsLeap][Mon]);
+ Hour = Max<ui32>() == hour ? Hour : ::Min<ui32>(hour, 23);
+ Min = Max<ui32>() == min ? Min : ::Min<ui32>(min, 59);
+ Sec = Max<ui32>() == sec ? Sec : ::Min<ui32>(sec, 60);
+ IsDst = isdst;
+
+ return RegenerateFields();
+ }
+
+ TSimpleTM& TSimpleTM::RegenerateFields() {
return *this = New(AsTimeT(), GMTOff, IsDst);
- }
-
+ }
+
TSimpleTM& TSimpleTM::Add(EField f, i32 amount) {
if (!amount) {
return *this;
}
-
+
switch (f) {
default:
return *this;
@@ -143,59 +143,59 @@ namespace NDatetime {
case F_MIN:
amount *= 60;
[[fallthrough]];
- case F_SEC: {
+ case F_SEC: {
return *this = New(AsTimeT() + amount, GMTOff, IsDst);
- }
+ }
case F_YEAR: {
i32 y = amount + (i32)Year;
y = ::Min<i32>(Max<i32>(y, 0), 255 /*max year*/);
-
+
// YDay may correspond to different MDay if it's March or greater and the years have different leap status
if (Mon > 1) {
- YDay += (i32)LeapYearAD(RealYear()) - (i32)LeapYearAD(RealYear());
+ YDay += (i32)LeapYearAD(RealYear()) - (i32)LeapYearAD(RealYear());
}
-
+
Year = y;
- IsLeap = LeapYearAD(RealYear());
- return RegenerateFields();
+ IsLeap = LeapYearAD(RealYear());
+ return RegenerateFields();
}
case F_MON: {
i32 m = amount + Mon;
i32 y = (m < 0 ? (-12 + m) : m) / 12;
m = m - y * 12;
-
- if (y) {
+
+ if (y) {
Add(F_YEAR, y);
- }
-
+ }
+
if (m >= 0 && m < 12) {
MDay = ::Min<ui32>(MonthDays[IsLeap][m], MDay);
- Mon = m;
+ Mon = m;
}
- return RegenerateFields();
+ return RegenerateFields();
}
- }
- }
+ }
+ }
TString TSimpleTM::ToString(const char* fmt) const {
struct tm t = *this;
- return Strftime(fmt, &t);
- }
-
- time_t TSimpleTM::AsTimeT() const {
- struct tm t = AsStructTmLocal();
- return TimeGM(&t) - GMTOff - IsDst * 3600;
+ return Strftime(fmt, &t);
}
-
- struct tm TSimpleTM::AsStructTmUTC() const {
- struct tm res;
- Zero(res);
- time_t t = AsTimeT();
- return *GmTimeR(&t, &res);
- }
-
- struct tm TSimpleTM::AsStructTmLocal() const {
+
+ time_t TSimpleTM::AsTimeT() const {
+ struct tm t = AsStructTmLocal();
+ return TimeGM(&t) - GMTOff - IsDst * 3600;
+ }
+
+ struct tm TSimpleTM::AsStructTmUTC() const {
+ struct tm res;
+ Zero(res);
+ time_t t = AsTimeT();
+ return *GmTimeR(&t, &res);
+ }
+
+ struct tm TSimpleTM::AsStructTmLocal() const {
struct tm t;
Zero(t);
t.tm_isdst = IsDst;
@@ -207,12 +207,12 @@ namespace NDatetime {
t.tm_mday = MDay;
t.tm_year = Year;
t.tm_yday = YDay;
-#ifndef _win_
+#ifndef _win_
t.tm_gmtoff = GMTOff;
-#endif
+#endif
return t;
}
-}
+}
template <>
void In<TMonth>(IInputStream& in, TMonth& t) {
diff --git a/util/draft/datetime.h b/util/draft/datetime.h
index 58a64b16ee..8a387ea6f1 100644
--- a/util/draft/datetime.h
+++ b/util/draft/datetime.h
@@ -1,32 +1,32 @@
-#pragma once
-
-#include <util/generic/algorithm.h>
+#pragma once
+
+#include <util/generic/algorithm.h>
#include <util/generic/string.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include <util/generic/ymath.h>
#include <util/datetime/base.h>
-
+
#include <cstdlib>
#include <time.h>
-namespace NDatetime {
+namespace NDatetime {
extern const ui32 MonthDays[2][12]; // !leapYear; !!leapYear
extern const ui32 MonthDaysNewYear[2][13]; // !leapYear; !!leapYear
-
+
inline ui32 YearDaysAD(ui32 year) {
year = Max<ui32>(year, 1) - 1; //1 AD comes straight after 1 BC, no 0 AD
return year * 365 + year / 4 - year / 100 + year / 400;
}
-
+
inline bool LeapYearAD(ui32 year) {
- return (!(year % 4) && (year % 100)) || !(year % 400);
+ return (!(year % 4) && (year % 100)) || !(year % 400);
}
-
+
inline ui32 YDayFromMonthAndDay(ui32 month /*0 - based*/, ui32 mday /*1 - based*/, bool isleap) {
return MonthDaysNewYear[isleap][Min(month, (ui32)11u)] + mday - 1;
}
-
+
void YDayToMonthAndDay(ui32 yday /*0 - based*/, bool isleap, ui32* month /*0 - based*/, ui32* mday /*1 - based*/);
struct TSimpleTM {
@@ -39,111 +39,111 @@ namespace NDatetime {
F_MON,
F_YEAR
};
-
- i32 GMTOff = 0; // -43200 - 50400 seconds
- ui16 Year = 0; // from 1900
- ui16 YDay = 0; // 0-365
- ui8 Mon = 0; // 0-11
- ui8 MDay = 0; // 1-31
- ui8 WDay = 0; // 0-6
- ui8 Hour = 0; // 0-23
- ui8 Min = 0; // 0-59
- ui8 Sec = 0; // 0-60 - doesn't care for leap seconds. Most of the time it's ok.
- i8 IsDst = 0; // -1/0/1
- bool IsLeap = false;
-
- public:
- static TSimpleTM New(time_t t = 0, i32 gmtoff = 0, i8 isdst = 0);
- static TSimpleTM NewLocal(time_t = 0);
-
+
+ i32 GMTOff = 0; // -43200 - 50400 seconds
+ ui16 Year = 0; // from 1900
+ ui16 YDay = 0; // 0-365
+ ui8 Mon = 0; // 0-11
+ ui8 MDay = 0; // 1-31
+ ui8 WDay = 0; // 0-6
+ ui8 Hour = 0; // 0-23
+ ui8 Min = 0; // 0-59
+ ui8 Sec = 0; // 0-60 - doesn't care for leap seconds. Most of the time it's ok.
+ i8 IsDst = 0; // -1/0/1
+ bool IsLeap = false;
+
+ public:
+ static TSimpleTM New(time_t t = 0, i32 gmtoff = 0, i8 isdst = 0);
+ static TSimpleTM NewLocal(time_t = 0);
+
static TSimpleTM New(const struct tm&);
-
- static TSimpleTM CurrentUTC();
-
- TSimpleTM() = default;
-
+
+ static TSimpleTM CurrentUTC();
+
+ TSimpleTM() = default;
+
TSimpleTM(ui32 year, ui32 mon, ui32 day, ui32 h = 0, ui32 m = 0, ui32 s = 0) {
Zero(*this);
SetRealDate(year, mon, day, h, m, s);
}
-
+
// keeps the object consistent
TSimpleTM& Add(EField f, i32 amount = 1);
-
+
TString ToString(const char* fmt = "%a, %d %b %Y %H:%M:%S %z") const;
-
- TSimpleTM& ToUTC() {
+
+ TSimpleTM& ToUTC() {
return *this = New(AsTimeT());
- }
-
- bool IsUTC() const {
- return !IsDst && !GMTOff;
- }
-
- time_t AsTimeT() const;
-
- operator time_t() const {
- return AsTimeT();
- };
-
- struct tm AsStructTmLocal() const;
-
- struct tm AsStructTmUTC() const;
-
- operator struct tm() const {
- return AsStructTmLocal();
- }
-
+ }
+
+ bool IsUTC() const {
+ return !IsDst && !GMTOff;
+ }
+
+ time_t AsTimeT() const;
+
+ operator time_t() const {
+ return AsTimeT();
+ };
+
+ struct tm AsStructTmLocal() const;
+
+ struct tm AsStructTmUTC() const;
+
+ operator struct tm() const {
+ return AsStructTmLocal();
+ }
+
ui32 RealYear() const {
return ui32(Year + 1900);
}
-
+
ui32 RealMonth() const {
return ui32(Mon + 1);
}
-
- TSimpleTM& SetRealDate(ui32 year, ui32 mon, ui32 mday, ui32 hour = -1, ui32 min = -1, ui32 sec = -1, i32 isdst = 0);
-
- // regenerates all fields from Year, MDay, Hour, Min, Sec, IsDst, GMTOffset
- TSimpleTM& RegenerateFields();
-
+
+ TSimpleTM& SetRealDate(ui32 year, ui32 mon, ui32 mday, ui32 hour = -1, ui32 min = -1, ui32 sec = -1, i32 isdst = 0);
+
+ // regenerates all fields from Year, MDay, Hour, Min, Sec, IsDst, GMTOffset
+ TSimpleTM& RegenerateFields();
+
friend bool operator==(const TSimpleTM& a, const TSimpleTM& b) {
- return a.AsTimeT() == b.AsTimeT();
+ return a.AsTimeT() == b.AsTimeT();
}
-
+
friend bool operator==(const TSimpleTM& s, const struct tm& t) {
return s == New(t);
}
-
+
friend bool operator==(const struct tm& t, const TSimpleTM& s) {
return s == t;
}
-
+
friend bool operator!=(const TSimpleTM& a, const TSimpleTM& b) {
return !(a == b);
}
-
+
friend bool operator!=(const TSimpleTM& s, const struct tm& t) {
return !(s == t);
}
-
+
friend bool operator!=(const struct tm& t, const TSimpleTM& s) {
return s != t;
}
};
-}
+}
inline TString date2str(const time_t date) {
- struct tm dateTm;
- memset(&dateTm, 0, sizeof(dateTm));
- localtime_r(&date, &dateTm);
+ struct tm dateTm;
+ memset(&dateTm, 0, sizeof(dateTm));
+ localtime_r(&date, &dateTm);
char buf[9];
strftime(buf, sizeof(buf), "%Y%m%d", &dateTm);
return TString(buf);
}
inline time_t str2date(const TString& dateStr) {
- struct tm dateTm;
+ struct tm dateTm;
memset(&dateTm, 0, sizeof(tm));
strptime(dateStr.data(), "%Y%m%d", &dateTm);
return mktime(&dateTm);
diff --git a/util/draft/datetime_ut.cpp b/util/draft/datetime_ut.cpp
index f959848d5e..a5e065ef6e 100644
--- a/util/draft/datetime_ut.cpp
+++ b/util/draft/datetime_ut.cpp
@@ -1,66 +1,66 @@
#include "datetime.h"
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <util/string/builder.h>
Y_UNIT_TEST_SUITE(TSimpleTMTest) {
TString PrintMarker(const TString& test, int line) {
return TStringBuilder() << "test " << test << " at line " << line;
- }
-
+ }
+
TString JoinMarker(const TString& marker, time_t t) {
return TStringBuilder() << marker << " (tstamp=" << t << ")";
- }
-
+ }
+
TString PrintMarker(const TString& test, int line, time_t t) {
- return JoinMarker(PrintMarker(test, line), t);
- }
-
+ return JoinMarker(PrintMarker(test, line), t);
+ }
+
void AssertStructTmEqual(const TString& marker, const struct tm& tmt, const NDatetime::TSimpleTM& tms) {
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Sec, tmt.tm_sec, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Min, tmt.tm_min, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Hour, tmt.tm_hour, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.WDay, tmt.tm_wday, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.MDay, tmt.tm_mday, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Mon, tmt.tm_mon, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.YDay, tmt.tm_yday, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Year, tmt.tm_year, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.IsDst, tmt.tm_isdst, marker);
-#ifndef _win_
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.GMTOff, tmt.tm_gmtoff, marker);
-#endif
- }
-
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Sec, tmt.tm_sec, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Min, tmt.tm_min, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Hour, tmt.tm_hour, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.WDay, tmt.tm_wday, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.MDay, tmt.tm_mday, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Mon, tmt.tm_mon, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.YDay, tmt.tm_yday, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Year, tmt.tm_year, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.IsDst, tmt.tm_isdst, marker);
+#ifndef _win_
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.GMTOff, tmt.tm_gmtoff, marker);
+#endif
+ }
+
void AssertSimpleTM(const TString& mark,
- const NDatetime::TSimpleTM& tms,
- time_t tstamp, ui32 year, ui32 mon, ui32 mday, ui32 hour, ui32 minu, ui32 sec) {
+ const NDatetime::TSimpleTM& tms,
+ time_t tstamp, ui32 year, ui32 mon, ui32 mday, ui32 hour, ui32 minu, ui32 sec) {
TString marker = JoinMarker(mark, tstamp);
- struct tm tmt;
- Zero(tmt);
- GmTimeR(&tstamp, &tmt);
- AssertStructTmEqual(marker, tmt, tms);
- tmt = tms.AsStructTmUTC();
- time_t tstamp1 = TimeGM(&tmt);
- UNIT_ASSERT_VALUES_EQUAL_C(tstamp, tstamp1, marker);
- UNIT_ASSERT_VALUES_EQUAL_C(tstamp, tms.AsTimeT(), marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.RealYear(), year, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.RealMonth(), mon, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.MDay, mday, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Hour, hour, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Min, minu, marker);
- UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Sec, sec, marker);
- }
-
+ struct tm tmt;
+ Zero(tmt);
+ GmTimeR(&tstamp, &tmt);
+ AssertStructTmEqual(marker, tmt, tms);
+ tmt = tms.AsStructTmUTC();
+ time_t tstamp1 = TimeGM(&tmt);
+ UNIT_ASSERT_VALUES_EQUAL_C(tstamp, tstamp1, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C(tstamp, tms.AsTimeT(), marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.RealYear(), year, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.RealMonth(), mon, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.MDay, mday, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Hour, hour, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Min, minu, marker);
+ UNIT_ASSERT_VALUES_EQUAL_C((int)tms.Sec, sec, marker);
+ }
+
Y_UNIT_TEST(TestLeap) {
- using namespace NDatetime;
+ using namespace NDatetime;
UNIT_ASSERT(LeapYearAD(2000));
UNIT_ASSERT(LeapYearAD(2012));
UNIT_ASSERT(!LeapYearAD(1999));
UNIT_ASSERT(LeapYearAD(2004));
UNIT_ASSERT(!LeapYearAD(1900));
- }
-
+ }
+
Y_UNIT_TEST(TestYDayConversion) {
using namespace NDatetime;
ui32 month;
@@ -81,151 +81,151 @@ Y_UNIT_TEST_SUITE(TSimpleTMTest) {
Y_UNIT_TEST(SimpleTMTest) {
using namespace NDatetime;
-
- tzset();
-
- TSimpleTM::New(-1); //should not die here
-
- UNIT_ASSERT_VALUES_EQUAL((ui32)0, (ui32)TSimpleTM::New(0));
- UNIT_ASSERT((ui32)TSimpleTM::New(0).IsUTC());
+
+ tzset();
+
+ TSimpleTM::New(-1); //should not die here
+
+ UNIT_ASSERT_VALUES_EQUAL((ui32)0, (ui32)TSimpleTM::New(0));
+ UNIT_ASSERT((ui32)TSimpleTM::New(0).IsUTC());
time_t t = time(nullptr);
-
+
{
- struct tm tmt;
- Zero(tmt);
- gmtime_r(&t, &tmt);
+ struct tm tmt;
+ Zero(tmt);
+ gmtime_r(&t, &tmt);
UNIT_ASSERT_VALUES_EQUAL_C((i64)t, (i64)TSimpleTM::New(t).AsTimeT(), ToString(t)); // time_t -> gmt tm -> time_t
- UNIT_ASSERT_VALUES_EQUAL_C((i64)t, (i64)TSimpleTM::New(tmt).AsTimeT(), ToString(t)); // gmt tm -> time_t
- AssertStructTmEqual(PrintMarker("UTC:time_t", __LINE__, t),
- tmt, TSimpleTM::New(t));
- AssertStructTmEqual(PrintMarker("UTC:tm", __LINE__, t),
- tmt, TSimpleTM::New(tmt));
- UNIT_ASSERT(TSimpleTM::New(t).IsUTC());
- UNIT_ASSERT(TSimpleTM::New(tmt).IsUTC());
+ UNIT_ASSERT_VALUES_EQUAL_C((i64)t, (i64)TSimpleTM::New(tmt).AsTimeT(), ToString(t)); // gmt tm -> time_t
+ AssertStructTmEqual(PrintMarker("UTC:time_t", __LINE__, t),
+ tmt, TSimpleTM::New(t));
+ AssertStructTmEqual(PrintMarker("UTC:tm", __LINE__, t),
+ tmt, TSimpleTM::New(tmt));
+ UNIT_ASSERT(TSimpleTM::New(t).IsUTC());
+ UNIT_ASSERT(TSimpleTM::New(tmt).IsUTC());
}
-
- {
- struct tm tmt;
- Zero(tmt);
- localtime_r(&t, &tmt);
-
- UNIT_ASSERT_VALUES_EQUAL((i64)t, (i64)TSimpleTM::NewLocal(t).AsTimeT()); // time_t -> local tm -> time_t
- UNIT_ASSERT_VALUES_EQUAL((i64)t, (i64)TSimpleTM::New(tmt).AsTimeT());
- AssertStructTmEqual(PrintMarker("local:time_t", __LINE__, t),
- tmt, TSimpleTM::NewLocal(t));
- AssertStructTmEqual(PrintMarker("local:tm", __LINE__, t),
- tmt, TSimpleTM::New(tmt));
- AssertStructTmEqual(PrintMarker("local:tm:RegenerateFields", __LINE__, t),
- tmt, TSimpleTM::New(tmt).RegenerateFields());
- AssertStructTmEqual(PrintMarker("local:time_t:SetRealDate", __LINE__, t),
+
+ {
+ struct tm tmt;
+ Zero(tmt);
+ localtime_r(&t, &tmt);
+
+ UNIT_ASSERT_VALUES_EQUAL((i64)t, (i64)TSimpleTM::NewLocal(t).AsTimeT()); // time_t -> local tm -> time_t
+ UNIT_ASSERT_VALUES_EQUAL((i64)t, (i64)TSimpleTM::New(tmt).AsTimeT());
+ AssertStructTmEqual(PrintMarker("local:time_t", __LINE__, t),
+ tmt, TSimpleTM::NewLocal(t));
+ AssertStructTmEqual(PrintMarker("local:tm", __LINE__, t),
+ tmt, TSimpleTM::New(tmt));
+ AssertStructTmEqual(PrintMarker("local:tm:RegenerateFields", __LINE__, t),
+ tmt, TSimpleTM::New(tmt).RegenerateFields());
+ AssertStructTmEqual(PrintMarker("local:time_t:SetRealDate", __LINE__, t),
tmt, TSimpleTM::NewLocal(t).SetRealDate(tmt.tm_year + 1900, tmt.tm_mon + 1, tmt.tm_mday, tmt.tm_hour, tmt.tm_min, tmt.tm_sec, tmt.tm_isdst));
- }
-
- {
- TSimpleTM tt = TSimpleTM::New(0);
-
- tt.SetRealDate(2012, 3, 30, 5, 6, 7);
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1333083967, 2012, 3, 30, 5, 6, 7);
-
- tt.SetRealDate(2012, 3, 8, 5, 6, 7);
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1331183167, 2012, 3, 8, 5, 6, 7);
-
- tt.SetRealDate(2010, 10, 4, 5, 6, 7);
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1286168767, 2010, 10, 4, 5, 6, 7);
-
- tt.Add(TSimpleTM::F_MON);
- AssertSimpleTM(PrintMarker("UTC:AddMonth", __LINE__),
- tt, 1288847167, 2010, 11, 4, 5, 6, 7);
-
- tt.Add(TSimpleTM::F_DAY);
- AssertSimpleTM(PrintMarker("UTC:AddDay", __LINE__),
- tt, 1288933567, 2010, 11, 5, 5, 6, 7);
-
- tt.Add(TSimpleTM::F_YEAR);
- AssertSimpleTM(PrintMarker("UTC:AddYear", __LINE__),
- tt, 1320469567, 2011, 11, 5, 5, 6, 7);
-
+ }
+
+ {
+ TSimpleTM tt = TSimpleTM::New(0);
+
+ tt.SetRealDate(2012, 3, 30, 5, 6, 7);
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1333083967, 2012, 3, 30, 5, 6, 7);
+
+ tt.SetRealDate(2012, 3, 8, 5, 6, 7);
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1331183167, 2012, 3, 8, 5, 6, 7);
+
+ tt.SetRealDate(2010, 10, 4, 5, 6, 7);
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1286168767, 2010, 10, 4, 5, 6, 7);
+
+ tt.Add(TSimpleTM::F_MON);
+ AssertSimpleTM(PrintMarker("UTC:AddMonth", __LINE__),
+ tt, 1288847167, 2010, 11, 4, 5, 6, 7);
+
+ tt.Add(TSimpleTM::F_DAY);
+ AssertSimpleTM(PrintMarker("UTC:AddDay", __LINE__),
+ tt, 1288933567, 2010, 11, 5, 5, 6, 7);
+
+ tt.Add(TSimpleTM::F_YEAR);
+ AssertSimpleTM(PrintMarker("UTC:AddYear", __LINE__),
+ tt, 1320469567, 2011, 11, 5, 5, 6, 7);
+
for (ui32 i = 0; i < 365; ++i) {
- tt.Add(TSimpleTM::F_DAY);
+ tt.Add(TSimpleTM::F_DAY);
}
-
- AssertSimpleTM(PrintMarker("UTC:365*AddDay", __LINE__),
- tt, 1352005567, 2012, 11, 4, 5, 6, 7);
-
- tt.Add(TSimpleTM::F_MON, -10);
- AssertSimpleTM(PrintMarker("UTC:AddMonth(-10)", __LINE__),
- tt, 1325653567, 2012, 1, 4, 5, 6, 7);
-
- tt.Add(TSimpleTM::F_HOUR, -24 * 4 - 6);
- AssertSimpleTM(PrintMarker("UTC:AddHour(-102)", __LINE__),
- tt, 1325286367, 2011, 12, 30, 23, 6, 7);
- }
-
- {
- TSimpleTM tt = TSimpleTM::New();
-
- tt.SetRealDate(2012, 2, 29);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1330473600, 2012, 2, 29, 0, 0, 0);
-
- tt.SetRealDate(2012, 2, 29);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1330473600, 2012, 2, 29, 0, 0, 0);
-
- tt.SetRealDate(2013, 12, 28);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1388188800, 2013, 12, 28, 0, 0, 0);
-
- tt.SetRealDate(2012, 10, 23);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1350950400, 2012, 10, 23, 0, 0, 0);
-
- tt.SetRealDate(2013, 3, 16);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1363392000, 2013, 3, 16, 0, 0, 0);
-
- tt.SetRealDate(2013, 2, 17);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1361059200, 2013, 2, 17, 0, 0, 0);
-
- tt.SetRealDate(2012, 12, 23);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1356220800, 2012, 12, 23, 0, 0, 0);
-
- tt.SetRealDate(2012, 5, 17);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1337212800, 2012, 5, 17, 0, 0, 0);
-
- tt.SetRealDate(2012, 6, 15);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1339718400, 2012, 6, 15, 0, 0, 0);
-
- tt.SetRealDate(2009, 3, 17);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1237248000, 2009, 3, 17, 0, 0, 0);
-
- tt.SetRealDate(2013, 8, 12);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1376265600, 2013, 8, 12, 0, 0, 0);
-
- tt.SetRealDate(2015, 12, 11, 10, 9, 8);
-
- AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
- tt, 1449828548, 2015, 12, 11, 10, 9, 8);
- }
- }
-}
+
+ AssertSimpleTM(PrintMarker("UTC:365*AddDay", __LINE__),
+ tt, 1352005567, 2012, 11, 4, 5, 6, 7);
+
+ tt.Add(TSimpleTM::F_MON, -10);
+ AssertSimpleTM(PrintMarker("UTC:AddMonth(-10)", __LINE__),
+ tt, 1325653567, 2012, 1, 4, 5, 6, 7);
+
+ tt.Add(TSimpleTM::F_HOUR, -24 * 4 - 6);
+ AssertSimpleTM(PrintMarker("UTC:AddHour(-102)", __LINE__),
+ tt, 1325286367, 2011, 12, 30, 23, 6, 7);
+ }
+
+ {
+ TSimpleTM tt = TSimpleTM::New();
+
+ tt.SetRealDate(2012, 2, 29);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1330473600, 2012, 2, 29, 0, 0, 0);
+
+ tt.SetRealDate(2012, 2, 29);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1330473600, 2012, 2, 29, 0, 0, 0);
+
+ tt.SetRealDate(2013, 12, 28);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1388188800, 2013, 12, 28, 0, 0, 0);
+
+ tt.SetRealDate(2012, 10, 23);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1350950400, 2012, 10, 23, 0, 0, 0);
+
+ tt.SetRealDate(2013, 3, 16);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1363392000, 2013, 3, 16, 0, 0, 0);
+
+ tt.SetRealDate(2013, 2, 17);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1361059200, 2013, 2, 17, 0, 0, 0);
+
+ tt.SetRealDate(2012, 12, 23);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1356220800, 2012, 12, 23, 0, 0, 0);
+
+ tt.SetRealDate(2012, 5, 17);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1337212800, 2012, 5, 17, 0, 0, 0);
+
+ tt.SetRealDate(2012, 6, 15);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1339718400, 2012, 6, 15, 0, 0, 0);
+
+ tt.SetRealDate(2009, 3, 17);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1237248000, 2009, 3, 17, 0, 0, 0);
+
+ tt.SetRealDate(2013, 8, 12);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1376265600, 2013, 8, 12, 0, 0, 0);
+
+ tt.SetRealDate(2015, 12, 11, 10, 9, 8);
+
+ AssertSimpleTM(PrintMarker("UTC:SetRealDate", __LINE__),
+ tt, 1449828548, 2015, 12, 11, 10, 9, 8);
+ }
+ }
+}
diff --git a/util/draft/enum.h b/util/draft/enum.h
index f1a80d4640..18002b7df2 100644
--- a/util/draft/enum.h
+++ b/util/draft/enum.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
#include <bitset>
diff --git a/util/draft/holder_vector.h b/util/draft/holder_vector.h
index 9b8c0db7eb..1c62055bd9 100644
--- a/util/draft/holder_vector.h
+++ b/util/draft/holder_vector.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
#include <util/generic/ptr.h>
#include <util/generic/vector.h>
diff --git a/util/draft/matrix.h b/util/draft/matrix.h
index 8ffc439393..154d00b35e 100644
--- a/util/draft/matrix.h
+++ b/util/draft/matrix.h
@@ -1,4 +1,4 @@
-#pragma once
+#pragma once
#include <util/generic/noncopyable.h>
#include <util/system/yassert.h>
diff --git a/util/draft/ya.make b/util/draft/ya.make
index 3201221981..e00674b682 100644
--- a/util/draft/ya.make
+++ b/util/draft/ya.make
@@ -11,7 +11,7 @@ ENDIF()
SRCS(
date.cpp
- datetime.cpp
+ datetime.cpp
enum.cpp
holder_vector.cpp
ip.cpp