19 #ifdef EXECUTE_INCLUDE
28 class MonthDaySecond {
34 DEVICE static unsigned clampDom(
unsigned yoe,
unsigned moy,
unsigned dom) {
35 constexpr
unsigned max_days[11]{30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 30};
39 unsigned const max_day =
40 moy == 11 ? 27 + (++yoe % 4 == 0 && (yoe % 100 != 0 || yoe == 400))
42 return dom < max_day ? dom : max_day;
47 DEVICE MonthDaySecond(int64_t
const timeval) {
52 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365;
53 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
54 unsigned const moy = (5 * doy + 2) / 153;
55 dom = doy - (153 * moy + 2) / 5;
56 months = (era * 400 + yoe) * 12 + moy;
59 DEVICE MonthDaySecond
const& addMonths(int64_t
const months) {
60 this->months += months;
65 DEVICE int64_t unixtime()
const {
66 int64_t
const era =
floor_div(months, 12 * 400);
67 unsigned const moe = months - era * (12 * 400);
68 unsigned const yoe = moe / 12;
69 unsigned const moy = moe % 12;
70 unsigned const doy = (153 * moy + 2) / 5 + clampDom(yoe, moy, dom);
71 unsigned const doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
80 const int64_t timeval) {
83 return timeval + number;
95 return MonthDaySecond(timeval).addMonths(number).unixtime();
97 return MonthDaySecond(timeval).addMonths(number * 3).unixtime();
99 return MonthDaySecond(timeval).addMonths(number * 12).unixtime();
101 return MonthDaySecond(timeval).addMonths(number * 120).unixtime();
103 return MonthDaySecond(timeval).addMonths(number * 1200).unixtime();
105 return MonthDaySecond(timeval).addMonths(number * 12000).unixtime();
118 const int64_t number,
119 const int64_t timeval,
122 constexpr
unsigned pow10[10]{
123 1, 0, 0, 1000, 0, 0, 1000 * 1000, 0, 0, 1000 * 1000 * 1000};
130 unsigned const field_dim = (field - (
daMILLISECOND - 1)) * 3;
131 int const adj_dim = dim - field_dim;
133 return timeval +
floor_div(number, pow10[-adj_dim]);
135 return timeval + number * pow10[adj_dim];
139 unsigned const scale = pow10[dim];
140 return DateAdd(field, number,
floor_div(timeval, scale)) * scale +
147 const int64_t number,
148 const int64_t timeval,
149 const int64_t null_val) {
150 if (timeval == null_val) {
153 return DateAdd(field, number, timeval);
158 const int64_t number,
159 const int64_t timeval,
161 const int64_t null_val) {
162 if (timeval == null_val) {
165 return DateAddHighPrecision(field, number, timeval, dim);
168 #endif // EXECUTE_INCLUDE
RUNTIME_EXPORT DEVICE int64_t DateAddHighPrecisionNullable(const DateaddField field, const int64_t number, const int64_t timeval, const int32_t dim, const int64_t null_val)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept