MDEV-17203 Move fractional second truncation from Item_xxx_typecast::get_date() to Time and Datetime constructors

This commit is contained in:
Alexander Barkov 2018-09-16 12:40:57 +04:00
commit d93399746d
6 changed files with 68 additions and 59 deletions

View file

@ -1185,36 +1185,6 @@ bool time_to_datetime(MYSQL_TIME *ltime)
}
/**
Return a valid DATE or DATETIME value from an arbitrary MYSQL_TIME.
If ltime is TIME, it's first converted to DATETIME.
If ts_type is DATE, hhmmss is set to zero.
The date part of the result is checked against fuzzy_date.
@param ltime The value to convert.
@param fuzzy_date Flags to check date.
@param ts_type The type to convert to.
@return false on success, true of error (negative time).*/
bool
make_date_with_warn(MYSQL_TIME *ltime, ulonglong fuzzy_date,
timestamp_type ts_type)
{
DBUG_ASSERT(ts_type == MYSQL_TIMESTAMP_DATE ||
ts_type == MYSQL_TIMESTAMP_DATETIME);
if (ltime->time_type == MYSQL_TIMESTAMP_TIME && time_to_datetime(ltime))
{
/* e.g. negative time */
ErrConvTime str(ltime);
make_truncated_value_warning(current_thd, Sql_condition::WARN_LEVEL_WARN,
&str, ts_type, 0);
return true;
}
if ((ltime->time_type= ts_type) == MYSQL_TIMESTAMP_DATE)
ltime->hour= ltime->minute= ltime->second= ltime->second_part= 0;
return check_date_with_warn(ltime, fuzzy_date, ts_type);
}
/*
Convert a TIME value to DAY-TIME interval, e.g. for extraction:
EXTRACT(DAY FROM x), EXTRACT(HOUR FROM x), etc.