diff options
author | solar <solar@yandex-team.ru> | 2022-02-10 16:49:59 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:59 +0300 |
commit | 2b7b1ea361eac9c59c4a56052d7292b3ed8829be (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util/draft | |
parent | da648cf6f097dd42d968802dca7734c68ef57d67 (diff) | |
download | ydb-2b7b1ea361eac9c59c4a56052d7292b3ed8829be.tar.gz |
Restoring authorship annotation for <solar@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/draft')
-rw-r--r-- | util/draft/date.cpp | 22 | ||||
-rw-r--r-- | util/draft/date.h | 88 |
2 files changed, 55 insertions, 55 deletions
diff --git a/util/draft/date.cpp b/util/draft/date.cpp index 78b7ebda52..a290c46050 100644 --- a/util/draft/date.cpp +++ b/util/draft/date.cpp @@ -15,17 +15,17 @@ time_t GetDateStart(time_t ts) { dateTm.tm_min = 0; dateTm.tm_hour = 0; return mktime(&dateTm); -} - +} + static time_t ParseDate(const char* date, const char* format) { - tm dateTm; - memset(&dateTm, 0, sizeof(tm)); + tm dateTm; + memset(&dateTm, 0, sizeof(tm)); if (!strptime(date, format, &dateTm)) { ythrow yexception() << "Invalid date string and format: " << date << ", " << format; } return mktime(&dateTm); -} - +} + static time_t ParseDate(const char* dateStr) { if (strlen(dateStr) != 8) { ythrow yexception() << "Invalid date string: " << dateStr; @@ -51,9 +51,9 @@ TDate::TDate(const TString& yyyymmdd) TDate::TDate(time_t ts) : Timestamp(GetDateStart(ts)) -{ -} - +{ +} + TDate::TDate(const TString& date, const TString& format) : Timestamp(GetDateStart(ParseDate(date.data(), format.data()))) { @@ -86,8 +86,8 @@ TString TDate::ToStroka(const char* format) const { tm dateTm; localtime_r(&Timestamp, &dateTm); return Strftime(format, &dateTm); -} - +} + unsigned TDate::GetWeekDay() const { tm dateTm; localtime_r(&Timestamp, &dateTm); diff --git a/util/draft/date.h b/util/draft/date.h index acba9bc104..e3eb616fe5 100644 --- a/util/draft/date.h +++ b/util/draft/date.h @@ -1,10 +1,10 @@ #pragma once - + #include <util/stream/output.h> #include <util/stream/input.h> #include <util/generic/string.h> #include <util/datetime/constants.h> - + #include <ctime> // XXX: uses system calls for trivial things. may be very slow therefore. @@ -12,46 +12,46 @@ time_t GetDateStart(time_t ts); // Local date (without time zone) -class TDate { +class TDate { // XXX: wrong: must store number of days since epoch - time_t Timestamp; - -public: - TDate() - : Timestamp(0) - { - } - + time_t Timestamp; + +public: + TDate() + : Timestamp(0) + { + } + // XXX: wrong. Should be replace with two methods: TodayGmt() and TodayLocal() static TDate Today() { return TDate(time(nullptr)); - } - + } + TDate(const char* yyyymmdd); TDate(const TString& yyyymmdd); TDate(unsigned year, unsigned month, unsigned monthDay); // month from 01, monthDay from 01 TDate(const TString& date, const TString& format); explicit TDate(time_t t); - + time_t GetStart() const { - return Timestamp; - } - + return Timestamp; + } + time_t GetStartUTC() const; TString ToStroka(const char* format = "%Y%m%d") const; - + TDate& operator++() { Timestamp = GetDateStart(Timestamp + 3 * (SECONDS_IN_DAY / 2)); - return *this; - } - + return *this; + } + TDate& operator--() { Timestamp = GetDateStart(Timestamp - SECONDS_IN_DAY / 2); - return *this; - } - + return *this; + } + TDate& operator+=(unsigned days) { Timestamp = GetDateStart(Timestamp + days * SECONDS_IN_DAY + SECONDS_IN_DAY / 2); return *this; @@ -82,33 +82,33 @@ public: friend bool operator>=(const TDate& left, const TDate& right); friend bool operator==(const TDate& left, const TDate& right); friend int operator-(const TDate& left, const TDate& right); - + friend IInputStream& operator>>(IInputStream& left, TDate& right); friend IOutputStream& operator<<(IOutputStream& left, const TDate& right); -}; - +}; + Y_DECLARE_PODTYPE(TDate); inline bool operator<(const TDate& left, const TDate& right) { - return left.Timestamp < right.Timestamp; -} - + return left.Timestamp < right.Timestamp; +} + inline bool operator>(const TDate& left, const TDate& right) { - return left.Timestamp > right.Timestamp; -} - + return left.Timestamp > right.Timestamp; +} + inline bool operator<=(const TDate& left, const TDate& right) { - return left.Timestamp <= right.Timestamp; -} - + return left.Timestamp <= right.Timestamp; +} + inline bool operator>=(const TDate& left, const TDate& right) { - return left.Timestamp >= right.Timestamp; -} - + return left.Timestamp >= right.Timestamp; +} + inline bool operator==(const TDate& left, const TDate& right) { - return left.Timestamp == right.Timestamp; -} - + return left.Timestamp == right.Timestamp; +} + inline int operator-(const TDate& left, const TDate& right) { if (left < right) { return -(right - left); @@ -125,5 +125,5 @@ inline IInputStream& operator>>(IInputStream& left, TDate& right) { } inline IOutputStream& operator<<(IOutputStream& left, const TDate& right) { - return left << right.ToStroka(); -} + return left << right.ToStroka(); +} |