OmniSciDB  bf83d84833
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DateTruncate.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 /*
17  * Thank you Howard Hinnant for public domain date algorithms
18  * http://howardhinnant.github.io/date_algorithms.html
19  */
20 
21 #include "DateTruncate.h"
22 #include "ExtractFromTime.h"
23 
24 #ifndef __CUDACC__
25 #include <cstdlib> // abort()
26 #endif
27 
28 #include <cmath>
29 #include <ctime>
30 #include <iostream>
31 #include <limits>
32 
33 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_minute(int64_t timeval) {
34  return timeval - unsigned_mod(timeval, kSecsPerMin);
35 }
36 
37 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_hour(int64_t timeval) {
38  return timeval - unsigned_mod(timeval, kSecsPerHour);
39 }
40 
41 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_quarterday(int64_t timeval) {
42  return timeval - unsigned_mod(timeval, kSecsPerQuarterDay);
43 }
44 
45 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_day(int64_t timeval) {
46  return timeval - unsigned_mod(timeval, kSecsPerDay);
47 }
48 
49 namespace {
50 // Days before Thursday (since 1 Jan 1970 is a Thursday.)
51 constexpr unsigned dtMONDAY = 3;
52 constexpr unsigned dtSUNDAY = 4;
53 constexpr unsigned dtSATURDAY = 5;
54 } // namespace
55 
56 template <unsigned OFFSET>
57 ALWAYS_INLINE DEVICE int64_t datetrunc_week(int64_t timeval) {
58  // Truncate to OFFSET.
59  return timeval - unsigned_mod(timeval + OFFSET * kSecsPerDay, 7 * kSecsPerDay);
60 }
61 
62 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_week_monday(int64_t timeval) {
63  return datetrunc_week<dtMONDAY>(timeval);
64 }
65 
66 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_week_sunday(int64_t timeval) {
67  return datetrunc_week<dtSUNDAY>(timeval);
68 }
69 
70 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_week_saturday(int64_t timeval) {
71  return datetrunc_week<dtSATURDAY>(timeval);
72 }
73 
74 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_month(int64_t timeval) {
75  if (timeval >= 0L && timeval <= UINT32_MAX - (kEpochOffsetYear1900)) {
76  STATIC_QUAL const uint32_t cumulative_month_epoch_starts[kMonsPerYear] = {0,
77  2678400,
78  5270400,
79  7948800,
80  10540800,
81  13219200,
82  15897600,
83  18489600,
84  21168000,
85  23760000,
86  26438400,
87  29116800};
88  // Handles times from Thu 01 Jan 1970 00:00:00 - Thu 07 Feb 2036 06:28:15.
89  uint32_t seconds_march_1900 = timeval + kEpochOffsetYear1900 - kSecsJanToMar1900;
90  uint32_t seconds_past_4year_period = seconds_march_1900 % kSecondsPer4YearCycle;
91  uint32_t four_year_period_seconds =
92  (seconds_march_1900 / kSecondsPer4YearCycle) * kSecondsPer4YearCycle;
93  uint32_t year_seconds_past_4year_period =
94  (seconds_past_4year_period / kSecondsPerNonLeapYear) * kSecondsPerNonLeapYear;
95  if (seconds_past_4year_period >=
96  kSecondsPer4YearCycle - kUSecsPerDay) { // if we are in Feb 29th
97  year_seconds_past_4year_period -= kSecondsPerNonLeapYear;
98  }
99  uint32_t seconds_past_march =
100  seconds_past_4year_period - year_seconds_past_4year_period;
101  uint32_t month =
102  seconds_past_march / (30 * kUSecsPerDay); // Will make the correct month either
103  // be the guessed month or month before
104  month = month <= 11 ? month : 11;
105  if (cumulative_month_epoch_starts[month] > seconds_past_march) {
106  month--;
107  }
108  return (static_cast<int64_t>(four_year_period_seconds) +
109  year_seconds_past_4year_period + cumulative_month_epoch_starts[month] -
111  } else {
112  int64_t const day = floor_div(timeval, kSecsPerDay);
113  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
114  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
115  unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
116  unsigned const moy = (5 * doy + 2) / 153;
117  unsigned const dom = doy - (153 * moy + 2) / 5;
118  return (day - dom) * kSecsPerDay;
119  }
120 }
121 
122 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_quarter(int64_t timeval) {
123  if (timeval >= 0L && timeval <= UINT32_MAX - kEpochOffsetYear1900) {
124  STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts[4] = {
125  0, 7776000, 15638400, 23587200};
126  STATIC_QUAL const uint32_t cumulative_quarter_epoch_starts_leap_year[4] = {
127  0, 7862400, 15724800, 23673600};
128  // Handles times from Thu 01 Jan 1970 00:00:00 - Thu 07 Feb 2036 06:28:15.
129  uint32_t seconds_1900 = timeval + kEpochOffsetYear1900;
130  uint32_t leap_years = (seconds_1900 - kSecsJanToMar1900) / kSecondsPer4YearCycle;
131  uint32_t year = (seconds_1900 - leap_years * kUSecsPerDay) / kSecondsPerNonLeapYear;
132  uint32_t base_year_leap_years = (year - 1) / 4;
133  uint32_t base_year_seconds =
134  year * kSecondsPerNonLeapYear + base_year_leap_years * kUSecsPerDay;
135  const bool is_leap_year = year % 4 == 0 && year != 0;
136  const uint32_t* quarter_offsets = is_leap_year
137  ? cumulative_quarter_epoch_starts_leap_year
138  : cumulative_quarter_epoch_starts;
139  uint32_t partial_year_seconds = seconds_1900 % base_year_seconds;
140  uint32_t quarter = partial_year_seconds / (90 * kUSecsPerDay);
141  quarter = quarter <= 3 ? quarter : 3;
142  if (quarter_offsets[quarter] > partial_year_seconds) {
143  quarter--;
144  }
145  return (static_cast<int64_t>(base_year_seconds) + quarter_offsets[quarter] -
147  } else {
148  int64_t const day = floor_div(timeval, kSecsPerDay);
149  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
150  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
151  unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
152  constexpr unsigned apr1 = 31; // Days in march
153  unsigned doq; // Day-of-quarter = Days since last Apr1, Jul1, Oct1, Jan1.
154  if (doy < apr1) {
155  bool const leap = yoe % 4 == 0 && (yoe % 100 != 0 || yoe == 0);
156  doq = JANMAR + leap + doy; // Q1
157  } else {
158  unsigned const q = (3 * (doy - apr1) + 2) / 275; // quarter = 0, 1, 2
159  doq = doy - (apr1 + q * 92 - (q != 0)); // Q2, Q3, Q4
160  }
161  return (day - doq) * kSecsPerDay;
162  }
163 }
164 
165 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_year(int64_t timeval) {
166  if (timeval >= 0L && timeval <= UINT32_MAX - kEpochOffsetYear1900) {
167  // Handles times from Thu 01 Jan 1970 00:00:00 - Thu 07 Feb 2036 06:28:15.
168  uint32_t seconds_1900 = static_cast<uint32_t>(timeval) + kEpochOffsetYear1900;
169  uint32_t leap_years = (seconds_1900 - kSecsJanToMar1900) / kSecondsPer4YearCycle;
170  uint32_t year = (seconds_1900 - leap_years * kUSecsPerDay) / kSecondsPerNonLeapYear;
171  uint32_t base_year_leap_years = (year - 1) / 4;
172  return (static_cast<int64_t>(year) * kSecondsPerNonLeapYear +
173  base_year_leap_years * kUSecsPerDay - kEpochOffsetYear1900);
174  } else {
175  int64_t const day = floor_div(timeval, kSecsPerDay);
176  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
177  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
178  unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
179  unsigned docy; // Day-of-calendar-year = Days since last Jan1.
180  if (doy < MARJAN) {
181  bool const leap = yoe % 4 == 0 && (yoe == 0 || yoe % 100 != 0);
182  docy = JANMAR + leap + doy;
183  } else {
184  docy = doy - MARJAN;
185  }
186  return (day - docy) * kSecsPerDay;
187  }
188 }
189 
190 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_decade(int64_t timeval) {
191  // Number of days from x00301 to (x+1)00101. Always includes exactly two leap days.
192  constexpr unsigned decmarjan = MARJAN + 9 * 365 + 2;
193  int64_t const day = floor_div(timeval, kSecsPerDay);
194  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
195  unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
196  unsigned const decoe = yoe - yoe % 10; // Decade-of-era
197  // Initialize to days after mar1 of decade, then adjust to after jan1 below.
198  unsigned days_after_decade = doe - (365 * decoe + decoe / 4 - decoe / 100);
199  if (days_after_decade < decmarjan) {
200  bool const leap = decoe % 4 == 0 && (decoe == 0 || decoe % 100 != 0);
201  days_after_decade += JANMAR + leap;
202  } else {
203  days_after_decade -= decmarjan;
204  }
205  return (day - days_after_decade) * kSecsPerDay;
206 }
207 
208 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_century(int64_t timeval) {
209  int64_t const day = floor_div(timeval, kSecsPerDay);
210  unsigned const doe = unsigned_mod(day - kEpochAdjustedDays, kDaysPer400Years);
211  // Day-of-century = Days since last 010101 (Jan 1 1901, 2001, 2101, etc.)
212  unsigned const doc = doe < MARJAN ? doe + (36525 - MARJAN) : (doe - MARJAN) % 36524;
213  return (day - doc) * kSecsPerDay;
214 }
215 
216 extern "C" ALWAYS_INLINE DEVICE int64_t datetrunc_millennium(int64_t timeval) {
217  constexpr unsigned millennium2001 = 365242; // Days from Jan 1 2001 to 3001.
218  int64_t const day = floor_div(timeval, kSecsPerDay);
219  // lcm(400, 1000) = 2000 so use 5*400-year eras at a time.
220  unsigned dom = unsigned_mod(day - kEpochAdjustedDays, 5 * kDaysPer400Years);
221  if (dom < MARJAN) {
222  dom += millennium2001 + 1 - MARJAN;
223  } else if (dom < MARJAN + millennium2001) {
224  dom -= MARJAN;
225  } else {
226  dom -= MARJAN + millennium2001;
227  }
228  return (day - dom) * kSecsPerDay;
229 }
230 
231 /*
232  * @brief support the SQL DATE_TRUNC function
233  */
234 int64_t DateTruncate(DatetruncField field, const int64_t timeval) {
235  switch (field) {
236  case dtNANOSECOND:
237  case dtMICROSECOND:
238  case dtMILLISECOND:
239  case dtSECOND:
240  return timeval;
241  case dtMINUTE:
242  return datetrunc_minute(timeval);
243  case dtHOUR:
244  return datetrunc_hour(timeval);
245  case dtQUARTERDAY:
246  return datetrunc_quarterday(timeval);
247  case dtDAY:
248  return datetrunc_day(timeval);
249  case dtWEEK:
250  return datetrunc_week_monday(timeval);
251  case dtWEEK_SUNDAY:
252  return datetrunc_week_sunday(timeval);
253  case dtWEEK_SATURDAY:
254  return datetrunc_week_saturday(timeval);
255  case dtMONTH:
256  return datetrunc_month(timeval);
257  case dtQUARTER:
258  return datetrunc_quarter(timeval);
259  case dtYEAR:
260  return datetrunc_year(timeval);
261  case dtDECADE:
262  return datetrunc_decade(timeval);
263  case dtCENTURY:
264  return datetrunc_century(timeval);
265  case dtMILLENNIUM:
266  return datetrunc_millennium(timeval);
267  default:
268 #ifdef __CUDACC__
269  return std::numeric_limits<int64_t>::min();
270 #else
271  abort();
272 #endif
273  }
274 }
275 
276 // scale is 10^{3,6,9}
277 extern "C" ALWAYS_INLINE DEVICE int64_t
278 DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale) {
279  return floor_div(timeval, scale * kSecsPerDay) * kSecsPerDay;
280 }
281 
282 extern "C" ALWAYS_INLINE DEVICE int64_t
284  const int64_t scale,
285  const int64_t null_val) {
286  if (timeval == null_val) {
287  return null_val;
288  }
289  return DateTruncateHighPrecisionToDate(timeval, scale);
290 }
291 
292 namespace {
293 
294 struct EraTime {
295  int64_t const era;
296  int const yoe; // year-of-era
297  int const moy; // month-of-year (March = 0)
298  int const dom; // day-of-month
299  int const sod; // second-of-day
300 
301  DEVICE static EraTime make(int64_t const time) {
302  int64_t const day = floor_div(time, kSecsPerDay);
303  int64_t const era = floor_div(day - kEpochAdjustedDays, kDaysPer400Years);
304  int const sod = time - day * kSecsPerDay;
305  int const doe = day - kEpochAdjustedDays - era * kDaysPer400Years;
306  int const yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
307  int const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
308  int const moy = (5 * doy + 2) / 153;
309  int const dom = doy - (153 * moy + 2) / 5;
310  return {era, yoe, moy, dom, sod};
311  }
312 
313  DEVICE EraTime operator-() const { return {-era, -yoe, -moy, -dom, -sod}; }
314 
316  return {era - rhs.era, yoe - rhs.yoe, moy - rhs.moy, dom - rhs.dom, sod - rhs.sod};
317  }
318 
319  enum Field { ERA, YOE, MOY, DOM, SOD };
320  // Sign of EraTime starting at field.
321  DEVICE int sign(Field const field) const {
322  switch (field) {
323  case ERA:
324  if (era != 0) {
325  return era < 0 ? -1 : 1;
326  }
327  case YOE:
328  if (yoe != 0) {
329  return yoe < 0 ? -1 : 1;
330  }
331  case MOY:
332  if (moy != 0) {
333  return moy < 0 ? -1 : 1;
334  }
335  case DOM:
336  if (dom != 0) {
337  return dom < 0 ? -1 : 1;
338  }
339  case SOD:
340  if (sod != 0) {
341  return sod < 0 ? -1 : 1;
342  }
343  default:
344  return 0;
345  }
346  }
347 
348  DEVICE int64_t count(DatetruncField const field) const {
349  int const sgn = sign(ERA);
350  EraTime const ut = sgn == -1 ? -*this : *this; // Unsigned time
351  switch (field) {
352  case dtMONTH:
353  return sgn * (12 * (400 * ut.era + ut.yoe) + ut.moy - (ut.sign(DOM) == -1));
354  case dtQUARTER: {
355  int const quarters = ut.moy / 3;
356  int const rem = ut.moy % 3;
357  return sgn * (4 * (400 * ut.era + ut.yoe) + quarters -
358  (rem < 0 || (rem == 0 && ut.sign(DOM) == -1)));
359  }
360  case dtYEAR:
361  return sgn * (400 * ut.era + ut.yoe - (ut.sign(MOY) == -1));
362  case dtDECADE: {
363  uint64_t const decades = (400 * ut.era + ut.yoe) / 10;
364  unsigned const rem = (400 * ut.era + ut.yoe) % 10;
365  return sgn * (decades - (rem == 0 && ut.sign(MOY) == -1));
366  }
367  case dtCENTURY: {
368  uint64_t const centuries = (400 * ut.era + ut.yoe) / 100;
369  unsigned const rem = (400 * ut.era + ut.yoe) % 100;
370  return sgn * (centuries - (rem == 0 && ut.sign(MOY) == -1));
371  }
372  case dtMILLENNIUM: {
373  uint64_t const millennia = (400 * ut.era + ut.yoe) / 1000;
374  unsigned const rem = (400 * ut.era + ut.yoe) % 1000;
375  return sgn * (millennia - (rem == 0 && ut.sign(MOY) == -1));
376  }
377  default:
378 #ifdef __CUDACC__
379  return std::numeric_limits<int64_t>::min();
380 #else
381  abort();
382 #endif
383  }
384  }
385 };
386 
387 } // namespace
388 
389 extern "C" DEVICE int64_t DateDiff(const DatetruncField datepart,
390  const int64_t startdate,
391  const int64_t enddate) {
392  switch (datepart) {
393  case dtNANOSECOND:
394  return (enddate - startdate) * kNanoSecsPerSec;
395  case dtMICROSECOND:
396  return (enddate - startdate) * kMicroSecsPerSec;
397  case dtMILLISECOND:
398  return (enddate - startdate) * kMilliSecsPerSec;
399  case dtSECOND:
400  return enddate - startdate;
401  case dtMINUTE:
402  return (enddate - startdate) / kSecsPerMin;
403  case dtHOUR:
404  return (enddate - startdate) / kSecsPerHour;
405  case dtQUARTERDAY:
406  return (enddate - startdate) / (kSecsPerDay / 4);
407  case dtDAY:
408  return (enddate - startdate) / kSecsPerDay;
409  case dtWEEK:
410  case dtWEEK_SUNDAY:
411  case dtWEEK_SATURDAY:
412  return (enddate - startdate) / (7 * kSecsPerDay);
413  default:
414  return (EraTime::make(enddate) - EraTime::make(startdate)).count(datepart);
415  }
416 }
417 
418 extern "C" DEVICE int64_t DateDiffHighPrecision(const DatetruncField datepart,
419  const int64_t startdate,
420  const int64_t enddate,
421  const int32_t start_dim,
422  const int32_t end_dim) {
423  // Return pow(10,i). Only valid for i = 0, 3, 6, 9.
424  constexpr int pow10[10]{1, 0, 0, 1000, 0, 0, 1000 * 1000, 0, 0, 1000 * 1000 * 1000};
425  switch (datepart) {
426  case dtNANOSECOND:
427  case dtMICROSECOND:
428  case dtMILLISECOND: {
429  static_assert(dtMILLISECOND + 1 == dtMICROSECOND, "Please keep these consecutive.");
430  static_assert(dtMICROSECOND + 1 == dtNANOSECOND, "Please keep these consecutive.");
431  int const target_dim = (datepart - (dtMILLISECOND - 1)) * 3; // 3, 6, or 9.
432  int const delta_dim = end_dim - start_dim; // in [-9,9] multiple of 3
433  int const adj_dim = target_dim - (delta_dim < 0 ? start_dim : end_dim);
434  int64_t const numerator = delta_dim < 0 ? enddate * pow10[-delta_dim] - startdate
435  : enddate - startdate * pow10[delta_dim];
436  return adj_dim < 0 ? numerator / pow10[-adj_dim] : numerator * pow10[adj_dim];
437  }
438  default:
439  int64_t const end_seconds = floor_div(enddate, pow10[end_dim]);
440  int delta_ns = (enddate - end_seconds * pow10[end_dim]) * pow10[9 - end_dim];
441  int64_t const start_seconds = floor_div(startdate, pow10[start_dim]);
442  delta_ns -= (startdate - start_seconds * pow10[start_dim]) * pow10[9 - start_dim];
443  int64_t const delta_s = end_seconds - start_seconds;
444  // sub-second values must be accounted for when calling DateDiff. Examples:
445  // 2000-02-15 12:00:00.006 to 2000-03-15 12:00:00.005 is 0 months.
446  // 2000-02-15 12:00:00.006 to 2000-03-15 12:00:00.006 is 1 month.
447  int const adj_sec =
448  0 < delta_s && delta_ns < 0 ? -1 : delta_s < 0 && 0 < delta_ns ? 1 : 0;
449  return DateDiff(datepart, start_seconds, end_seconds + adj_sec);
450  }
451 }
452 
453 extern "C" DEVICE int64_t DateDiffNullable(const DatetruncField datepart,
454  const int64_t startdate,
455  const int64_t enddate,
456  const int64_t null_val) {
457  if (startdate == null_val || enddate == null_val) {
458  return null_val;
459  }
460  return DateDiff(datepart, startdate, enddate);
461 }
462 
463 extern "C" DEVICE int64_t DateDiffHighPrecisionNullable(const DatetruncField datepart,
464  const int64_t startdate,
465  const int64_t enddate,
466  const int32_t start_dim,
467  const int32_t end_dim,
468  const int64_t null_val) {
469  if (startdate == null_val || enddate == null_val) {
470  return null_val;
471  }
472  return DateDiffHighPrecision(datepart, startdate, enddate, start_dim, end_dim);
473 }
static constexpr int64_t kSecsPerDay
static constexpr uint32_t kSecsJanToMar1900
static constexpr uint32_t kUSecsPerDay
DEVICE int sign(Field const field) const
ALWAYS_INLINE DEVICE int64_t datetrunc_quarter(int64_t timeval)
int64_t DateTruncate(DatetruncField field, const int64_t timeval)
static constexpr int64_t kSecsPerHour
static constexpr int64_t kSecsPerMin
static constexpr int64_t kNanoSecsPerSec
ALWAYS_INLINE DEVICE int64_t datetrunc_millennium(int64_t timeval)
constexpr unsigned JANMAR
static constexpr int64_t kSecsPerQuarterDay
static DEVICE EraTime make(int64_t const time)
ALWAYS_INLINE DEVICE int64_t datetrunc_quarterday(int64_t timeval)
DEVICE int64_t DateDiffNullable(const DatetruncField datepart, const int64_t startdate, const int64_t enddate, const int64_t null_val)
#define STATIC_QUAL
DEVICE int64_t DateDiffHighPrecisionNullable(const DatetruncField datepart, const int64_t startdate, const int64_t enddate, const int32_t start_dim, const int32_t end_dim, const int64_t null_val)
ALWAYS_INLINE DEVICE int64_t datetrunc_decade(int64_t timeval)
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
ALWAYS_INLINE DEVICE int64_t datetrunc_hour(int64_t timeval)
static constexpr uint32_t kEpochOffsetYear1900
#define DEVICE
static constexpr int64_t kMilliSecsPerSec
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
ALWAYS_INLINE DEVICE int64_t datetrunc_week_monday(int64_t timeval)
ALWAYS_INLINE DEVICE int64_t datetrunc_week_sunday(int64_t timeval)
static constexpr int32_t kEpochAdjustedDays
DatetruncField
Definition: DateTruncate.h:27
DEVICE EraTime operator-(EraTime const &rhs)
ALWAYS_INLINE DEVICE int64_t datetrunc_week(int64_t timeval)
ALWAYS_INLINE DEVICE int64_t DateTruncateHighPrecisionToDateNullable(const int64_t timeval, const int64_t scale, const int64_t null_val)
ALWAYS_INLINE DEVICE int64_t datetrunc_year(int64_t timeval)
static constexpr uint32_t kSecondsPer4YearCycle
static constexpr int64_t kDaysPer400Years
constexpr unsigned MARJAN
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)
DEVICE int64_t DateDiff(const DatetruncField datepart, const int64_t startdate, const int64_t enddate)
DEVICE int64_t count(DatetruncField const field) const
ALWAYS_INLINE DEVICE int64_t datetrunc_month(int64_t timeval)
ALWAYS_INLINE DEVICE int64_t datetrunc_century(int64_t timeval)
ALWAYS_INLINE DEVICE int64_t datetrunc_week_saturday(int64_t timeval)
DEVICE int64_t DateDiffHighPrecision(const DatetruncField datepart, const int64_t startdate, const int64_t enddate, const int32_t start_dim, const int32_t end_dim)
ALWAYS_INLINE DEVICE int64_t datetrunc_minute(int64_t timeval)
ALWAYS_INLINE DEVICE int64_t datetrunc_day(int64_t timeval)
ALWAYS_INLINE DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
static constexpr uint32_t kSecondsPerNonLeapYear
#define ALWAYS_INLINE
static constexpr int64_t kMicroSecsPerSec
static constexpr int32_t kMonsPerYear