Commit 25ad38ab authored by Alexander Barkov's avatar Alexander Barkov

MDEV-17288 Replace Item_func::get_arg0_date() to Date/Datetime methods

parent 50003a95
......@@ -177,12 +177,6 @@ class Item_func :public Item_func_or_sum,
virtual void print(String *str, enum_query_type query_type);
void print_op(String *str, enum_query_type query_type);
void print_args(String *str, uint from, enum_query_type query_type);
inline bool get_arg0_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{
DBUG_ASSERT(!(fuzzy_date & TIME_TIME_ONLY));
Datetime dt(current_thd, args[0], fuzzy_date);
return (null_value= dt.copy_to_mysql_time(ltime));
}
bool is_null() {
update_null_value();
return null_value;
......
This diff is collapsed.
......@@ -175,7 +175,7 @@ int calc_weekday(long daynr,bool sunday_first_day_of_week)
next week is week 1.
*/
uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year)
uint calc_week(const MYSQL_TIME *l_time, uint week_behaviour, uint *year)
{
uint days;
ulong daynr=calc_daynr(l_time->year,l_time->month,l_time->day);
......
......@@ -120,7 +120,7 @@ int my_time_compare(const MYSQL_TIME *a, const MYSQL_TIME *b);
void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
void calc_time_from_sec(MYSQL_TIME *to, ulong seconds, ulong microseconds);
uint calc_week(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
uint calc_week(const MYSQL_TIME *l_time, uint week_behaviour, uint *year);
int calc_weekday(long daynr,bool sunday_first_day_of_week);
bool parse_date_time_format(timestamp_type format_type,
......
......@@ -920,6 +920,31 @@ class Temporal_with_date: public Temporal
void check_date_or_invalidate(int *warn, sql_mode_t flags);
void make_from_item(THD *thd, Item *item, sql_mode_t flags);
void make_from_item(THD *thd, Item *item);
ulong daynr() const
{
return (ulong) ::calc_daynr((uint) year, (uint) month, (uint) day);
}
ulong dayofyear() const
{
return (ulong) (daynr() - ::calc_daynr(year, 1, 1) + 1);
}
uint quarter() const
{
return (month + 2) / 3;
}
uint week(uint week_behaviour) const
{
uint year;
return calc_week(this, week_behaviour, &year);
}
uint yearweek(uint week_behaviour) const
{
uint year;
uint week= calc_week(this, week_behaviour, &year);
return week + year * 100;
}
Temporal_with_date()
{
time_type= MYSQL_TIMESTAMP_NONE;
......@@ -1025,6 +1050,32 @@ class Date: public Temporal_with_date
*ltime= *this;
return false;
}
ulong daynr() const
{
DBUG_ASSERT(is_valid_date_slow());
return Temporal_with_date::daynr();
}
ulong dayofyear() const
{
DBUG_ASSERT(is_valid_date_slow());
return Temporal_with_date::dayofyear();
}
uint quarter() const
{
DBUG_ASSERT(is_valid_date_slow());
return Temporal_with_date::quarter();
}
uint week(uint week_behaviour) const
{
DBUG_ASSERT(is_valid_date_slow());
return Temporal_with_date::week(week_behaviour);
}
uint yearweek(uint week_behaviour) const
{
DBUG_ASSERT(is_valid_date_slow());
return Temporal_with_date::yearweek(week_behaviour);
}
longlong to_longlong() const
{
return is_valid_date() ? (longlong) TIME_to_ulonglong_date(this) : 0LL;
......@@ -1175,11 +1226,40 @@ class Datetime: public Temporal_with_date
DBUG_ASSERT(is_valid_value_slow());
return time_type == MYSQL_TIMESTAMP_DATETIME;
}
bool check_date(longlong flags, int *warnings) const
{
DBUG_ASSERT(is_valid_datetime_slow());
return ::check_date(this, (year || month || day), flags, warnings);
}
bool check_date(longlong flags) const
{
int dummy; /* unused */
return check_date(flags, &dummy);
}
bool hhmmssff_is_zero() const
{
DBUG_ASSERT(is_valid_datetime_slow());
return hour == 0 && minute == 0 && second == 0 && second_part == 0;
}
ulong daynr() const
{
DBUG_ASSERT(is_valid_datetime_slow());
return Temporal_with_date::daynr();
}
longlong hhmmss_to_seconds_abs() const
{
DBUG_ASSERT(is_valid_datetime_slow());
return hour * 3600L + minute * 60 + second;
}
longlong hhmmss_to_seconds() const
{
return neg ? -hhmmss_to_seconds_abs() : hhmmss_to_seconds_abs();
}
longlong to_seconds() const
{
return hhmmss_to_seconds() + (longlong) daynr() * 24L * 3600L;
}
const MYSQL_TIME *get_mysql_time() const
{
DBUG_ASSERT(is_valid_datetime_slow());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment