List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:December 29 1999 5:39pm
Subject:RE: UNIX_TIMESTAMP BUG?
View as plain text  
>>>>> "Quentin" == Quentin Bennett <quentin.bennett@stripped>
> writes:

Quentin> Hmmmm,
Quentin> With the server running in TZ=GMT

Quentin> select  UNIX_TIMESTAMP('1970-01-01 00:00:00') 

Quentin> the answer is (correctly) 0.

Quentin> but running in TZ=NZ (where I am) it returns

Quentin> 43200

Quentin> (i.e. 12 hours) BUT NZ is ahead of GMT, so in NZ, the 'seconds since 1/1/70
Quentin> 00:00:00' is actually

Quentin> -43200

Quentin> (i.e. 12 hours before UNIX time starts)

Quentin> I haven't quite got is staight in my head yet, but I suspect the seconds
Quentin> calculation in my_gmt_sec.

Quentin> 5pm (NZ Time) here, so I'm off home.

Quentin> Here is the trace for the above select:

<cut>

Hi!

Here is a patch that should fix problems when the timezone >= 12 hours
from GMT.

Regards,
Monty


*** /my/monty/master/mysql-3.23.7-alpha/sql/time.cc	Wed Oct  6 20:52:35 1999
--- ./time.cc	Wed Dec 29 16:15:09 1999
***************
*** 64,70 ****
    l_time=&tm_tmp;
    for (loop=0; loop < 3 && t->hour != (uint) l_time->tm_hour ; loop++)
    {					/* One check should be enough ? */
!     diff=3600L*(long) ((((int) (t->hour - l_time->tm_hour)+36) % 24)-12);
      my_time_zone+=diff;
      tmp+=(time_t) diff;
      localtime_r(&tmp,&tm_tmp);
--- 64,74 ----
    l_time=&tm_tmp;
    for (loop=0; loop < 3 && t->hour != (uint) l_time->tm_hour ; loop++)
    {					/* One check should be enough ? */
!     /* Get difference in days */
!     int days= t->day - l_time->tm_mday;
!     if (days < -1)
!       days=1;					// Month has wrapped
!     diff=3600L*(long) (days*24+(t->hour - l_time->tm_hour));
      my_time_zone+=diff;
      tmp+=(time_t) diff;
      localtime_r(&tmp,&tm_tmp);
***************
*** 74,80 ****
       we move the start of the next real hour */
    if (loop == 3 && t->hour != (uint) l_time->tm_hour)
    {
!     diff=3600L*(long) ((((int) (t->hour - l_time->tm_hour)+36) % 24)-12);
      if (diff == 3600)
        tmp+=3600 - t->minute*60 - t->second;	// Move to next hour
      else if (diff == -3600)
--- 78,87 ----
       we move the start of the next real hour */
    if (loop == 3 && t->hour != (uint) l_time->tm_hour)
    {
!     int days= t->day - l_time->tm_mday;
!     if (days < -1)
!       days=1;					// Month has wrapped
!     diff=3600L*(long) (days*24+(t->hour - l_time->tm_hour));
      if (diff == 3600)
        tmp+=3600 - t->minute*60 - t->second;	// Move to next hour
      else if (diff == -3600)
Thread
UNIX_TIMESTAMP BUG?Quentin Bennett8 Dec
Re: UNIX_TIMESTAMP BUG?Sasha Pachev8 Dec
  • Re: UNIX_TIMESTAMP BUG?Vivek Khera8 Dec
RE: UNIX_TIMESTAMP BUG?Quentin Bennett9 Dec
RE: UNIX_TIMESTAMP BUG?Quentin Bennett15 Dec
RE: UNIX_TIMESTAMP BUG?sinisa16 Dec
RE: UNIX_TIMESTAMP BUG?Quentin Bennett16 Dec
RE: UNIX_TIMESTAMP BUG?Michael Widenius29 Dec
RE: UNIX_TIMESTAMP BUG?Quentin Bennett29 Dec