OmniSciDB
c1a53651b2
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
ExtractFromTime.h
Go to the documentation of this file.
1
/*
2
* Copyright 2022 HEAVY.AI, 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
#ifndef QUERYENGINE_EXTRACTFROMTIME_H
18
#define QUERYENGINE_EXTRACTFROMTIME_H
19
20
#include <cstdint>
21
#include <ctime>
22
/* `../` is required for UDFCompiler */
23
#include "../Shared/funcannotations.h"
24
25
static
constexpr int64_t
kNanoSecsPerSec
= 1000000000;
26
static
constexpr int64_t
kMicroSecsPerSec
= 1000000;
27
static
constexpr int64_t
kMilliSecsPerSec
= 1000;
28
static
constexpr int64_t
kMilliSecsPerMin
= 60000;
29
static
constexpr int64_t
kMilliSecsPerHour
= 3600000;
30
static
constexpr int64_t
kMilliSecsPerDay
= 86400000;
31
static
constexpr int64_t
kSecsPerMin
= 60;
32
static
constexpr int64_t
kMinsPerHour
= 60;
33
static
constexpr int64_t
kHoursPerDay
= 24;
34
static
constexpr int64_t
kSecsPerHour
= 3600;
35
static
constexpr int64_t
kSecsPerDay
= 86400;
36
static
constexpr int64_t
kSecsPerQuarterDay
= 21600;
37
static
constexpr int32_t
kDaysPerWeek
= 7;
38
static
constexpr int32_t
kMonsPerYear
= 12;
39
static
constexpr int64_t
kSecsPerHalfDay
= 43200;
40
static
constexpr int64_t
kMinsPerMonth
= 43200;
// Month of 30 days
41
42
static
constexpr int32_t
kYearBase
= 1900;
43
44
/* move epoch from 01.01.1970 to 01.03.2000 - this is the first day of new
45
* 400-year long cycle, right after additional day of leap year. This adjustment
46
* is required only for date calculation, so instead of modifying time value
47
* (which would require 64-bit operations to work correctly) it's enough to
48
* adjust the calculated number of days since epoch. */
49
static
constexpr int32_t
kEpochAdjustedDays
= 11017;
50
/* year to which the adjustment was made */
51
static
constexpr int32_t
kEpochAdjustedYears
= 2000;
52
/* 1st March of 2000 is Wednesday */
53
static
constexpr int32_t
kEpochAdjustedWDay
= 3;
54
/* there are 97 leap years in 400-year periods. ((400 - 97) * 365 + 97 * 366) */
55
static
constexpr int64_t
kDaysPer400Years
= 146097;
56
/* there are 24 leap years in 100-year periods. ((100 - 24) * 365 + 24 * 366) */
57
static
constexpr int64_t
kDaysPer100Years
= 36524;
58
/* there is one leap year every 4 years */
59
static
constexpr int32_t
kDaysPer4Years
= 3 * 365 + 366;
60
/* number of days in a non-leap year */
61
static
constexpr int32_t
kDaysPerYear
= 365;
62
/* number of days in January */
63
static
constexpr int32_t
kDaysInJanuary
= 31;
64
/* number of days in non-leap February */
65
static
constexpr int32_t
kDaysInFebruary
= 28;
66
67
static
constexpr uint32_t
kSecondsPerNonLeapYear
= 31536000;
68
static
constexpr uint32_t
kSecondsPer4YearCycle
= 126230400;
69
static
constexpr uint32_t
kUSecsPerDay
= 86400;
70
static
constexpr uint32_t
kEpochOffsetYear1900
= 2208988800;
71
static
constexpr uint32_t
kSecsJanToMar1900
= 5097600;
72
73
// Number of days from March 1 to Jan 1.
74
constexpr
unsigned
MARJAN
= 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31;
75
constexpr
unsigned
JANMAR
= 31 + 28;
// leap day handled separately
76
77
enum
ExtractField
{
78
kYEAR
,
79
kQUARTER
,
80
kMONTH
,
81
kDAY
,
82
kHOUR
,
83
kMINUTE
,
84
kSECOND
,
85
kMILLISECOND
,
86
kMICROSECOND
,
87
kNANOSECOND
,
88
kDOW
,
89
kISODOW
,
90
kDOY
,
91
kEPOCH
,
92
kQUARTERDAY
,
93
kWEEK
,
94
kWEEK_SUNDAY
,
95
kWEEK_SATURDAY
,
96
kDATEEPOCH
,
97
kUNKNOWN_FIELD
98
};
99
100
DEVICE
int64_t
ExtractFromTime
(
ExtractField
field
,
const
int64_t timeval);
101
102
// Return floor(dividend / divisor).
103
// Assumes 0 < divisor.
104
DEVICE
inline
int64_t
floor_div
(int64_t
const
dividend, int64_t
const
divisor) {
105
return
(dividend < 0 ? dividend - (divisor - 1) : dividend) / divisor;
106
}
107
108
// Return remainer r of dividend / divisor, where 0 <= r < divisor.
109
// Assumes 0 < divisor.
110
DEVICE
inline
int64_t
unsigned_mod
(int64_t
const
dividend, int64_t
const
divisor) {
111
int64_t mod = dividend % divisor;
112
if
(mod < 0) {
113
mod += divisor;
114
}
115
return
mod;
116
}
117
118
#endif // QUERYENGINE_EXTRACTFROMTIME_H
kSecsPerDay
static constexpr int64_t kSecsPerDay
Definition:
ExtractFromTime.h:35
kSecsJanToMar1900
static constexpr uint32_t kSecsJanToMar1900
Definition:
ExtractFromTime.h:71
kUSecsPerDay
static constexpr uint32_t kUSecsPerDay
Definition:
ExtractFromTime.h:69
kDOW
Definition:
ExtractFromTime.h:88
kHOUR
Definition:
ExtractFromTime.h:82
kMINUTE
Definition:
ExtractFromTime.h:83
kSecsPerHour
static constexpr int64_t kSecsPerHour
Definition:
ExtractFromTime.h:34
kDaysPerYear
static constexpr int32_t kDaysPerYear
Definition:
ExtractFromTime.h:61
kWEEK
Definition:
ExtractFromTime.h:93
kSecsPerMin
static constexpr int64_t kSecsPerMin
Definition:
ExtractFromTime.h:31
kNanoSecsPerSec
static constexpr int64_t kNanoSecsPerSec
Definition:
ExtractFromTime.h:25
kDATEEPOCH
Definition:
ExtractFromTime.h:96
kQUARTERDAY
Definition:
ExtractFromTime.h:92
kMilliSecsPerDay
static constexpr int64_t kMilliSecsPerDay
Definition:
ExtractFromTime.h:30
kUNKNOWN_FIELD
Definition:
ExtractFromTime.h:97
kEPOCH
Definition:
ExtractFromTime.h:91
JANMAR
constexpr unsigned JANMAR
Definition:
ExtractFromTime.h:75
kSecsPerQuarterDay
static constexpr int64_t kSecsPerQuarterDay
Definition:
ExtractFromTime.h:36
kMinsPerHour
static constexpr int64_t kMinsPerHour
Definition:
ExtractFromTime.h:32
floor_div
DEVICE int64_t floor_div(int64_t const dividend, int64_t const divisor)
Definition:
ExtractFromTime.h:104
kDaysInJanuary
static constexpr int32_t kDaysInJanuary
Definition:
ExtractFromTime.h:63
kEpochOffsetYear1900
static constexpr uint32_t kEpochOffsetYear1900
Definition:
ExtractFromTime.h:70
kYearBase
static constexpr int32_t kYearBase
Definition:
ExtractFromTime.h:42
kMILLISECOND
Definition:
ExtractFromTime.h:85
kSecsPerHalfDay
static constexpr int64_t kSecsPerHalfDay
Definition:
ExtractFromTime.h:39
DEVICE
#define DEVICE
Definition:
funcannotations.h:20
kMilliSecsPerMin
static constexpr int64_t kMilliSecsPerMin
Definition:
ExtractFromTime.h:28
kMinsPerMonth
static constexpr int64_t kMinsPerMonth
Definition:
ExtractFromTime.h:40
kMilliSecsPerSec
static constexpr int64_t kMilliSecsPerSec
Definition:
ExtractFromTime.h:27
field
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition:
JsonAccessors.h:31
kEpochAdjustedDays
static constexpr int32_t kEpochAdjustedDays
Definition:
ExtractFromTime.h:49
kNANOSECOND
Definition:
ExtractFromTime.h:87
kMICROSECOND
Definition:
ExtractFromTime.h:86
kDaysPerWeek
static constexpr int32_t kDaysPerWeek
Definition:
ExtractFromTime.h:37
kDaysInFebruary
static constexpr int32_t kDaysInFebruary
Definition:
ExtractFromTime.h:65
kEpochAdjustedYears
static constexpr int32_t kEpochAdjustedYears
Definition:
ExtractFromTime.h:51
kSecondsPer4YearCycle
static constexpr uint32_t kSecondsPer4YearCycle
Definition:
ExtractFromTime.h:68
kHoursPerDay
static constexpr int64_t kHoursPerDay
Definition:
ExtractFromTime.h:33
kDOY
Definition:
ExtractFromTime.h:90
kWEEK_SUNDAY
Definition:
ExtractFromTime.h:94
kWEEK_SATURDAY
Definition:
ExtractFromTime.h:95
kDaysPer400Years
static constexpr int64_t kDaysPer400Years
Definition:
ExtractFromTime.h:55
kSECOND
Definition:
ExtractFromTime.h:84
MARJAN
constexpr unsigned MARJAN
Definition:
ExtractFromTime.h:74
unsigned_mod
DEVICE int64_t unsigned_mod(int64_t const dividend, int64_t const divisor)
Definition:
ExtractFromTime.h:110
ExtractFromTime
DEVICE int64_t ExtractFromTime(ExtractField field, const int64_t timeval)
Definition:
ExtractFromTime.cpp:294
kISODOW
Definition:
ExtractFromTime.h:89
ExtractField
ExtractField
Definition:
ExtractFromTime.h:77
kYEAR
Definition:
ExtractFromTime.h:78
kDaysPer4Years
static constexpr int32_t kDaysPer4Years
Definition:
ExtractFromTime.h:59
kMilliSecsPerHour
static constexpr int64_t kMilliSecsPerHour
Definition:
ExtractFromTime.h:29
kQUARTER
Definition:
ExtractFromTime.h:79
kSecondsPerNonLeapYear
static constexpr uint32_t kSecondsPerNonLeapYear
Definition:
ExtractFromTime.h:67
kDAY
Definition:
ExtractFromTime.h:81
kMicroSecsPerSec
static constexpr int64_t kMicroSecsPerSec
Definition:
ExtractFromTime.h:26
kEpochAdjustedWDay
static constexpr int32_t kEpochAdjustedWDay
Definition:
ExtractFromTime.h:53
kMonsPerYear
static constexpr int32_t kMonsPerYear
Definition:
ExtractFromTime.h:38
kMONTH
Definition:
ExtractFromTime.h:80
kDaysPer100Years
static constexpr int64_t kDaysPer100Years
Definition:
ExtractFromTime.h:57
QueryEngine
ExtractFromTime.h
Generated on Fri Jan 6 2023 06:29:41 for OmniSciDB by
1.8.5