From 347c164c35eddab388009470e6848cb361ac93f8 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 15:22:53 +0200 Subject: Merging upstream version 1:10.11.8. Signed-off-by: Daniel Baumann --- sql/item_timefunc.cc | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'sql/item_timefunc.cc') diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index db38e44d..0ac75f90 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2942,7 +2942,7 @@ bool Item_extract::fix_length_and_dec(THD *thd) switch (int_type) { case INTERVAL_YEAR: set_date_length(4); break; // YYYY case INTERVAL_YEAR_MONTH: set_date_length(6); break; // YYYYMM - case INTERVAL_QUARTER: set_date_length(2); break; // 1..4 + case INTERVAL_QUARTER: set_date_length(1); break; // 1..4 case INTERVAL_MONTH: set_date_length(2); break; // MM case INTERVAL_WEEK: set_date_length(2); break; // 0..52 case INTERVAL_DAY: set_day_length(daylen); break; // DD @@ -3507,6 +3507,24 @@ bool Item_func_timediff::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzy if (l_time1.neg != l_time2.neg) l_sign= -l_sign; + if (l_time1.time_type == MYSQL_TIMESTAMP_TIME) + { + /* + In case of TIME-alike arguments: + TIMEDIFF('38:59:59', '839:00:00') + let's truncate extra fractional seconds that might appear if the argument + values were out of the supported TIME range. For example, args[n]->get_time() + for the string literal '839:00:00' returns TIME'838:59:59.999999'. + The fractional part must be truncated according to this->decimals, + to avoid returning more fractional seconds than it was detected + during this->fix_length_and_dec(). + Note, the thd rounding mode should not be important here, as we're removing + redundant digits from the maximum possible value: '838:59:59.999999'. + */ + my_time_trunc(&l_time1, decimals); + my_time_trunc(&l_time2, decimals); + } + if (calc_time_diff(&l_time1, &l_time2, l_sign, &l_time3, fuzzydate)) return (null_value= 1); -- cgit v1.2.3