aboutsummaryrefslogtreecommitdiffstats
path: root/util/datetime
diff options
context:
space:
mode:
authorleo <leo@yandex-team.ru>2022-02-10 16:46:40 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:40 +0300
commit980edcd3304699edf9d4e4d6a656e585028e2a72 (patch)
tree139f47f3911484ae9af0eb347b1a88bd6c4bb35f /util/datetime
parentb036a557f285146e5e35d4213e29a094ab907bcf (diff)
downloadydb-980edcd3304699edf9d4e4d6a656e585028e2a72.tar.gz
Restoring authorship annotation for <leo@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/datetime')
-rw-r--r--util/datetime/cputimer.cpp24
-rw-r--r--util/datetime/cputimer.h14
-rw-r--r--util/datetime/parser.rl626
-rw-r--r--util/datetime/strptime.cpp132
-rw-r--r--util/datetime/systime.cpp50
-rw-r--r--util/datetime/systime.h16
6 files changed, 131 insertions, 131 deletions
diff --git a/util/datetime/cputimer.cpp b/util/datetime/cputimer.cpp
index 516d372c37..24e40ff8bb 100644
--- a/util/datetime/cputimer.cpp
+++ b/util/datetime/cputimer.cpp
@@ -5,7 +5,7 @@
#include <util/string/printf.h>
#include <util/stream/output.h>
#include <util/generic/singleton.h>
-
+
#if defined(_unix_)
#include <unistd.h>
#include <sched.h>
@@ -14,7 +14,7 @@
#include <sys/param.h>
#elif defined(_win_)
#include <util/system/winint.h>
-#endif
+#endif
TTimer::TTimer(const TStringBuf message) {
static const int SMALL_DURATION_CHAR_LENGTH = 9; // strlen("0.123456s")
@@ -90,7 +90,7 @@ TFormattedPrecisionTimer::~TFormattedPrecisionTimer() {
*Out << Message << ": " << diff << " ticks " << FormatCycles(diff) << Endl;
}
-
+
TFuncTimer::TFuncTimer(const char* func)
: Start_(TInstant::Now())
, Func_(func)
@@ -103,26 +103,26 @@ TFuncTimer::~TFuncTimer() {
}
TTimeLogger::TTimeLogger(const TString& message, bool verbose)
- : Message(message)
+ : Message(message)
, Verbose(verbose)
- , OK(false)
+ , OK(false)
, Begin(time(nullptr))
, BeginCycles(GetCycleCount())
-{
+{
if (Verbose) {
fprintf(stderr, "=========================================================\n");
fprintf(stderr, "%s started: %.24s (%lu) (%d)\n", Message.data(), ctime(&Begin), (unsigned long)Begin, (int)getpid());
}
-}
-
+}
+
double TTimeLogger::ElapsedTime() const {
return time(nullptr) - Begin;
}
void TTimeLogger::SetOK() {
- OK = true;
-}
-
+ OK = true;
+}
+
TTimeLogger::~TTimeLogger() {
time_t tim = time(nullptr);
ui64 endCycles = GetCycleCount();
@@ -133,4 +133,4 @@ TTimeLogger::~TTimeLogger() {
(unsigned long)tim - (unsigned long)Begin, FormatCycles(endCycles - BeginCycles).data());
fprintf(stderr, "%s=========================================================\n", prefix);
}
-}
+}
diff --git a/util/datetime/cputimer.h b/util/datetime/cputimer.h
index 7d38d5bdb3..b7849cf735 100644
--- a/util/datetime/cputimer.h
+++ b/util/datetime/cputimer.h
@@ -7,7 +7,7 @@
#include <util/stream/str.h>
class TTimer {
-private:
+private:
TInstant Start_;
TStringStream Message_;
@@ -108,17 +108,17 @@ public:
#endif
class TTimeLogger {
-private:
+private:
TString Message;
bool Verbose;
- bool OK;
+ bool OK;
time_t Begin;
ui64 BeginCycles;
-
+
public:
TTimeLogger(const TString& message, bool verbose = true);
- ~TTimeLogger();
+ ~TTimeLogger();
- void SetOK();
+ void SetOK();
double ElapsedTime() const;
-};
+};
diff --git a/util/datetime/parser.rl6 b/util/datetime/parser.rl6
index 931f09eae1..8e47b66179 100644
--- a/util/datetime/parser.rl6
+++ b/util/datetime/parser.rl6
@@ -7,7 +7,7 @@
#include <util/datetime/parser.h>
#include <util/generic/ymath.h>
-
+
%%{
@@ -119,18 +119,18 @@ action set_mil_offset {
if (c <= 'M') {
// ['A'..'M'] \ 'J'
if (c < 'J')
- DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A' + 1).Minutes();
+ DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A' + 1).Minutes();
else
- DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A').Minutes();
+ DateTimeFields.ZoneOffsetMinutes = (i32)TDuration::Hours(c - 'A').Minutes();
} else {
// ['N'..'Y']
- DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(c - 'N' + 1).Minutes();
+ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(c - 'N' + 1).Minutes();
}
}
}
action set_digit_offset {
- DateTimeFields.ZoneOffsetMinutes = Sign * (i32)(TDuration::Hours(I / 100) + TDuration::Minutes(I % 100)).Minutes();
+ DateTimeFields.ZoneOffsetMinutes = Sign * (i32)(TDuration::Hours(I / 100) + TDuration::Minutes(I % 100)).Minutes();
}
mil_zone = /[A-IK-Za-ik-z]/ $set_mil_offset;
@@ -142,14 +142,14 @@ mil_zone = /[A-IK-Za-ik-z]/ $set_mil_offset;
zone = 'UT' @{ DateTimeFields.ZoneOffsetMinutes = 0; }
| 'GMT' @{ DateTimeFields.ZoneOffsetMinutes = 0; }
- | 'EST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(5).Minutes();}
- | 'EDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(4).Minutes(); }
- | 'CST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(6).Minutes();}
- | 'CDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(5).Minutes(); }
- | 'MST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(7).Minutes();}
- | 'MDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(6).Minutes(); }
- | 'PST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(8).Minutes();}
- | 'PDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(7).Minutes(); };
+ | 'EST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(5).Minutes();}
+ | 'EDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(4).Minutes(); }
+ | 'CST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(6).Minutes();}
+ | 'CDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(5).Minutes(); }
+ | 'MST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(7).Minutes();}
+ | 'MDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(6).Minutes(); }
+ | 'PST' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(8).Minutes();}
+ | 'PDT' @{ DateTimeFields.ZoneOffsetMinutes = -(i32)TDuration::Hours(7).Minutes(); };
digit_offset = ('+' | '-') > { Sign = fc == '+' ? 1 : -1; } . int4 @set_digit_offset;
diff --git a/util/datetime/strptime.cpp b/util/datetime/strptime.cpp
index f0d4ec333e..fb6b038bf0 100644
--- a/util/datetime/strptime.cpp
+++ b/util/datetime/strptime.cpp
@@ -54,14 +54,14 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <util/system/compat.h>
-#include "systime.h"
+#include <util/system/compat.h>
+#include "systime.h"
#ifdef _win32_
#ifndef lint
#ifndef NOID
static char copyright[] =
"@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved.";
-static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27";
+static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27";
#endif /* !defined NOID */
#endif /* not lint */
//__FBSDID("$FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.35 2003/11/17 04:19:15 nectar Exp $");
@@ -176,31 +176,31 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
char c;
const char* ptr;
int i;
- size_t len = 0;
- int Ealternative, Oalternative;
+ size_t len = 0;
+ int Ealternative, Oalternative;
struct lc_time_T* tptr = __get_current_time_locale();
- ptr = fmt;
- while (*ptr != 0) {
- if (*buf == 0)
- break;
+ ptr = fmt;
+ while (*ptr != 0) {
+ if (*buf == 0)
+ break;
- c = *ptr++;
+ c = *ptr++;
- if (c != '%') {
- if (isspace((unsigned char)c))
- while (*buf != 0 && isspace((unsigned char)*buf))
+ if (c != '%') {
+ if (isspace((unsigned char)c))
+ while (*buf != 0 && isspace((unsigned char)*buf))
++buf;
- else if (c != *buf++)
- return 0;
- continue;
- }
+ else if (c != *buf++)
+ return 0;
+ continue;
+ }
- Ealternative = 0;
- Oalternative = 0;
+ Ealternative = 0;
+ Oalternative = 0;
label:
- c = *ptr++;
- switch (c) {
+ c = *ptr++;
+ switch (c) {
case 0:
case '%':
if (*buf++ != '%')
@@ -234,13 +234,13 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
buf = _strptime(buf, tptr->c_fmt, tm, GMTp);
if (buf == 0)
return 0;
- break;
+ break;
case 'D':
buf = _strptime(buf, "%m/%d/%y", tm, GMTp);
if (buf == 0)
return 0;
- break;
+ break;
case 'E':
if (Ealternative || Oalternative)
@@ -304,7 +304,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
return 0;
tm->tm_yday = i - 1;
- break;
+ break;
case 'M':
case 'S':
@@ -312,7 +312,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
break;
if (!isdigit((unsigned char)*buf))
- return 0;
+ return 0;
len = 2;
for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) {
@@ -341,13 +341,13 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
case 'k':
case 'l':
/*
- * Of these, %l is the only specifier explicitly
- * documented as not being zero-padded. However,
- * there is no harm in allowing zero-padding.
- *
- * XXX The %l specifier may gobble one too many
- * digits if used incorrectly.
- */
+ * Of these, %l is the only specifier explicitly
+ * documented as not being zero-padded. However,
+ * there is no harm in allowing zero-padding.
+ *
+ * XXX The %l specifier may gobble one too many
+ * digits if used incorrectly.
+ */
if (!isdigit((unsigned char)*buf))
return 0;
@@ -361,7 +361,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
if (i > 23)
return 0;
} else if (i > 12)
- return 0;
+ return 0;
tm->tm_hour = i;
@@ -372,9 +372,9 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
case 'p':
/*
- * XXX This is bogus if parsed before hour-related
- * specifiers.
- */
+ * XXX This is bogus if parsed before hour-related
+ * specifiers.
+ */
len = strlen(tptr->am);
if (strnicmp(buf, tptr->am, len) == 0) {
if (tm->tm_hour > 12)
@@ -410,20 +410,20 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
break;
}
if (i == asizeof(tptr->weekday))
- return 0;
+ return 0;
tm->tm_wday = i;
- buf += len;
- break;
+ buf += len;
+ break;
case 'U':
case 'W':
/*
- * XXX This is bogus, as we can not assume any valid
- * information present in the tm structure at this
- * point to calculate a real value, so just check the
- * range for now.
- */
+ * XXX This is bogus, as we can not assume any valid
+ * information present in the tm structure at this
+ * point to calculate a real value, so just check the
+ * range for now.
+ */
if (!isdigit((unsigned char)*buf))
return 0;
@@ -459,13 +459,13 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
case 'd':
case 'e':
/*
- * The %e specifier is explicitly documented as not
- * being zero-padded but there is no harm in allowing
- * such padding.
- *
- * XXX The %e specifier may gobble one too many
- * digits if used incorrectly.
- */
+ * The %e specifier is explicitly documented as not
+ * being zero-padded but there is no harm in allowing
+ * such padding.
+ *
+ * XXX The %e specifier may gobble one too many
+ * digits if used incorrectly.
+ */
if (!isdigit((unsigned char)*buf))
return 0;
@@ -501,13 +501,13 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
len = strlen(tptr->month[i]);
if (strnicmp(buf, tptr->month[i],
len) == 0)
- break;
+ break;
len = strlen(tptr->mon[i]);
if (strnicmp(buf, tptr->mon[i],
len) == 0)
break;
- }
- }
+ }
+ }
if (i == asizeof(tptr->month))
return 0;
@@ -548,7 +548,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
errno = sverrno;
return 0;
}
- errno = sverrno;
+ errno = sverrno;
buf = cp;
GmTimeR(&t, tm);
*GMTp = 1;
@@ -587,7 +587,7 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
char* zonestr;
for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) { /*empty*/
- }
+ }
if (cp - buf) {
zonestr = (char*)alloca(cp - buf + 1);
strncpy(zonestr, buf, cp - buf);
@@ -605,23 +605,23 @@ _strptime(const char* buf, const char* fmt, struct tm* tm, int* GMTp)
buf += cp - buf;
}
} break;
- }
- }
+ }
+ }
return (char*)buf;
}
char* strptime(const char* buf, const char* fmt, struct tm* tm)
{
char* ret;
- int gmt;
+ int gmt;
- gmt = 0;
- ret = _strptime(buf, fmt, tm, &gmt);
- if (ret && gmt) {
- time_t t = timegm(tm);
- localtime_r(&t, tm);
- }
+ gmt = 0;
+ ret = _strptime(buf, fmt, tm, &gmt);
+ if (ret && gmt) {
+ time_t t = timegm(tm);
+ localtime_r(&t, tm);
+ }
- return (ret);
+ return (ret);
}
#endif //_win32_
diff --git a/util/datetime/systime.cpp b/util/datetime/systime.cpp
index 6ee7e8fc6e..b4e9c48eed 100644
--- a/util/datetime/systime.cpp
+++ b/util/datetime/systime.cpp
@@ -1,4 +1,4 @@
-#include "systime.h"
+#include "systime.h"
#include <util/system/yassert.h>
#include <util/system/defaults.h>
@@ -11,32 +11,32 @@ void FileTimeToTimeval(const FILETIME* ft, timeval* tv) {
ui64 ft_scalar;
FILETIME ft_struct;
} nt_time;
- nt_time.ft_struct = *ft;
- tv->tv_sec = (long)((nt_time.ft_scalar - NANOINTERVAL) / LL(10000000));
- tv->tv_usec = (i32)((nt_time.ft_scalar / LL(10)) % LL(1000000));
-}
-
+ nt_time.ft_struct = *ft;
+ tv->tv_sec = (long)((nt_time.ft_scalar - NANOINTERVAL) / LL(10000000));
+ tv->tv_usec = (i32)((nt_time.ft_scalar / LL(10)) % LL(1000000));
+}
+
int gettimeofday(timeval* tp, void*) {
- FILETIME ft;
- GetSystemTimeAsFileTime(&ft);
- FileTimeToTimeval(&ft, tp);
- return 0;
-}
-
+ FILETIME ft;
+ GetSystemTimeAsFileTime(&ft);
+ FileTimeToTimeval(&ft, tp);
+ return 0;
+}
+
tm* localtime_r(const time_t* clock, tm* result) {
- tzset();
- tm* res = localtime(clock);
- if (res) {
- memcpy(result, res, sizeof(tm));
- return result;
- }
- return 0;
-}
-
+ tzset();
+ tm* res = localtime(clock);
+ if (res) {
+ memcpy(result, res, sizeof(tm));
+ return result;
+ }
+ return 0;
+}
+
tm* gmtime_r(const time_t* clock, tm* result) {
return gmtime_s(result, clock) == 0 ? result : 0;
-}
-
+}
+
char* ctime_r(const time_t* clock, char* buf) {
char* res = ctime(clock);
if (res) {
@@ -54,7 +54,7 @@ char* ctime_r(const time_t* clock, char* buf) {
#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
#define FOURCENTURIES (400 * 365 + 100 - 3)
-
+
//! Inverse of gmtime: converts struct tm to time_t, assuming the data
//! in tm is UTC rather than local timezone. This implementation
//! returns the number of seconds since 1970-01-01, converted to time_t.
@@ -83,7 +83,7 @@ time_t TimeGM(const struct tm* t) {
unsigned long secs = days * 86400ul + t->tm_hour * 3600 + t->tm_min * 60 + t->tm_sec;
return (time_t)secs;
-}
+}
struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf) {
static const int _ytab[2][12] = {
diff --git a/util/datetime/systime.h b/util/datetime/systime.h
index 491d36e802..167c1dab86 100644
--- a/util/datetime/systime.h
+++ b/util/datetime/systime.h
@@ -3,7 +3,7 @@
#include <util/system/platform.h>
#include <util/generic/string.h>
-#include <ctime>
+#include <ctime>
// timegm and gmtime_r versions that don't need access to filesystem or a big stack
time_t TimeGM(const struct tm* t);
@@ -14,12 +14,12 @@ TString CTimeR(const time_t* timer);
#ifdef _win_
#include <util/system/winint.h>
#include <winsock2.h>
-
+
void FileTimeToTimeval(const FILETIME* ft, struct timeval* tv);
-
+
// obtains the current time, expressed as seconds and microseconds since 00:00 UTC, January 1, 1970
int gettimeofday(struct timeval* tp, void*);
-
+
// thou should not mix these with non-_r functions
tm* localtime_r(const time_t* clock, tm* result);
tm* gmtime_r(const time_t* clock, tm* result);
@@ -30,11 +30,11 @@ inline time_t timegm(struct tm* t) {
}
char* strptime(const char* buf, const char* fmt, struct tm* tm); // strptime.cpp
-#else
+#else
#include <sys/time.h>
-#endif
+#endif
-#ifndef timersub
+#ifndef timersub
#define timersub(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
@@ -44,4 +44,4 @@ char* strptime(const char* buf, const char* fmt, struct tm* tm); // strptime.cpp
(vvp)->tv_usec += 1000000; \
} \
} while (0)
-#endif
+#endif