Commit 385ee993 authored by Alexander Barkov's avatar Alexander Barkov

A cleanup for MDEV-16852

Changing data types for:
- seconds from longlong to ulonglong
- microseconds from long to ulong
in:
- parameters of calc_time_diff()
- parameters of calc_time_from_sec()
- Members of Sec6_add

This will help to reuse the code easier:
all other functions use ulonglong+long
for seconds/microsecond, e.g.:

- number_to_time()
- number_to_datetime()
- number_to_datetime_with_warn()
- Field_temporal_with_date::store_decimal()
- my_decimal2seconds()
- Item::get_seconds()
parent 9da706fa
...@@ -758,8 +758,8 @@ bool get_next_time(const Time_zone *time_zone, my_time_t *next, ...@@ -758,8 +758,8 @@ bool get_next_time(const Time_zone *time_zone, my_time_t *next,
if (seconds) if (seconds)
{ {
longlong seconds_diff; ulonglong seconds_diff;
long microsec_diff; ulong microsec_diff;
bool negative= calc_time_diff(&local_now, &local_start, 1, bool negative= calc_time_diff(&local_now, &local_start, 1,
&seconds_diff, &microsec_diff); &seconds_diff, &microsec_diff);
if (!negative) if (!negative)
......
...@@ -2760,8 +2760,8 @@ longlong Item_func_microsecond::val_int() ...@@ -2760,8 +2760,8 @@ longlong Item_func_microsecond::val_int()
longlong Item_func_timestamp_diff::val_int() longlong Item_func_timestamp_diff::val_int()
{ {
MYSQL_TIME ltime1, ltime2; MYSQL_TIME ltime1, ltime2;
longlong seconds; ulonglong seconds;
long microseconds; ulong microseconds;
long months= 0; long months= 0;
int neg= 1; int neg= 1;
THD *thd= current_thd; THD *thd= current_thd;
...@@ -2840,21 +2840,21 @@ longlong Item_func_timestamp_diff::val_int() ...@@ -2840,21 +2840,21 @@ longlong Item_func_timestamp_diff::val_int()
case INTERVAL_MONTH: case INTERVAL_MONTH:
return months*neg; return months*neg;
case INTERVAL_WEEK: case INTERVAL_WEEK:
return seconds / SECONDS_IN_24H / 7L * neg; return ((longlong) (seconds / SECONDS_IN_24H / 7L)) * neg;
case INTERVAL_DAY: case INTERVAL_DAY:
return seconds / SECONDS_IN_24H * neg; return ((longlong) (seconds / SECONDS_IN_24H)) * neg;
case INTERVAL_HOUR: case INTERVAL_HOUR:
return seconds/3600L*neg; return ((longlong) (seconds / 3600L)) * neg;
case INTERVAL_MINUTE: case INTERVAL_MINUTE:
return seconds/60L*neg; return ((longlong) (seconds / 60L)) * neg;
case INTERVAL_SECOND: case INTERVAL_SECOND:
return seconds*neg; return ((longlong) seconds) * neg;
case INTERVAL_MICROSECOND: case INTERVAL_MICROSECOND:
/* /*
In MySQL difference between any two valid datetime values In MySQL difference between any two valid datetime values
in microseconds fits into longlong. in microseconds fits into longlong.
*/ */
return (seconds*1000000L+microseconds)*neg; return ((longlong) ((ulonglong) seconds * 1000000L + microseconds)) * neg;
default: default:
break; break;
} }
......
...@@ -866,10 +866,10 @@ bool Log_to_csv_event_handler:: ...@@ -866,10 +866,10 @@ bool Log_to_csv_event_handler::
Open_tables_backup open_tables_backup; Open_tables_backup open_tables_backup;
CHARSET_INFO *client_cs= thd->variables.character_set_client; CHARSET_INFO *client_cs= thd->variables.character_set_client;
bool save_time_zone_used; bool save_time_zone_used;
long query_time= (long) MY_MIN(query_utime/1000000, TIME_MAX_VALUE_SECONDS); ulong query_time= (ulong) MY_MIN(query_utime/1000000, TIME_MAX_VALUE_SECONDS);
long lock_time= (long) MY_MIN(lock_utime/1000000, TIME_MAX_VALUE_SECONDS); ulong lock_time= (ulong) MY_MIN(lock_utime/1000000, TIME_MAX_VALUE_SECONDS);
long query_time_micro= (long) (query_utime % 1000000); ulong query_time_micro= (ulong) (query_utime % 1000000);
long lock_time_micro= (long) (lock_utime % 1000000); ulong lock_time_micro= (ulong) (lock_utime % 1000000);
DBUG_ENTER("Log_to_csv_event_handler::log_slow"); DBUG_ENTER("Log_to_csv_event_handler::log_slow");
......
...@@ -549,7 +549,7 @@ void localtime_to_TIME(MYSQL_TIME *to, struct tm *from) ...@@ -549,7 +549,7 @@ void localtime_to_TIME(MYSQL_TIME *to, struct tm *from)
} }
void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds) void calc_time_from_sec(MYSQL_TIME *to, ulong seconds, ulong microseconds)
{ {
long t_seconds; long t_seconds;
// to->neg is not cleared, it may already be set to a useful value // to->neg is not cleared, it may already be set to a useful value
...@@ -1130,7 +1130,7 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, ...@@ -1130,7 +1130,7 @@ bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
bool bool
calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
int l_sign, longlong *seconds_out, long *microseconds_out) int l_sign, ulonglong *seconds_out, ulong *microseconds_out)
{ {
long days; long days;
bool neg; bool neg;
...@@ -1172,8 +1172,8 @@ calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, ...@@ -1172,8 +1172,8 @@ calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
microseconds= -microseconds; microseconds= -microseconds;
neg= 1; neg= 1;
} }
*seconds_out= microseconds/1000000L; *seconds_out= (ulonglong) microseconds/1000000L;
*microseconds_out= (long) (microseconds%1000000L); *microseconds_out= (ulong) (microseconds%1000000L);
return neg; return neg;
} }
...@@ -1181,8 +1181,8 @@ calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, ...@@ -1181,8 +1181,8 @@ calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
int l_sign, MYSQL_TIME *l_time3, ulonglong fuzzydate) int l_sign, MYSQL_TIME *l_time3, ulonglong fuzzydate)
{ {
longlong seconds; ulonglong seconds;
long microseconds; ulong microseconds;
bzero((char *) l_time3, sizeof(*l_time3)); bzero((char *) l_time3, sizeof(*l_time3));
l_time3->neg= calc_time_diff(l_time1, l_time2, l_sign, l_time3->neg= calc_time_diff(l_time1, l_time2, l_sign,
&seconds, &microseconds); &seconds, &microseconds);
...@@ -1201,7 +1201,7 @@ bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, ...@@ -1201,7 +1201,7 @@ bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
("invalid" means > TIME_MAX_SECOND) ("invalid" means > TIME_MAX_SECOND)
*/ */
set_if_smaller(seconds, INT_MAX32); set_if_smaller(seconds, INT_MAX32);
calc_time_from_sec(l_time3, (long) seconds, microseconds); calc_time_from_sec(l_time3, (ulong) seconds, microseconds);
return ((fuzzydate & TIME_NO_ZERO_DATE) && (seconds == 0) && return ((fuzzydate & TIME_NO_ZERO_DATE) && (seconds == 0) &&
(microseconds == 0)); (microseconds == 0));
} }
...@@ -1335,8 +1335,8 @@ mix_date_and_time_complex(MYSQL_TIME *ldate, const MYSQL_TIME *ltime) ...@@ -1335,8 +1335,8 @@ mix_date_and_time_complex(MYSQL_TIME *ldate, const MYSQL_TIME *ltime)
{ {
DBUG_ASSERT(ldate->time_type == MYSQL_TIMESTAMP_DATE || DBUG_ASSERT(ldate->time_type == MYSQL_TIMESTAMP_DATE ||
ldate->time_type == MYSQL_TIMESTAMP_DATETIME); ldate->time_type == MYSQL_TIMESTAMP_DATETIME);
longlong seconds; ulonglong seconds;
long days, useconds; ulong days, useconds;
int sign= ltime->neg ? 1 : -1; int sign= ltime->neg ? 1 : -1;
ldate->neg= calc_time_diff(ldate, ltime, sign, &seconds, &useconds); ldate->neg= calc_time_diff(ldate, ltime, sign, &seconds, &useconds);
......
...@@ -141,7 +141,7 @@ bool my_TIME_to_str(const MYSQL_TIME *ltime, String *str, uint dec); ...@@ -141,7 +141,7 @@ bool my_TIME_to_str(const MYSQL_TIME *ltime, String *str, uint dec);
bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type, bool date_add_interval(MYSQL_TIME *ltime, interval_type int_type,
const INTERVAL &interval); const INTERVAL &interval);
bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
int l_sign, longlong *seconds_out, long *microseconds_out); int l_sign, ulonglong *seconds_out, ulong *microseconds_out);
int append_interval(String *str, interval_type int_type, int append_interval(String *str, interval_type int_type,
const INTERVAL &interval); const INTERVAL &interval);
/** /**
...@@ -171,7 +171,7 @@ bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2, ...@@ -171,7 +171,7 @@ bool calc_time_diff(const MYSQL_TIME *l_time1, const MYSQL_TIME *l_time2,
int my_time_compare(const MYSQL_TIME *a, const MYSQL_TIME *b); int my_time_compare(const MYSQL_TIME *a, const MYSQL_TIME *b);
void localtime_to_TIME(MYSQL_TIME *to, struct tm *from); void localtime_to_TIME(MYSQL_TIME *to, struct tm *from);
void calc_time_from_sec(MYSQL_TIME *to, long seconds, long microseconds); 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(MYSQL_TIME *l_time, uint week_behaviour, uint *year);
int calc_weekday(long daynr,bool sunday_first_day_of_week); int calc_weekday(long daynr,bool sunday_first_day_of_week);
......
...@@ -217,15 +217,15 @@ class VDec2_lazy ...@@ -217,15 +217,15 @@ class VDec2_lazy
*/ */
class Sec6_add class Sec6_add
{ {
longlong m_sec; // number of seconds ulonglong m_sec; // number of seconds
long m_usec; // number of microseconds ulong m_usec; // number of microseconds
bool m_neg; // false if positive, true if negative bool m_neg; // false if positive, true if negative
bool m_error; // false if the value is OK, true otherwise bool m_error; // false if the value is OK, true otherwise
void to_hh24mmssff(MYSQL_TIME *ltime, timestamp_type tstype) const void to_hh24mmssff(MYSQL_TIME *ltime, timestamp_type tstype) const
{ {
bzero(ltime, sizeof(*ltime)); bzero(ltime, sizeof(*ltime));
ltime->neg= m_neg; ltime->neg= m_neg;
calc_time_from_sec(ltime, (long) (m_sec % SECONDS_IN_24H), m_usec); calc_time_from_sec(ltime, (ulong) (m_sec % SECONDS_IN_24H), m_usec);
ltime->time_type= tstype; ltime->time_type= tstype;
} }
public: public:
......
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