OmniSciDB  a987f07e93
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExtractFromTime.cpp File Reference
#include "ExtractFromTime.h"
#include <cstdlib>
+ Include dependency graph for ExtractFromTime.cpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 anonymous_namespace{ExtractFromTime.cpp}
 

Functions

template<unsigned OFFSET>
DEVICE unsigned anonymous_namespace{ExtractFromTime.cpp}::week_start_from_yoe (unsigned const yoe)
 
ALWAYS_INLINE DEVICE int64_t ExtractTimeFromHPTimestamp (const int64_t timeval, const int64_t scale)
 
ALWAYS_INLINE DEVICE int64_t ExtractTimeFromHPTimestampNullable (const int64_t timeval, const int64_t scale, const int64_t null_val)
 
ALWAYS_INLINE DEVICE int64_t ExtractTimeFromLPTimestamp (const int64_t timeval)
 
ALWAYS_INLINE DEVICE int64_t ExtractTimeFromLPTimestampNullable (const int64_t timeval, const int64_t null_val)
 
ALWAYS_INLINE DEVICE int64_t extract_hour (const int64_t lcltime)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_minute (const int64_t lcltime)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_second (const int64_t lcltime)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_millisecond (const int64_t lcltime)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_microsecond (const int64_t lcltime)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_nanosecond (const int64_t lcltime)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_dow (const int64_t lcltime)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_quarterday (const int64_t lcltime)
 
DEVICE int32_t extract_month_fast (const int64_t lcltime)
 
DEVICE int32_t extract_quarter_fast (const int64_t lcltime)
 
