aboutsummaryrefslogtreecommitdiffstats
path: root/util/draft/datetime.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/draft/datetime.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/draft/datetime.h')
-rw-r--r--util/draft/datetime.h128
1 files changed, 64 insertions, 64 deletions
diff --git a/util/draft/datetime.h b/util/draft/datetime.h
index 8a387ea6f1..b72b8d7c55 100644
--- a/util/draft/datetime.h
+++ b/util/draft/datetime.h
@@ -3,42 +3,42 @@
#include <util/generic/algorithm.h>
#include <util/generic/string.h>
#include <util/generic/yexception.h>
-#include <util/generic/ymath.h>
-#include <util/datetime/base.h>
-
-#include <cstdlib>
+#include <util/generic/ymath.h>
+#include <util/datetime/base.h>
+#include <cstdlib>
+
#include <time.h>
namespace NDatetime {
- extern const ui32 MonthDays[2][12]; // !leapYear; !!leapYear
+ 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 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) {
+ inline bool LeapYearAD(ui32 year) {
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;
- }
+ 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 {
- enum EField {
- F_NONE = 0,
- F_SEC,
- F_MIN,
- F_HOUR,
- F_DAY,
- F_MON,
- F_YEAR
- };
+ struct TSimpleTM {
+ enum EField {
+ F_NONE = 0,
+ F_SEC,
+ F_MIN,
+ F_HOUR,
+ F_DAY,
+ F_MON,
+ F_YEAR
+ };
i32 GMTOff = 0; // -43200 - 50400 seconds
ui16 Year = 0; // from 1900
@@ -56,24 +56,24 @@ namespace NDatetime {
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 New(const struct tm&);
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);
- }
+ 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);
+ // 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() {
- return *this = New(AsTimeT());
+ return *this = New(AsTimeT());
}
bool IsUTC() const {
@@ -94,43 +94,43 @@ namespace NDatetime {
return AsStructTmLocal();
}
- ui32 RealYear() const {
- return ui32(Year + 1900);
- }
+ ui32 RealYear() const {
+ return ui32(Year + 1900);
+ }
- ui32 RealMonth() const {
- return ui32(Mon + 1);
- }
+ 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();
- friend bool operator==(const TSimpleTM& a, const TSimpleTM& b) {
+ friend bool operator==(const TSimpleTM& a, const TSimpleTM& b) {
return a.AsTimeT() == b.AsTimeT();
- }
+ }
- friend bool operator==(const TSimpleTM& s, const struct tm& t) {
- return s == New(t);
- }
+ 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 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& a, const TSimpleTM& b) {
+ return !(a == b);
+ }
- friend bool operator!=(const TSimpleTM& s, const struct tm& t) {
- return !(s == t);
- }
+ 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;
- }
- };
+ friend bool operator!=(const struct tm& t, const TSimpleTM& s) {
+ return s != t;
+ }
+ };
}
inline TString date2str(const time_t date) {
@@ -150,28 +150,28 @@ inline time_t str2date(const TString& dateStr) {
}
// checks whether time2 > time1 and close enough to it
-inline bool AreTimesSeqAndClose(time_t time1, time_t time2, time_t closeInterval = 10) {
+inline bool AreTimesSeqAndClose(time_t time1, time_t time2, time_t closeInterval = 10) {
return (time2 - time1) <= closeInterval;
}
// checks whether time2 and time1 are close enough
-inline bool AreTimesClose(time_t time1, time_t time2, time_t closeInterval = 10) {
- return std::abs(time2 - time1) <= closeInterval;
+inline bool AreTimesClose(time_t time1, time_t time2, time_t closeInterval = 10) {
+ return std::abs(time2 - time1) <= closeInterval;
}
////////////////////////////////
-struct TMonth {
+struct TMonth {
ui16 Year;
- ui8 Month;
+ ui8 Month;
TMonth(ui16 year = 0, ui8 month = 0)
: Year(year)
, Month(month)
- {
- }
+ {
+ }
- TMonth operator-(ui16 n) {
+ TMonth operator-(ui16 n) {
if (n <= Month) {
return TMonth(Year, Month - (ui8)n);
} else {