from_unixtime incorrectly applies localtime correction

from_unixtime incorrectly applies localtime correction

am 04.03.2003 19:39:12 von Jim Heedles

>Description:
On a windows or linux system where the time is set to local time, the
function from_unixtime incorrectly applies the offset from UTC to Local to
the result. For example when set to EST, "select from_unixtime(0);"
returns "1969-12-31 19:00:00". In fact, section 6.3.4 of the MySql manual
was generated using a system set to a local one hour ahead of UTC.
This can be demonstrated on multiple versions of 3.23.xx and 4.0.10-gamma.
>How-To-Repeat:
1) set the computer clock to localtime on a window system or set the TZ
variable to display localtime.
2) issue "select from_unixtime(0);" using any database
>Fix:
None known. Floating point values representing time to fractions of a
second cannot be properly interpreted across replicated servers in multiple
timezones.

>Submitter-Id:
>Originator: Jim Heedles
>Organization:
Spaceflight Systems Corporation
>MySQL support: none
>Synopsis: from_unixtime incorrectly applies localtime correction
>Severity: serious
>Priority: low
>Category: mysql
>Class: sw-bug
>Release: mysql-3.23.55 (Official MySQL RPM)
>Server: /usr/bin/mysqladmin Ver 8.23 Distrib 3.23.55, for pc-linux on
i686
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Server version 3.23.55-Max
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 14 min 14 sec

Threads: 1 Questions: 6 Slow queries: 0 Opens: 6 Flush tables: 1 Open
tables: 0 Queries per second avg: 0.007
>Environment:

System: Linux SSC-RSG1.ssc-nh.com 2.4.18-4 #1 Thu May 2 18:47:38 EDT 2002
i686 unknown
Architecture: i686

Some paths: /usr/bin/perl /usr/bin/make /usr/bin/gmake /usr/bin/gcc
/usr/bin/cc
GCC: Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)
Compilation info: CC='gcc' CFLAGS='-O6 -fno-omit-frame-pointer -mpentium'
CXX='gcc' CXXFLAGS='-O6 -fno-omit-frame-pointer
-felide-constructors -fno-exceptions -fno-rtti -mpentium'
LDFLAGS=''
LIBC:
lrwxrwxrwx 1 root root 13 Sep 16 07:17 /lib/libc.so.6 ->
libc-2.2.5.so
-rwxr-xr-x 1 root root 1260480 Apr 15 2002 /lib/libc-2.2.5.so
-rw-r--r-- 1 root root 2310808 Apr 15 2002 /usr/lib/libc.a
-rw-r--r-- 1 root root 178 Apr 15 2002 /usr/lib/libc.so
Configure command: ./configure '--disable-shared'
'--with-mysqld-ldflags=-all-static' '--with-client-ldflags=-all-static'
'--without-berkeley-db' '--without-innodb' '--enable-assembler'
'--enable-local-infile' '--with-mysqld-user=mysql'
'--with-unix-socket-path=/var/lib/mysql/mysql.sock' '--prefix=/'
'--with-extra-charsets=complex' '--exec-prefix=/usr'
'--libexecdir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share'
'--localstatedir=/var/lib/mysql' '--infodir=/usr/share/info'
'--includedir=/usr/include' '--mandir=/usr/share/man'
'--with-comment=Official MySQL RPM' 'CC=gcc' 'CFLAGS=-O6
-fno-omit-frame-pointer -mpentium' 'CXXFLAGS=-O6 -fno-omit-frame-pointer
-felide-constructors -fno-exceptions -fno-rtti -mpentium'
'CXX=gcc'



------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13897@lists.mysql.com
To unsubscribe, e-mail

Re: from_unixtime incorrectly applies localtime correction

am 05.03.2003 10:38:53 von Alexander Keremidarski

Jim,

Jim Heedles wrote:
>>Description:
>
> On a windows or linux system where the time is set to local time, the
> function from_unixtime incorrectly applies the offset from UTC to Local to
> the result. For example when set to EST, "select from_unixtime(0);"
> returns "1969-12-31 19:00:00". In fact, section 6.3.4 of the MySql manual
> was generated using a system set to a local one hour ahead of UTC.
> This can be demonstrated on multiple versions of 3.23.xx and 4.0.10-gamma.

I don't understand well what do you mean by the above especially sentence saying:
"section 6.3.4 of the MySql manual was generated using a system set to a local one
hour ahead of UTC"


FROM_UNIXTRIME() always uses system TimeZone.

I am in EET which is GMT+2 so for me:

mysql> select from_unixtime(0);
+---------------------+
| from_unixtime(0) |
+---------------------+
| 1970-01-01 02:00:00 |
+---------------------+


This is not a bug - this is how UNIX Timestamp is defined - "Number of seconds
since 1970-01-01 00:00:00 GMT"
As I'm 2 hours ahead of GMT obviously for me 00:00:00 GMT = 02:00:00 EET

--
MySQL Conference and Expo 2003 http://www.mysql.com/events/uc2003/index.html
For technical support contracts, visit https://order.mysql.com/?ref=msal
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mr. Alexander Keremidarski
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer
/_/ /_/\_, /___/\___\_\___/ Sofia, Bulgaria
<___/ www.mysql.com




------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13904@lists.mysql.com
To unsubscribe, e-mail

Re: from_unixtime incorrectly applies localtime correction

am 05.03.2003 15:02:22 von indrek siitan

Hi,

> On a windows or linux system where the time is set to local
> time, the function from_unixtime incorrectly applies the offset
> from UTC to Local to the result. For example when set to
> EST, "select from_unixtime(0);" returns "1969-12-31 19:00:00".
> In fact, section 6.3.4 of the MySql manual was generated using
> a system set to a local one hour ahead of UTC.
> This can be demonstrated on multiple versions of 3.23.xx and
> 4.0.10-gamma.

> >How-To-Repeat:
> 1) set the computer clock to localtime on a window system or set
> the TZ variable to display localtime.
> 2) issue "select from_unixtime(0);" using any database


Yes, MySQL applies the timezone information to all dates, so since EST is
GMT-5, "1969-12-31 19:00:00" is a completely expected result. If you need
unified results across multiple machines in different timezones, the best
way is to set the TZ variable to "UTC" and apply the timezone information on
the application level.


Rgds,
Indrek

--
MySQL Users Conference and Expo: http://www.mysql.com/events/uc2003/
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Indrek Siitan
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, The Web Guru
/_/ /_/\_, /___/\___\_\___/ UuemƵisa, Haapsalu, Estonia
<___/ www.mysql.com





------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail bugs-thread13907@lists.mysql.com
To unsubscribe, e-mail