DEVICE int32_t extract_year_fast (const int64_t lcltime)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_epoch (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_dateepoch (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_isodow (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_day (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_day_of_year (const int64_t timeval)
 
template<unsigned OFFSET>
ALWAYS_INLINE DEVICE int64_t extract_week (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_week_monday (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_week_sunday (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_week_saturday (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_month (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_quarter (const int64_t timeval)
 
RUNTIME_EXPORT ALWAYS_INLINE
DEVICE int64_t 
extract_year (const int64_t timeval)
 
DEVICE int64_t ExtractFromTime (ExtractField field, const int64_t timeval)
 

Variables

constexpr unsigned anonymous_namespace{ExtractFromTime.cpp}::MONDAY = 2
 
constexpr unsigned anonymous_namespace{ExtractFromTime.cpp}::SUNDAY = 3
 
constexpr unsigned anonymous_namespace{ExtractFromTime.cpp}::SATURDAY = 4
 

Function Documentation

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_dateepoch ( const int64_t  timeval)

Definition at line 188 of file ExtractFromTime.cpp.

References kSecsPerDay, and unsigned_mod().

Referenced by ExtractFromTime().

188  {
189  return timeval - unsigned_mod(timeval, kSecsPerDay);
190 }
static constexpr int64_t kSecsPerDay
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_day ( const int64_t  timeval)

Definition at line 200 of file ExtractFromTime.cpp.

References floor_div(), kDaysPer400Years, kEpochAdjustedDays, kSecsPerDay, and unsigned_mod().

Referenced by ExtractFromTime().

200  {
201  int64_t const day = floor_div(timeval, kSecsPerDay);
202  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
203  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
204  unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
205  unsigned const moy = (5 * doy + 2) / 153;
206  return doy - (153 * moy + 2) / 5 + 1;
207 }
static constexpr int64_t kSecsPerDay
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
static constexpr int32_t kEpochAdjustedDays
static constexpr int64_t kDaysPer400Years
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_day_of_year ( const int64_t  timeval)

Definition at line 210 of file ExtractFromTime.cpp.

References floor_div(), JANMAR, kDaysPer400Years, kEpochAdjustedDays, kSecsPerDay, MARJAN, and unsigned_mod().

Referenced by ExtractFromTime().

210  {
211  int64_t const day = floor_div(timeval, kSecsPerDay);
212  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
213  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
214  unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
215  return doy + (doy < MARJAN ? 1 + JANMAR + (yoe % 4 == 0 && (yoe % 100 != 0 || yoe == 0))
216  : 1 - MARJAN);
217 }
static constexpr int64_t kSecsPerDay
constexpr unsigned JANMAR
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
static constexpr int32_t kEpochAdjustedDays
static constexpr int64_t kDaysPer400Years
constexpr unsigned MARJAN
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_dow ( const int64_t  lcltime)

Definition at line 107 of file ExtractFromTime.cpp.

References floor_div(), kDaysPerWeek, kSecsPerDay, and unsigned_mod().

Referenced by ExtractFromTime().

107  {
108  int64_t const days_past_epoch = floor_div(lcltime, kSecsPerDay);
109  return unsigned_mod(days_past_epoch + 4, kDaysPerWeek);
110 }
static constexpr int64_t kSecsPerDay
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
static constexpr int32_t kDaysPerWeek
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_epoch ( const int64_t  timeval)

Definition at line 183 of file ExtractFromTime.cpp.

Referenced by ExtractFromTime().

183  {
184  return timeval;
185 }

+ Here is the caller graph for this function:

ALWAYS_INLINE DEVICE int64_t extract_hour ( const int64_t  lcltime)

Definition at line 76 of file ExtractFromTime.cpp.

References kSecsPerDay, kSecsPerHour, and unsigned_mod().

Referenced by ExtractFromTime().

76  {
77  return unsigned_mod(lcltime, kSecsPerDay) / kSecsPerHour;
78 }
static constexpr int64_t kSecsPerDay
static constexpr int64_t kSecsPerHour
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_isodow ( const int64_t  timeval)

Definition at line 194 of file ExtractFromTime.cpp.

References floor_div(), kDaysPerWeek, kSecsPerDay, and unsigned_mod().

Referenced by ExtractFromTime().

194  {
195  int64_t const days_past_epoch = floor_div(timeval, kSecsPerDay);
196  return unsigned_mod(days_past_epoch + 3, kDaysPerWeek) + 1;
197 }
static constexpr int64_t kSecsPerDay
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
static constexpr int32_t kDaysPerWeek
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_microsecond ( const int64_t  lcltime)

Definition at line 96 of file ExtractFromTime.cpp.

References kMicroSecsPerSec, kSecsPerMin, and unsigned_mod().

Referenced by ExtractFromTime().

96  {
97  return unsigned_mod(lcltime, kSecsPerMin * kMicroSecsPerSec);
98 }
static constexpr int64_t kSecsPerMin
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)
static constexpr int64_t kMicroSecsPerSec

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_millisecond ( const int64_t  lcltime)

Definition at line 91 of file ExtractFromTime.cpp.

References kMilliSecsPerSec, kSecsPerMin, and unsigned_mod().

Referenced by ExtractFromTime().

91  {
92  return unsigned_mod(lcltime, kSecsPerMin * kMilliSecsPerSec);
93 }
static constexpr int64_t kSecsPerMin
static constexpr int64_t kMilliSecsPerSec
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_minute ( const int64_t  lcltime)

Definition at line 81 of file ExtractFromTime.cpp.

References kSecsPerHour, kSecsPerMin, and unsigned_mod().

Referenced by ExtractFromTime().

81  {
82  return unsigned_mod(lcltime, kSecsPerHour) / kSecsPerMin;
83 }
static constexpr int64_t kSecsPerHour
static constexpr int64_t kSecsPerMin
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_month ( const int64_t  timeval)

Definition at line 252 of file ExtractFromTime.cpp.

References extract_month_fast(), floor_div(), kDaysPer400Years, kEpochAdjustedDays, kEpochOffsetYear1900, kSecsPerDay, and unsigned_mod().

Referenced by ExtractFromTime().

252  {
253  if (timeval >= 0LL && timeval <= UINT32_MAX - kEpochOffsetYear1900) {
254  return extract_month_fast(timeval);
255  }
256  int64_t const day = floor_div(timeval, kSecsPerDay);
257  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
258  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
259  unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
260  unsigned const moy = (5 * doy + 2) / 153;
261  return moy + (moy < 10 ? 3 : -9);
262 }
static constexpr int64_t kSecsPerDay
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
static constexpr uint32_t kEpochOffsetYear1900
static constexpr int32_t kEpochAdjustedDays
static constexpr int64_t kDaysPer400Years
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)
DEVICE int32_t extract_month_fast(const int64_t lcltime)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE int32_t extract_month_fast ( const int64_t  lcltime)

Definition at line 117 of file ExtractFromTime.cpp.

References kEpochOffsetYear1900, kMonsPerYear, kSecondsPer4YearCycle, kSecondsPerNonLeapYear, kSecsJanToMar1900, kUSecsPerDay, and STATIC_QUAL.

Referenced by extract_month().

117  {
118  STATIC_QUAL const uint32_t cumulative_month_epoch_starts[kMonsPerYear] = {0,
119  2678400,
120  5270400,
121  7948800,
122  10540800,
123  13219200,
124  15897600,
125  18489600,
126  21168000,
127  23760000,
128  26438400,
129  29116800};
130  uint32_t seconds_march_1900 = lcltime + kEpochOffsetYear1900 - kSecsJanToMar1900;
131  uint32_t seconds_past_4year_period = seconds_march_1900 % kSecondsPer4YearCycle;
132  uint32_t year_seconds_past_4year_period =
133  (seconds_past_4year_period / kSecondsPerNonLeapYear) * kSecondsPerNonLeapYear;
134  if (seconds_past_4year_period >=
135  kSecondsPer4YearCycle - kUSecsPerDay) { // if we are in Feb 29th
136  year_seconds_past_4year_period -= kSecondsPerNonLeapYear;
137  }
138  uint32_t seconds_past_march =
139  seconds_past_4year_period - year_seconds_past_4year_period;
140  uint32_t month =
141  seconds_past_march / (30 * kUSecsPerDay); // Will make the correct month either be
142  // the guessed month or month before
143  month = month <= 11 ? month : 11;
144  if (cumulative_month_epoch_starts[month] > seconds_past_march) {
145  month--;
146  }
147  return (month + 2) % 12 + 1;
148 }
static constexpr uint32_t kSecsJanToMar1900
static constexpr uint32_t kUSecsPerDay
#define STATIC_QUAL
static constexpr uint32_t kEpochOffsetYear1900
static constexpr uint32_t kSecondsPer4YearCycle
static constexpr uint32_t kSecondsPerNonLeapYear
static constexpr int32_t kMonsPerYear

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_nanosecond ( const int64_t  lcltime)

Definition at line 101 of file ExtractFromTime.cpp.

References kNanoSecsPerSec, kSecsPerMin, and unsigned_mod().

Referenced by ExtractFromTime().

101  {
102  return unsigned_mod(lcltime, kSecsPerMin * kNanoSecsPerSec);
103 }
static constexpr int64_t kSecsPerMin
static constexpr int64_t kNanoSecsPerSec
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_quarter ( const int64_t  timeval)

Definition at line 265 of file ExtractFromTime.cpp.

References extract_quarter_fast(), floor_div(), kDaysPer400Years, kEpochAdjustedDays, kEpochOffsetYear1900, kSecsPerDay, and unsigned_mod().

Referenced by ExtractFromTime().

265  {
266  if (timeval >= 0LL && timeval <= UINT32_MAX - kEpochOffsetYear1900) {
267  return extract_quarter_fast(timeval);
268  }
269  constexpr int64_t quarter[12]{1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 1, 1};
270  int64_t const day = floor_div(timeval, kSecsPerDay);
271  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
272  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
273  unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
274  unsigned const moy = (5 * doy + 2) / 153;
275  return quarter[moy];
276 }
static constexpr int64_t kSecsPerDay
DEVICE int32_t extract_quarter_fast(const int64_t lcltime)
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
static constexpr uint32_t kEpochOffsetYear1900
static constexpr int32_t kEpochAdjustedDays
static constexpr int64_t kDaysPer400Years
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE int32_t extract_quarter_fast ( const int64_t  lcltime)

Definition at line 150 of file ExtractFromTime.cpp.

References kEpochOffsetYear1900, kSecondsPer4YearCycle, kSecondsPerNonLeapYear, kSecsJanToMar1900, kSecsPerDay, kUSecsPerDay, and STATIC_QUAL.

Referenced by extract_quarter().

150  {
151  STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts[4] = {
152  0, 7776000, 15638400, 23587200};
153  STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts_leap_year[4] = {
154  0, 7862400, 15724800, 23673600};
155  uint32_t seconds_1900 = lcltime + kEpochOffsetYear1900;
156  uint32_t leap_years = (seconds_1900 - kSecsJanToMar1900) / kSecondsPer4YearCycle;
157  uint32_t year = (seconds_1900 - leap_years * kSecsPerDay) / kSecondsPerNonLeapYear;
158  uint32_t base_year_leap_years = (year - 1) / 4;
159  uint32_t base_year_seconds =
160  year * kSecondsPerNonLeapYear + base_year_leap_years * kUSecsPerDay;
161  bool is_leap_year = year % 4 == 0 && year != 0;
162  const uint32_t* quarter_offsets = is_leap_year
163  ? cumulative_quarter_epoch_starts_leap_year
164  : cumulative_quarter_epoch_starts;
165  uint32_t partial_year_seconds = seconds_1900 % base_year_seconds;
166  uint32_t quarter = partial_year_seconds / (90 * kUSecsPerDay);
167  quarter = quarter <= 3 ? quarter : 3;
168  if (quarter_offsets[quarter] > partial_year_seconds) {
169  quarter--;
170  }
171  return quarter + 1;
172 }
static constexpr int64_t kSecsPerDay
static constexpr uint32_t kSecsJanToMar1900
static constexpr uint32_t kUSecsPerDay
#define STATIC_QUAL
static constexpr uint32_t kEpochOffsetYear1900
static constexpr uint32_t kSecondsPer4YearCycle
static constexpr uint32_t kSecondsPerNonLeapYear

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_quarterday ( const int64_t  lcltime)

Definition at line 113 of file ExtractFromTime.cpp.

References kSecsPerDay, kSecsPerQuarterDay, and unsigned_mod().

Referenced by ExtractFromTime().

113  {
114  return unsigned_mod(lcltime, kSecsPerDay) / kSecsPerQuarterDay + 1;
115 }
static constexpr int64_t kSecsPerDay
static constexpr int64_t kSecsPerQuarterDay
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_second ( const int64_t  lcltime)

Definition at line 86 of file ExtractFromTime.cpp.

References kSecsPerMin, and unsigned_mod().

Referenced by ExtractFromTime().

86  {
87  return unsigned_mod(lcltime, kSecsPerMin);
88 }
static constexpr int64_t kSecsPerMin
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<unsigned OFFSET>
ALWAYS_INLINE DEVICE int64_t extract_week ( const int64_t  timeval)

Definition at line 220 of file ExtractFromTime.cpp.

References floor_div(), kDaysPer400Years, kEpochAdjustedDays, kSecsPerDay, and unsigned_mod().

220  {
221  int64_t const day = floor_div(timeval, kSecsPerDay);
222  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
223  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
224  unsigned week_start = week_start_from_yoe<OFFSET>(yoe);
225  if (doe < week_start) {
226  if (yoe == 0) {
227  // 2000-03-01 is OFFSET days from start of week, week + 9.
228  return (doe + OFFSET) / 7 + 9;
229  } else {
230  week_start = week_start_from_yoe<OFFSET>(yoe - 1);
231  }
232  }
233  return (doe - week_start) / 7 + 1;
234 }
static constexpr int64_t kSecsPerDay
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
static constexpr int32_t kEpochAdjustedDays
static constexpr int64_t kDaysPer400Years
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_week_monday ( const int64_t  timeval)

Definition at line 237 of file ExtractFromTime.cpp.

Referenced by ExtractFromTime().

237  {
238  return extract_week<MONDAY>(timeval);
239 }

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_week_saturday ( const int64_t  timeval)

Definition at line 247 of file ExtractFromTime.cpp.

Referenced by ExtractFromTime().

247  {
248  return extract_week<SATURDAY>(timeval);
249 }

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_week_sunday ( const int64_t  timeval)

Definition at line 242 of file ExtractFromTime.cpp.

Referenced by ExtractFromTime().

242  {
243  return extract_week<SUNDAY>(timeval);
244 }

+ Here is the caller graph for this function:

RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_year ( const int64_t  timeval)

Definition at line 279 of file ExtractFromTime.cpp.

References extract_year_fast(), floor_div(), kDaysPer400Years, kEpochAdjustedDays, kEpochOffsetYear1900, kSecsPerDay, and MARJAN.

Referenced by ExtractFromTime().

279  {
280  if (timeval >= 0LL && timeval <= UINT32_MAX - kEpochOffsetYear1900) {
281  return extract_year_fast(timeval);
282  }
283  int64_t const day = floor_div(timeval, kSecsPerDay);
284  int64_t const era = floor_div(day - kEpochAdjustedDays, kDaysPer400Years);
285  unsigned const doe = day - kEpochAdjustedDays - era * kDaysPer400Years;
286  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
287  unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
288  return 2000 + era * 400 + yoe + (MARJAN <= doy);
289 }
static constexpr int64_t kSecsPerDay
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
static constexpr uint32_t kEpochOffsetYear1900
static constexpr int32_t kEpochAdjustedDays
static constexpr int64_t kDaysPer400Years
constexpr unsigned MARJAN
DEVICE int32_t extract_year_fast(const int64_t lcltime)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

DEVICE int32_t extract_year_fast ( const int64_t  lcltime)

Definition at line 174 of file ExtractFromTime.cpp.

References kEpochOffsetYear1900, kSecondsPer4YearCycle, kSecondsPerNonLeapYear, kSecsJanToMar1900, and kUSecsPerDay.

Referenced by extract_year().

174  {
175  const uint32_t seconds_1900 = lcltime + kEpochOffsetYear1900;
176  const uint32_t leap_years = (seconds_1900 - kSecsJanToMar1900) / kSecondsPer4YearCycle;
177  const uint32_t year =
178  (seconds_1900 - leap_years * kUSecsPerDay) / kSecondsPerNonLeapYear + 1900;
179  return year;
180 }
static constexpr uint32_t kSecsJanToMar1900
static constexpr uint32_t kUSecsPerDay
static constexpr uint32_t kEpochOffsetYear1900
static constexpr uint32_t kSecondsPer4YearCycle
static constexpr uint32_t kSecondsPerNonLeapYear

+ Here is the caller graph for this function:

DEVICE int64_t ExtractFromTime ( ExtractField  field,
const int64_t  timeval 
)

Definition at line 294 of file ExtractFromTime.cpp.

References extract_dateepoch(), extract_day(), extract_day_of_year(), extract_dow(), extract_epoch(), extract_hour(), extract_isodow(), extract_microsecond(), extract_millisecond(), extract_minute(), extract_month(), extract_nanosecond(), extract_quarter(), extract_quarterday(), extract_second(), extract_week_monday(), extract_week_saturday(), extract_week_sunday(), extract_year(), kDATEEPOCH, kDAY, kDOW, kDOY, kEPOCH, kHOUR, kISODOW, kMICROSECOND, kMILLISECOND, kMINUTE, kMONTH, kNANOSECOND, kQUARTER, kQUARTERDAY, kSECOND, kUNKNOWN_FIELD, kWEEK, kWEEK_SATURDAY, kWEEK_SUNDAY, and kYEAR.

Referenced by Timestamp::getDay(), getExpressionRange(), DateTimeTranslator::getExtractFromTimeConstantValue(), Timestamp::getHours(), Timestamp::getMicroseconds(), Timestamp::getMilliseconds(), Timestamp::getMinutes(), Timestamp::getMonth(), Timestamp::getNanoseconds(), Timestamp::getSeconds(), and Timestamp::getYear().

294  {
295  switch (field) {
296  case kEPOCH:
297  return extract_epoch(timeval);
298  case kDATEEPOCH:
299  return extract_dateepoch(timeval);
300  case kQUARTERDAY:
301  return extract_quarterday(timeval);
302  case kHOUR:
303  return extract_hour(timeval);
304  case kMINUTE:
305  return extract_minute(timeval);
306  case kSECOND:
307  return extract_second(timeval);
308  case kMILLISECOND:
309  return extract_millisecond(timeval);
310  case kMICROSECOND:
311  return extract_microsecond(timeval);
312  case kNANOSECOND:
313  return extract_nanosecond(timeval);
314  case kDOW:
315  return extract_dow(timeval);
316  case kISODOW:
317  return extract_isodow(timeval);
318  case kDAY:
319  return extract_day(timeval);
320  case kWEEK:
321  return extract_week_monday(timeval);
322  case kWEEK_SUNDAY:
323  return extract_week_sunday(timeval);
324  case kWEEK_SATURDAY:
325  return extract_week_saturday(timeval);
326  case kDOY:
327  return extract_day_of_year(timeval);
328  case kMONTH:
329  return extract_month(timeval);
330  case kQUARTER:
331  return extract_quarter(timeval);
332  case kYEAR:
333  return extract_year(timeval);
334  case kUNKNOWN_FIELD:
335  return -1;
336  }
337 
338 #ifdef __CUDACC__
339  return -1;
340 #else
341  abort();
342 #endif
343 }
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_year(const int64_t timeval)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_second(const int64_t lcltime)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_minute(const int64_t lcltime)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_month(const int64_t timeval)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_nanosecond(const int64_t lcltime)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_millisecond(const int64_t lcltime)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_week_sunday(const int64_t timeval)
ALWAYS_INLINE DEVICE int64_t extract_hour(const int64_t lcltime)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_quarter(const int64_t timeval)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_week_monday(const int64_t timeval)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_dateepoch(const int64_t timeval)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_day(const int64_t timeval)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_epoch(const int64_t timeval)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_dow(const int64_t lcltime)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_week_saturday(const int64_t timeval)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_isodow(const int64_t timeval)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_microsecond(const int64_t lcltime)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_quarterday(const int64_t lcltime)
RUNTIME_EXPORT ALWAYS_INLINE DEVICE int64_t extract_day_of_year(const int64_t timeval)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ALWAYS_INLINE DEVICE int64_t ExtractTimeFromHPTimestamp ( const int64_t  timeval,
const int64_t  scale 
)

Definition at line 48 of file ExtractFromTime.cpp.

References floor_div(), kSecsPerDay, and unsigned_mod().

Referenced by ExtractTimeFromHPTimestampNullable().

49  {
50  return unsigned_mod(floor_div(timeval, scale), kSecsPerDay);
51 }
static constexpr int64_t kSecsPerDay
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ALWAYS_INLINE DEVICE int64_t ExtractTimeFromHPTimestampNullable ( const int64_t  timeval,
const int64_t  scale,
const int64_t  null_val 
)

Definition at line 54 of file ExtractFromTime.cpp.

References ExtractTimeFromHPTimestamp().

56  {
57  if (timeval == null_val) {
58  return null_val;
59  }
60  return ExtractTimeFromHPTimestamp(timeval, scale);
61 }
ALWAYS_INLINE DEVICE int64_t ExtractTimeFromHPTimestamp(const int64_t timeval, const int64_t scale)

+ Here is the call graph for this function:

ALWAYS_INLINE DEVICE int64_t ExtractTimeFromLPTimestamp ( const int64_t  timeval)

Definition at line 64 of file ExtractFromTime.cpp.

References kSecsPerDay, and unsigned_mod().

Referenced by ExtractTimeFromLPTimestampNullable().

64  {
65  return unsigned_mod(timeval, kSecsPerDay);
66 }
static constexpr int64_t kSecsPerDay
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ALWAYS_INLINE DEVICE int64_t ExtractTimeFromLPTimestampNullable ( const int64_t  timeval,
const int64_t  null_val 
)

Definition at line 69 of file ExtractFromTime.cpp.

References ExtractTimeFromLPTimestamp().

69  {
70  if (timeval == null_val) {
71  return null_val;
72  }
73  return ExtractTimeFromLPTimestamp(timeval);
74 }
ALWAYS_INLINE DEVICE int64_t ExtractTimeFromLPTimestamp(const int64_t timeval)

+ Here is the call graph for this function: