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