OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExtractFromTime.h
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 #ifndef QUERYENGINE_EXTRACTFROMTIME_H
18 #define QUERYENGINE_EXTRACTFROMTIME_H
19 
20 #include <cstdint>
21 #include <ctime>
22 #include "../Shared/funcannotations.h"
23 
24 static constexpr int64_t kNanoSecsPerSec = 1000000000;
25 static constexpr int64_t kMicroSecsPerSec = 1000000;
26 static constexpr int64_t kMilliSecsPerSec = 1000;
27 static constexpr int64_t kSecsPerMin = 60;
28 static constexpr int64_t kMinsPerHour = 60;
29 static constexpr int64_t kHoursPerDay = 24;
30 static constexpr int64_t kSecPerHour = 3600;
31 static constexpr int64_t kSecsPerDay = 86400;
32 static constexpr int64_t kSecsPerQuarterDay = 21600;
33 static constexpr int32_t kDaysPerWeek = 7;
34 static constexpr int32_t kMonsPerYear = 12;
35 static constexpr int64_t kSecsPerHalfDay = 43200;
36 static constexpr int64_t kMinsPerMonth = 43200; // Month of 30 days
37 
38 static constexpr int32_t kYearBase = 1900;
39 
40 /* move epoch from 01.01.1970 to 01.03.2000 - this is the first day of new
41  * 400-year long cycle, right after additional day of leap year. This adjustment
42  * is required only for date calculation, so instead of modifying time value
43  * (which would require 64-bit operations to work correctly) it's enough to
44  * adjust the calculated number of days since epoch. */
45 static constexpr int32_t kEpochAdjustedDays = 11017;
46 /* year to which the adjustment was made */
47 static constexpr int32_t kEpochAdjustedYears = 2000;
48 /* 1st March of 2000 is Wednesday */
49 static constexpr int32_t kEpochAdjustedWDay = 3;
50 /* there are 97 leap years in 400-year periods. ((400 - 97) * 365 + 97 * 366) */
51 static constexpr int64_t kDaysPer400Years = 146097;
52 /* there are 24 leap years in 100-year periods. ((100 - 24) * 365 + 24 * 366) */
53 static constexpr int64_t kDaysPer100Years = 36524;
54 /* there is one leap year every 4 years */
55 static constexpr int32_t kDaysPer4Years = 3 * 365 + 366;
56 /* number of days in a non-leap year */
57 static constexpr int32_t kDaysPerYear = 365;
58 /* number of days in January */
59 static constexpr int32_t kDaysInJanuary = 31;
60 /* number of days in non-leap February */
61 static constexpr int32_t kDaysInFebruary = 28;
62 
63 static constexpr uint32_t kSecondsPerNonLeapYear = 31536000;
64 static constexpr uint32_t kSecondsPer4YearCycle = 126230400;
65 static constexpr uint32_t kUSecsPerDay = 86400;
66 static constexpr uint32_t kEpochOffsetYear1900 = 2208988800;
67 static constexpr uint32_t kSecsJanToMar1900 = 5097600;
68 
86 };
87 
88 // Shared by DateTruncate
89 DEVICE int32_t extract_dow(const int64_t lcltime);
90 
91 DEVICE tm gmtime_r_newlib(const int64_t lcltime, tm& res);
92 
94  const int64_t timeval);
95 
96 #endif // QUERYENGINE_EXTRACTFROMTIME_H
static constexpr int64_t kSecsPerDay
static constexpr uint32_t kSecsJanToMar1900
static constexpr uint32_t kUSecsPerDay
static constexpr int32_t kDaysPerYear
static constexpr int64_t kSecsPerMin
static constexpr int64_t kNanoSecsPerSec
static constexpr int64_t kSecsPerQuarterDay
static constexpr int64_t kMinsPerHour
static constexpr int32_t kDaysInJanuary
static constexpr uint32_t kEpochOffsetYear1900
static constexpr int32_t kYearBase
static constexpr int64_t kSecsPerHalfDay
#define DEVICE
static constexpr int64_t kMinsPerMonth
static constexpr int64_t kMilliSecsPerSec
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
DEVICE int32_t extract_dow(const int64_t lcltime)
static constexpr int32_t kEpochAdjustedDays
DEVICE tm gmtime_r_newlib(const int64_t lcltime, tm &res)
NEVER_INLINE DEVICE int64_t ExtractFromTime(ExtractField field, const int64_t timeval)
static constexpr int32_t kDaysPerWeek
static constexpr int32_t kDaysInFebruary
static constexpr int32_t kEpochAdjustedYears
static constexpr uint32_t kSecondsPer4YearCycle
static constexpr int64_t kHoursPerDay
static constexpr int64_t kDaysPer400Years
static constexpr int64_t kSecPerHour
ExtractField
#define NEVER_INLINE
static constexpr int32_t kDaysPer4Years
static constexpr uint32_t kSecondsPerNonLeapYear
static constexpr int64_t kMicroSecsPerSec
static constexpr int32_t kEpochAdjustedWDay
static constexpr int32_t kMonsPerYear
static constexpr int64_t kDaysPer100Years