summaryrefslogtreecommitdiff
path: root/storage/connect/value.cpp
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mnogosearch.org>2013-04-03 04:54:02 -0700
committerAlexander Barkov <bar@mnogosearch.org>2013-04-03 04:54:02 -0700
commit115a373b889e51cbb3d17e665da28f2308e1b0cc (patch)
treec00b8778330c1418e1d6675f0c8c8ee09b38fbeb /storage/connect/value.cpp
parentad9f8ddcc2a8322da0d5aca6287d0d0e5d91a8af (diff)
downloadmariadb-git-115a373b889e51cbb3d17e665da28f2308e1b0cc.tar.gz
Fixed a problem in index.test failures when run in a non-Paris time zone.
This fix also revealed wrong result recorded in fix.result. modified: mysql-test/suite/connect/r/fix.result storage/connect/value.cpp modified: mysql-test/suite/connect/r/bin.result mysql-test/suite/connect/r/fix.result mysql-test/suite/connect/t/bin.test storage/connect/value.cpp
Diffstat (limited to 'storage/connect/value.cpp')
-rw-r--r--storage/connect/value.cpp54
1 files changed, 46 insertions, 8 deletions
diff --git a/storage/connect/value.cpp b/storage/connect/value.cpp
index e21ba4fc396..c88c22dc3db 100644
--- a/storage/connect/value.cpp
+++ b/storage/connect/value.cpp
@@ -1261,8 +1261,36 @@ void DTVAL::SetTimeShift(void)
/* though the gmtime C function. The purpose of this function is to */
/* extend the range of valid dates by accepting negative time values. */
/***********************************************************************/
+#define MYSQL_SERVER 1
+#include "tztime.h"
+#include "sql_priv.h"
+#include "sql_class.h"
+#include "sql_time.h"
+
+static void TIME_to_localtime(struct tm *tm, const MYSQL_TIME *ltime)
+{
+ bzero(tm, sizeof(*tm));
+ tm->tm_year= ltime->year - 1900;
+ tm->tm_mon= ltime->month - 1;
+ tm->tm_mday= ltime->day;
+ tm->tm_hour= ltime->hour;
+ tm->tm_min= ltime->minute;
+ tm->tm_sec= ltime->second;
+}
+
+
+static struct tm *gmtime_mysql(const time_t *timep, struct tm *tm)
+{
+ MYSQL_TIME ltime;
+ current_thd->variables.time_zone->gmt_sec_to_TIME(&ltime, (my_time_t) *timep);
+ TIME_to_localtime(tm, &ltime);
+ return tm;
+}
+
+
struct tm *DTVAL::GetGmTime(void)
{
+ static struct tm tm_static; /* TODO: Move as a parameter to GetGmTime() */
struct tm *datm;
time_t t = (time_t)Tval;
@@ -1272,13 +1300,13 @@ struct tm *DTVAL::GetGmTime(void)
for (n = 0; t < 0; n += 4)
t += FOURYEARS;
- datm = gmtime(&t);
+ datm = gmtime_mysql(&t, &tm_static);
if (datm)
datm->tm_year -= n;
} else
- datm = gmtime((const time_t *)&t);
+ datm = gmtime_mysql(&t, &tm_static);
return datm;
} // end of GetGmTime
@@ -1288,10 +1316,21 @@ struct tm *DTVAL::GetGmTime(void)
/* mktime C function. The purpose of this function is to extend the */
/* range of valid dates by accepting to set negative time values. */
/***********************************************************************/
+
+static time_t mktime_mysql(struct tm *ptm)
+{
+ MYSQL_TIME ltime;
+ localtime_to_TIME(&ltime, ptm);
+ ltime.time_type= MYSQL_TIMESTAMP_DATETIME;
+ uint error_code;
+ time_t t= TIME_to_timestamp(current_thd, &ltime, &error_code);
+ return error_code ? (time_t) -1 : t;
+}
+
bool DTVAL::MakeTime(struct tm *ptm)
{
int n, y = ptm->tm_year;
- time_t t = mktime(ptm);
+ time_t t = mktime_mysql(ptm);
if (trace)
htrc("MakeTime from (%d,%d,%d,%d,%d,%d)\n",
@@ -1304,18 +1343,17 @@ bool DTVAL::MakeTime(struct tm *ptm)
for (n = 0; t == -1 && n < 20; n++) {
ptm->tm_year += 4;
- t = mktime(ptm);
+ t = mktime_mysql(ptm);
} // endfor t
if (t == -1)
return true;
- if ((t -= (n * FOURYEARS + Shift)) > 2000000000)
+ if ((t -= (n * FOURYEARS)) > 2000000000)
return true;
- Tval = (int)t;
- } else
- Tval = (int)t - Shift;
+ }
+ Tval= (int) t;
if (trace)
htrc("MakeTime Ival=%d\n", Tval);