Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
yiguolei committed Nov 22, 2024
1 parent 03b6ad5 commit 1b7f7d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions be/src/util/time_lut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void TimeLUTImpl::init_time_lut() {
}
}

uint8_t calc_week(uint16_t year, uint8_t month, uint8_t day, bool monday_first, bool week_year,
uint8_t calc_week(uint32_t year, uint32_t month, uint32_t day, bool monday_first, bool week_year,
bool first_weekday, uint16_t* to_year) {
uint32_t day_nr = calc_daynr(year, month, day);
uint32_t daynr_first_day = calc_daynr(year, 1, 1);
Expand Down Expand Up @@ -97,7 +97,7 @@ uint8_t calc_weekday(uint64_t day_nr, bool is_sunday_first_day) {
return (uint8_t)((day_nr + 5L + (is_sunday_first_day ? 1L : 0L)) % 7);
}

uint32_t calc_daynr(uint16_t year, uint8_t month, uint8_t day) {
uint32_t calc_daynr(uint32_t year, uint32_t month, uint32_t day) {
// date_day_offet_dict range from [1900-01-01, 2039-12-31]
if (date_day_offset_dict::can_speed_up_calc_daynr(year) &&
LIKELY(date_day_offset_dict::get_dict_init())) {
Expand Down Expand Up @@ -126,7 +126,7 @@ uint32_t calc_daynr(uint16_t year, uint8_t month, uint8_t day) {
return delsum + y / 4 - y / 100 + y / 400;
}

uint32_t year_week(uint16_t yy, uint8_t month, uint8_t day) {
uint32_t year_week(uint32_t yy, uint32_t month, uint32_t day) {
//not covered by year_week_table, calculate at runtime
uint16_t to_year = 0;
// The range of the week in the year_week is 1-53, so the mode WEEK_YEAR is always true.
Expand Down
6 changes: 3 additions & 3 deletions be/src/util/time_lut.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ constexpr uint16_t LUT_END_YEAR = 2030;
constexpr uint8_t NUM_MONTHS = 12;
constexpr uint8_t NUM_DAYS = 31;

uint32_t year_week(uint16_t yy, uint8_t month, uint8_t day);
uint32_t year_week(uint32_t yy, uint32_t month, uint32_t day);

uint32_t calc_daynr(uint16_t year, uint8_t month, uint8_t day);
uint32_t calc_daynr(uint32_t year, uint32_t month, uint32_t day);

uint8_t calc_weekday(uint64_t day_nr, bool is_sunday_first_day);

bool is_leap(uint32_t year);

uint32_t calc_days_in_year(uint32_t year);

uint8_t calc_week(uint16_t yy, uint8_t month, uint8_t day, bool monday_first, bool week_year,
uint8_t calc_week(uint32_t yy, uint32_t month, uint32_t day, bool monday_first, bool week_year,
bool first_weekday, uint16_t* to_year);

class TimeLUTImpl {
Expand Down
22 changes: 11 additions & 11 deletions be/src/vec/runtime/vdatetime_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ bool VecDateTimeValue::date_add_interval(const TimeInterval& interval) {
int64_t seconds = (_day - 1) * 86400L + _hour * 3600L + _minute * 60 + _second +
sign * (interval.day * 86400 + interval.hour * 3600 +
interval.minute * 60 + interval.second);
int32_t days = seconds / 86400;
int32_t days = cast_set<int32_t>(seconds / 86400);
seconds %= 86400L;
if (seconds < 0) {
seconds += 86400L;
Expand All @@ -1671,7 +1671,7 @@ bool VecDateTimeValue::date_add_interval(const TimeInterval& interval) {
}
} else if constexpr ((unit == DAY) || (unit == WEEK)) {
// This only change day information, not change second information
uint32_t day_nr = daynr() + interval.day * sign;
uint32_t day_nr = cast_set<int32_t>(daynr() + interval.day * sign);
if (!get_date_from_daynr(day_nr)) {
return false;
}
Expand Down Expand Up @@ -1716,7 +1716,7 @@ bool VecDateTimeValue::date_set_interval(const TimeInterval& interval) {
// This may change the day information
int64_t seconds = interval.day * 86400L + interval.hour * 3600 + interval.minute * 60 +
interval.second;
int64_t days = seconds / 86400;
int32_t days = cast_set<int32_t>(seconds / 86400);
seconds %= 86400L;
_second = (uint8_t)(seconds % 60);
_minute = (uint8_t)((seconds / 60) % 60);
Expand Down Expand Up @@ -2651,7 +2651,7 @@ bool DateV2Value<T>::from_date_format_str(const char* format, int format_len, co

// Year day
if (yearday > 0) {
uint64_t days = doris::calc_daynr(year, 1, 1) + yearday - 1;
uint32_t days = doris::calc_daynr(year, 1, 1) + yearday - 1;
if (!get_date_from_daynr(days)) {
return false;
}
Expand All @@ -2664,7 +2664,7 @@ bool DateV2Value<T>::from_date_format_str(const char* format, int format_len, co
(!strict_week_number && strict_week_number_year >= 0)) {
return false;
}
uint64_t days =
uint32_t days =
doris::calc_daynr(strict_week_number ? strict_week_number_year : year, 1, 1);

uint8_t weekday_b = doris::calc_weekday(days, sunday_first);
Expand Down Expand Up @@ -3797,17 +3797,17 @@ bool DateV2Value<T>::from_date_int64(int64_t value) {
uint64_t date = value / 1000000;

auto [year, month, day, hour, minute, second] = std::tuple {0, 0, 0, 0, 0, 0};
year = date / 10000;
year = (int)(date / 10000);
date %= 10000;
month = date / 100;
day = date % 100;
month = int(date / 100);
day = int(date % 100);

if constexpr (is_datetime) {
uint64_t time = value % 1000000;
hour = time / 10000;
hour = int(time / 10000);
time %= 10000;
minute = time / 100;
second = time % 100;
minute = int(time / 100);
second = int(time % 100);
return check_range_and_set_time(year, month, day, hour, minute, second, 0);
} else {
return check_range_and_set_time(year, month, day, 0, 0, 0, 0);
Expand Down

0 comments on commit 1b7f7d2

Please sign in to comment.