summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <dlenev@mysql.com>2004-11-04 14:25:08 +0300
committerunknown <dlenev@mysql.com>2004-11-04 14:25:08 +0300
commit1e87c820d15a0cb36f8731af8449c8f14ece8826 (patch)
treeb602bdf9475ecfba62ab4e4b627761bb164652ee /sql
parent7651674f0376f1a5db51826cae478b17bdd48465 (diff)
parentd259ba4006a683e953486191d2851ee6c63f66b7 (diff)
downloadmariadb-git-1e87c820d15a0cb36f8731af8449c8f14ece8826.tar.gz
Merge bk-internal.mysql.com:/home/bk/mysql-4.0
into mysql.com:/home/dlenev/src/mysql-4.0-bg6387
Diffstat (limited to 'sql')
-rw-r--r--sql/time.cc23
1 files changed, 18 insertions, 5 deletions
diff --git a/sql/time.cc b/sql/time.cc
index 0363d764100..38670db054f 100644
--- a/sql/time.cc
+++ b/sql/time.cc
@@ -81,6 +81,10 @@ long my_gmt_sec(TIME *t, long *my_timezone)
I couldn't come up with a better way to get a repeatable result :(
We can't use mktime() as it's buggy on many platforms and not thread safe.
+
+ Note: this code assumes that our time_t estimation is not too far away
+ from real value (we assume that localtime_r(tmp) will return something
+ within 24 hrs from t) which is probably true for all current time zones.
*/
tmp=(time_t) (((calc_daynr((uint) t->year,(uint) t->month,(uint) t->day) -
(long) days_at_timestart)*86400L + (long) t->hour*3600L +
@@ -93,7 +97,8 @@ long my_gmt_sec(TIME *t, long *my_timezone)
for (loop=0;
loop < 2 &&
(t->hour != (uint) l_time->tm_hour ||
- t->minute != (uint) l_time->tm_min);
+ t->minute != (uint) l_time->tm_min ||
+ t->second != (uint) l_time->tm_sec);
loop++)
{ /* One check should be enough ? */
/* Get difference in days */
@@ -103,15 +108,22 @@ long my_gmt_sec(TIME *t, long *my_timezone)
else if (days > 1)
days= -1;
diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour)) +
- (long) (60*((int) t->minute - (int) l_time->tm_min)));
+ (long) (60*((int) t->minute - (int) l_time->tm_min)) +
+ (long) ((int) t->second - (int) l_time->tm_sec));
current_timezone+= diff+3600; // Compensate for -3600 above
tmp+= (time_t) diff;
localtime_r(&tmp,&tm_tmp);
l_time=&tm_tmp;
}
/*
- Fix that if we are in the not existing daylight saving time hour
- we move the start of the next real hour
+ Fix that if we are in the non existing daylight saving time hour
+ we move the start of the next real hour.
+
+ This code doesn't handle such exotical thing as time-gaps whose length
+ is more than one hour or non-integer (latter can theoretically happen
+ if one of seconds will be removed due leap correction, or because of
+ general time correction like it happened for Africa/Monrovia time zone
+ in year 1972).
*/
if (loop == 2 && t->hour != (uint) l_time->tm_hour)
{
@@ -121,7 +133,8 @@ long my_gmt_sec(TIME *t, long *my_timezone)
else if (days > 1)
days= -1;
diff=(3600L*(long) (days*24+((int) t->hour - (int) l_time->tm_hour))+
- (long) (60*((int) t->minute - (int) l_time->tm_min)));
+ (long) (60*((int) t->minute - (int) l_time->tm_min)) +
+ (long) ((int) t->second - (int) l_time->tm_sec));
if (diff == 3600)
tmp+=3600 - t->minute*60 - t->second; // Move to next hour
else if (diff == -3600)