OmniSciDB  04ee39c94c
TimeGM Class Reference

#include <TimeGM.h>

Public Member Functions

time_t my_timegm (const struct tm *tm)
 
time_t my_timegm (const struct tm *tm, const time_t fsc, const int32_t dimen)
 
time_t my_timegm_days (const struct tm *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

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::TimeGM ( )
inlineprivate

Definition at line 54 of file TimeGM.h.

54 {};

◆ ~TimeGM()

virtual TimeGM::~TimeGM ( )
inlineprivatevirtual

Definition at line 55 of file TimeGM.h.

55 {};

Member Function Documentation

◆ instance()

static TimeGM& TimeGM::instance ( )
inlinestatic

Definition at line 44 of file TimeGM.h.

Referenced by anonymous_namespace{ExecuteTest.cpp}::parse_fractional_seconds(), 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:

◆ is_leap_year()

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:

◆ leap_days()

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:

◆ my_timegm() [1/2]

time_t TimeGM::my_timegm ( const struct tm *  tm)

Definition at line 108 of file timegm.cpp.

References my_timegm_days().

Referenced by my_timegm(), 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(const struct tm *tm)
Definition: timegm.cpp:95
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ my_timegm() [2/2]

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

Definition at line 124 of file timegm.cpp.

References my_timegm().

124  {
125  time_t sec;
126 
127  sec = my_timegm(tm) * static_cast<int64_t>(pow(10, dimen));
128  sec += fsc;
129 
130  return sec;
131 }
time_t my_timegm(const struct tm *tm)
Definition: timegm.cpp:108
+ Here is the call graph for this function:

◆ my_timegm_days()

time_t TimeGM::my_timegm_days ( const struct tm *  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:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_fractional_seconds()

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 anonymous_namespace{ExecuteTest.cpp}::parse_fractional_seconds(), and 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:

◆ parse_meridians()

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

◆ monoff

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

Definition at line 51 of file TimeGM.h.

Referenced by my_timegm_days().


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