OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TimeGM Class Reference

#include <TimeGM.h>

Public Member Functions

time_t my_timegm (tm const *tm)
 
time_t my_timegm (tm const *tm, const time_t fsc, const int32_t dimen)
 
time_t my_timegm_days (tm const *tm)
 
time_t parse_fractional_seconds (uint64_t sfrac, const int32_t ntotal, const int32_t dimen)
 
time_t parse_meridians (const time_t &timeval, const char *p, const uint32_t hour, const int32_t dimen)
 

Static Public Member Functions

static TimeGMinstance ()
 

Private Member Functions

time_t get_overflow_underflow_safe_epoch (tm const *tm, const time_t fsc, const int32_t dimen)
 
int is_leap_year (int year)
 
int leap_days (int y1, int y2)
 
 TimeGM ()
 
virtual ~TimeGM ()
 

Private Attributes

const int monoff [12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}
 

Detailed Description

Definition at line 32 of file TimeGM.h.

Constructor & Destructor Documentation

TimeGM::TimeGM ( )
inlineprivate

Definition at line 58 of file TimeGM.h.

58 {};
virtual TimeGM::~TimeGM ( )
inlineprivatevirtual

Definition at line 59 of file TimeGM.h.

59 {};

Member Function Documentation

time_t TimeGM::get_overflow_underflow_safe_epoch ( tm const *  tm,
const time_t  fsc,
const int32_t  dimen 
)
private

Definition at line 124 of file timegm.cpp.

References my_timegm(), and to_string().

Referenced by my_timegm().

126  {
127  const time_t epoch_seconds = my_timegm(tm);
128  const time_t epoch_scaled = epoch_seconds * static_cast<int64_t>(pow(10, dimen));
129  if (epoch_seconds &&
130  epoch_seconds != epoch_scaled / static_cast<int64_t>(pow(10, dimen))) {
131  throw std::runtime_error("Value out of range for TIMESTAMP(" + std::to_string(dimen) +
132  ").");
133  }
134  const time_t epoch_total = epoch_scaled + fsc;
135  if ((epoch_seconds > 0 && epoch_total < 0) || (epoch_seconds < 0 && epoch_total > 0)) {
136  throw std::runtime_error("Value out of range for TIMESTAMP(" + std::to_string(dimen) +
137  ").");
138  }
139 
140  return epoch_total;
141 }
time_t my_timegm(tm const *tm)
Definition: timegm.cpp:108
std::string to_string(char const *&&v)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static TimeGM& TimeGM::instance ( )
inlinestatic

Definition at line 44 of file TimeGM.h.

Referenced by DateTimeStringValidate< SQL_TYPE >::parseDateTimeString(), and DateTimeStringValidate< SQL_TYPE >::parseFractionalSeconds().

44  {
45  static TimeGM timegm{};
46  return timegm;
47  }
Definition: TimeGM.h:32

+ Here is the caller graph for this function:

int TimeGM::is_leap_year ( int  year)
private

Definition at line 42 of file timegm.cpp.

Referenced by my_timegm_days().

42  {
43  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
44 }

+ Here is the caller graph for this function:

int TimeGM::leap_days ( int  y1,
int  y2 
)
private

Definition at line 46 of file timegm.cpp.

Referenced by my_timegm_days().

46  {
47  --y1;
48  --y2;
49  return (y2 / 4 - y1 / 4) - (y2 / 100 - y1 / 100) + (y2 / 400 - y1 / 400);
50 }

+ Here is the caller graph for this function:

time_t TimeGM::my_timegm ( tm const *  tm)

Definition at line 108 of file timegm.cpp.

References my_timegm_days().

Referenced by get_overflow_underflow_safe_epoch(), and DateTimeStringValidate< SQL_TYPE >::parseDateTimeString().

