fix timediff bug
This commit is contained in:
33
deps/oblib/src/lib/timezone/ob_time_convert.cpp
vendored
33
deps/oblib/src/lib/timezone/ob_time_convert.cpp
vendored
@ -2134,7 +2134,6 @@ int ObTimeConverter::str_to_ob_time_without_date(const ObString& str, ObTime& ob
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int ObTimeConverter::str_to_ob_time_format(const ObString &str, const ObString &fmt, ObTime &ob_time, int16_t *scale)
|
int ObTimeConverter::str_to_ob_time_format(const ObString &str, const ObString &fmt, ObTime &ob_time, int16_t *scale)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
@ -2325,8 +2324,8 @@ int ObTimeConverter::str_to_ob_time_format(const ObString& str, const ObString&
|
|||||||
}
|
}
|
||||||
case 'W': {
|
case 'W': {
|
||||||
name.assign_ptr(const_cast<char *>(str_pos), static_cast<int32_t>(str_end - str_pos));
|
name.assign_ptr(const_cast<char *>(str_pos), static_cast<int32_t>(str_end - str_pos));
|
||||||
if (OB_SUCC(get_str_array_idx(name, WDAY_NAMES, static_cast<int32_t>(DAYS_PER_WEEK),
|
if (OB_SUCC(get_str_array_idx(
|
||||||
ob_time.parts_[DT_WDAY]))) {
|
name, WDAY_NAMES, static_cast<int32_t>(DAYS_PER_WEEK), ob_time.parts_[DT_WDAY]))) {
|
||||||
str_pos += WDAY_NAMES[ob_time.parts_[DT_WDAY]].len_;
|
str_pos += WDAY_NAMES[ob_time.parts_[DT_WDAY]].len_;
|
||||||
week_day_elements.weekday_set_ = true;
|
week_day_elements.weekday_set_ = true;
|
||||||
week_day_elements.weekday_value_ = ob_time.parts_[DT_WDAY] % DAYS_PER_WEEK;
|
week_day_elements.weekday_value_ = ob_time.parts_[DT_WDAY] % DAYS_PER_WEEK;
|
||||||
@ -2395,8 +2394,7 @@ int ObTimeConverter::str_to_ob_time_format(const ObString& str, const ObString&
|
|||||||
}
|
}
|
||||||
if (OB_FAIL(handle_year_week_wday(week_day_elements, ob_time))) {
|
if (OB_FAIL(handle_year_week_wday(week_day_elements, ob_time))) {
|
||||||
LOG_WARN("handle %u %x %v and %w value failed", K(ret));
|
LOG_WARN("handle %u %x %v and %w value failed", K(ret));
|
||||||
} else if (0 == ob_time.parts_[DT_MON] && 0 == ob_time.parts_[DT_MDAY]
|
} else if (0 == ob_time.parts_[DT_MON] && 0 == ob_time.parts_[DT_MDAY] && 0 == ob_time.parts_[DT_YEAR]) {
|
||||||
&& 0 == ob_time.parts_[DT_YEAR]) {
|
|
||||||
if (OB_FAIL(validate_time(ob_time))) {
|
if (OB_FAIL(validate_time(ob_time))) {
|
||||||
LOG_WARN("time value is invalid or out of range", K(ret), K(str));
|
LOG_WARN("time value is invalid or out of range", K(ret), K(str));
|
||||||
}
|
}
|
||||||
@ -2423,16 +2421,16 @@ int ObTimeConverter::calc_date_with_year_week_wday(const ObYearWeekWdayElems &el
|
|||||||
// now we get weekday of %X-01-01: tmp_ot.parts_[DT_WDAY]
|
// now we get weekday of %X-01-01: tmp_ot.parts_[DT_WDAY]
|
||||||
const bool is_sunday_start = elements.is_upper_week_set();
|
const bool is_sunday_start = elements.is_upper_week_set();
|
||||||
int32_t week = elements.week_value_;
|
int32_t week = elements.week_value_;
|
||||||
int32_t weekday = is_sunday_start ? elements.weekday_value_
|
int32_t weekday =
|
||||||
: ((elements.weekday_value_ + DAYS_PER_WEEK - 1) % DAYS_PER_WEEK) + 1;
|
is_sunday_start ? elements.weekday_value_ : ((elements.weekday_value_ + DAYS_PER_WEEK - 1) % DAYS_PER_WEEK) + 1;
|
||||||
// %X%V means week start with sunday and the first week in the year must contain sunday.
|
// %X%V means week start with sunday and the first week in the year must contain sunday.
|
||||||
const int32_t first_week_monday_offset_upper[DAYS_PER_WEEK] = {1, 7, 6, 5, 4, 3, 2};
|
const int32_t first_week_monday_offset_upper[DAYS_PER_WEEK] = {1, 7, 6, 5, 4, 3, 2};
|
||||||
// %X%V means week start with monday and the first week in the year must contain at least 4 days.
|
// %X%V means week start with monday and the first week in the year must contain at least 4 days.
|
||||||
const int32_t first_week_monday_offset_lower[DAYS_PER_WEEK] = {1, 0, -1, -2, -3, 3, 2};
|
const int32_t first_week_monday_offset_lower[DAYS_PER_WEEK] = {1, 0, -1, -2, -3, 3, 2};
|
||||||
int32_t offset = (elements.is_upper_week_set() ?
|
int32_t offset =
|
||||||
first_week_monday_offset_upper[tmp_ot.parts_[DT_WDAY] % DAYS_PER_WEEK] :
|
(elements.is_upper_week_set() ? first_week_monday_offset_upper[tmp_ot.parts_[DT_WDAY] % DAYS_PER_WEEK]
|
||||||
first_week_monday_offset_lower[tmp_ot.parts_[DT_WDAY] % DAYS_PER_WEEK])
|
: first_week_monday_offset_lower[tmp_ot.parts_[DT_WDAY] % DAYS_PER_WEEK]) +
|
||||||
+ (week - 1) * DAYS_PER_WEEK + (weekday - 1);
|
(week - 1) * DAYS_PER_WEEK + (weekday - 1);
|
||||||
int32_t date_value = tmp_ot.parts_[DT_DATE] + offset;
|
int32_t date_value = tmp_ot.parts_[DT_DATE] + offset;
|
||||||
if (OB_FAIL(date_to_ob_time(date_value, ot))) {
|
if (OB_FAIL(date_to_ob_time(date_value, ot))) {
|
||||||
LOG_WARN("date to ob time failed", K(ret));
|
LOG_WARN("date to ob time failed", K(ret));
|
||||||
@ -2445,8 +2443,8 @@ int ObTimeConverter::handle_year_week_wday(const ObYearWeekWdayElems &elements,
|
|||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
//%X/%x must be used together with %V/%v
|
//%X/%x must be used together with %V/%v
|
||||||
if ((elements.is_year_set() || elements.is_week_v_set())
|
if ((elements.is_year_set() || elements.is_week_v_set()) &&
|
||||||
&& !(elements.year_set_state_ == elements.week_set_state_ && elements.is_week_v_set())) {
|
!(elements.year_set_state_ == elements.week_set_state_ && elements.is_week_v_set())) {
|
||||||
ret = OB_INVALID_DATE_VALUE;
|
ret = OB_INVALID_DATE_VALUE;
|
||||||
MEMSET(ot.parts_, 0, sizeof(*ot.parts_) * TOTAL_PART_CNT);
|
MEMSET(ot.parts_, 0, sizeof(*ot.parts_) * TOTAL_PART_CNT);
|
||||||
ot.parts_[DT_DATE] = ZERO_DATE;
|
ot.parts_[DT_DATE] = ZERO_DATE;
|
||||||
@ -3330,8 +3328,12 @@ int ObTimeConverter::str_to_ob_time_oracle_dfm(
|
|||||||
if (OB_ISNULL(cvrt_ctx.tz_info_)) {
|
if (OB_ISNULL(cvrt_ctx.tz_info_)) {
|
||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_UNEXPECTED;
|
||||||
LOG_WARN("session timezone info is null", K(ret));
|
LOG_WARN("session timezone info is null", K(ret));
|
||||||
} else if (sub_timezone_offset(*(cvrt_ctx.tz_info_), ObString(),
|
} else if (sub_timezone_offset(*(cvrt_ctx.tz_info_),
|
||||||
utc_curr_time_copy, session_tz_offset, session_tz_id, session_tran_type_id)) {
|
ObString(),
|
||||||
|
utc_curr_time_copy,
|
||||||
|
session_tz_offset,
|
||||||
|
session_tz_id,
|
||||||
|
session_tran_type_id)) {
|
||||||
LOG_WARN("get session timezone offset failed", K(ret));
|
LOG_WARN("get session timezone offset failed", K(ret));
|
||||||
} else if (OB_FAIL(datetime_to_date(utc_curr_time, cvrt_ctx.tz_info_, cur_date))) {
|
} else if (OB_FAIL(datetime_to_date(utc_curr_time, cvrt_ctx.tz_info_, cur_date))) {
|
||||||
LOG_WARN("timestamp to date failed", K(ret));
|
LOG_WARN("timestamp to date failed", K(ret));
|
||||||
@ -5862,7 +5864,6 @@ int ObTimeConverter::calc_last_date_of_the_month(
|
|||||||
ret = OB_INVALID_ARGUMENT;
|
ret = OB_INVALID_ARGUMENT;
|
||||||
LOG_WARN("unexpected dest type", K(ret), K(dest_type));
|
LOG_WARN("unexpected dest type", K(ret), K(dest_type));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG_DEBUG("debug calc_last_mday", K(ob_time), K(ori_datetime_value), K(result_date_value));
|
LOG_DEBUG("debug calc_last_mday", K(ob_time), K(ori_datetime_value), K(result_date_value));
|
||||||
|
|||||||
@ -133,8 +133,8 @@ int ObExprTimeDiff::calc_timediff(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& e
|
|||||||
expr_datum.set_null();
|
expr_datum.set_null();
|
||||||
} else {
|
} else {
|
||||||
int64_t int64_diff = 0;
|
int64_t int64_diff = 0;
|
||||||
ObTime ot1;
|
ObTime ot1(DT_TYPE_TIME);
|
||||||
ObTime ot2;
|
ObTime ot2(DT_TYPE_TIME);
|
||||||
if (OB_FAIL(ob_datum_to_ob_time_without_date(
|
if (OB_FAIL(ob_datum_to_ob_time_without_date(
|
||||||
*param_datum1, expr.args_[0]->datum_meta_.type_, get_timezone_info(session), ot1))) {
|
*param_datum1, expr.args_[0]->datum_meta_.type_, get_timezone_info(session), ot1))) {
|
||||||
LOG_WARN("cast the first param failed", K(ret));
|
LOG_WARN("cast the first param failed", K(ret));
|
||||||
|
|||||||
Reference in New Issue
Block a user