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();
117 const int64_t number,
118 const int64_t timeval,
121 constexpr
unsigned pow10[10]{
122 1, 0, 0, 1000, 0, 0, 1000 * 1000, 0, 0, 1000 * 1000 * 1000};
129 unsigned const field_dim = (field - (
daMILLISECOND - 1)) * 3;
130 int const adj_dim = dim - field_dim;
132 return timeval +
floor_div(number, pow10[-adj_dim]);
134 return timeval + number * pow10[adj_dim];
138 unsigned const scale = pow10[dim];
139 return DateAdd(field, number,
floor_div(timeval, scale)) * scale +
145 const int64_t number,
146 const int64_t timeval,
147 const int64_t null_val) {
148 if (timeval == null_val) {
151 return DateAdd(field, number, timeval);
156 const int64_t number,
157 const int64_t timeval,
159 const int64_t null_val) {
160 if (timeval == null_val) {
163 return DateAddHighPrecision(field, number, timeval, dim);
166 #endif // EXECUTE_INCLUDE
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept