summaryrefslogtreecommitdiff
path: root/sql/sql_time.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_time.cc')
-rw-r--r--sql/sql_time.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/sql/sql_time.cc b/sql/sql_time.cc
index 199ce19450e..ccba3d16575 100644
--- a/sql/sql_time.cc
+++ b/sql/sql_time.cc
@@ -1100,6 +1100,35 @@ 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)
+{
+ longlong seconds;
+ long microseconds;
+ bzero((char *) l_time3, sizeof(*l_time3));
+ l_time3->neg= calc_time_diff(l_time1, l_time2, l_sign,
+ &seconds, &microseconds);
+ /*
+ For MYSQL_TIMESTAMP_TIME only:
+ If first argument was negative and diff between arguments
+ is non-zero we need to swap sign to get proper result.
+ */
+ if (l_time1->neg && (seconds || microseconds))
+ l_time3->neg= 1 - l_time3->neg; // Swap sign of result
+
+ /*
+ seconds is longlong, when casted to long it may become a small number
+ even if the original seconds value was too large and invalid.
+ as a workaround we limit seconds by a large invalid long number
+ ("invalid" means > TIME_MAX_SECOND)
+ */
+ set_if_smaller(seconds, INT_MAX32);
+ calc_time_from_sec(l_time3, (long) seconds, microseconds);
+ return ((fuzzydate & TIME_NO_ZERO_DATE) && (seconds == 0) &&
+ (microseconds == 0));
+}
+
+
/*
Compares 2 MYSQL_TIME structures
@@ -1341,3 +1370,23 @@ time_to_datetime_with_warn(THD *thd,
}
return false;
}
+
+
+bool datetime_to_time_with_warn(THD *thd, const MYSQL_TIME *dt,
+ MYSQL_TIME *tm, uint dec)
+{
+ if (thd->variables.old_behavior & OLD_MODE_ZERO_DATE_TIME_CAST)
+ {
+ *tm= *dt;
+ datetime_to_time(tm);
+ return false;
+ }
+ else /* new mode */
+ {
+ MYSQL_TIME current_date;
+ set_current_date(thd, &current_date);
+ calc_time_diff(dt, &current_date, 1, tm, 0);
+ }
+ int warnings= 0;
+ return check_time_range(tm, dec, &warnings);
+}