108  {
109  time_t days;
110  time_t hours;
111  time_t minutes;
112  time_t seconds;
113 
114  days = my_timegm_days(tm);
115  hours = days * 24 + tm->tm_hour;
116  minutes = hours * 60 + tm->tm_min;
117  seconds = minutes * 60 + tm->tm_sec;
118 
119  seconds -= tm->tm_gmtoff;
120 
121  return seconds;
122 }
time_t my_timegm_days(tm const *tm)
Definition: timegm.cpp:95

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

time_t TimeGM::my_timegm ( tm const *  tm,
const time_t  fsc,
const int32_t  dimen 
)

Definition at line 143 of file timegm.cpp.

References get_overflow_underflow_safe_epoch().

143  {
144  return get_overflow_underflow_safe_epoch(tm, fsc, dimen);
145 }
time_t get_overflow_underflow_safe_epoch(tm const *tm, const time_t fsc, const int32_t dimen)
Definition: timegm.cpp:124

+ Here is the call graph for this function:

time_t TimeGM::my_timegm_days ( tm const *  tm)

Definition at line 95 of file timegm.cpp.

References is_leap_year(), leap_days(), and monoff.

Referenced by my_timegm().

95  {
96  int32_t year;
97  time_t days;
98  year = 1900 + tm->tm_year;
99  days = 365 * (year - 1970) + leap_days(1970, year);
100  days += monoff[tm->tm_mon];
101  if (tm->tm_mon > 1 && is_leap_year(year)) {
102  ++days;
103  }
104  days += tm->tm_mday - 1;
105  return days;
106 }
int leap_days(int y1, int y2)
Definition: timegm.cpp:46
int is_leap_year(int year)
Definition: timegm.cpp:42
const int monoff[12]
Definition: TimeGM.h:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

time_t TimeGM::parse_fractional_seconds ( uint64_t  sfrac,
const int32_t  ntotal,
const int32_t  dimen 
)

Definition at line 52 of file timegm.cpp.

Referenced by DateTimeStringValidate< SQL_TYPE >::parseFractionalSeconds().

54  {
55  int nfrac = log10(sfrac) + 1;
56  if (ntotal - nfrac > dimen) {
57  return 0;
58  }
59  if (ntotal >= 0 && ntotal < dimen) {
60  sfrac *= pow(10, dimen - ntotal);
61  } else if (ntotal > dimen) {
62  sfrac /= pow(10, ntotal - dimen);
63  }
64  return sfrac;
65 }

+ Here is the caller graph for this function:

time_t TimeGM::parse_meridians ( const time_t &  timeval,
const char *  p,
const uint32_t  hour,
const int32_t  dimen 
)

Definition at line 67 of file timegm.cpp.

References kSecsPerHalfDay.

Referenced by DateTimeStringValidate< SQL_TYPE >::parseDateTimeString().

70  {
71  char meridies[20];
72  if (sscanf(p, "%*d %s", meridies) != 1) {
73  if (sscanf(p, "%s", meridies) != 1) {
74  return timeval;
75  };
76  }
77  if (boost::iequals(std::string(meridies), "pm") ||
78  boost::iequals(std::string(meridies), "p.m.") ||
79  boost::iequals(std::string(meridies), "p.m")) {
80  return hour == 12 ? timeval
81  : timeval + kSecsPerHalfDay * static_cast<int64_t>(pow(10, dimen));
82  } else if (boost::iequals(std::string(meridies), "am") ||
83  boost::iequals(std::string(meridies), "a.m.") ||
84  boost::iequals(std::string(meridies), "a.m")) {
85  return hour == 12 ? timeval - kSecsPerHalfDay * static_cast<int64_t>(pow(10, dimen))
86  : timeval;
87  } else {
88  return timeval;
89  }
90 }
static constexpr int64_t kSecsPerHalfDay

+ Here is the caller graph for this function:

Member Data Documentation

const int TimeGM::monoff[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}
private

Definition at line 55 of file TimeGM.h.

Referenced by my_timegm_days().


The documentation for this class was generated from the following files: