[erlang-bugs] erlang:localtime_to_universaltime return wrong value when pass "true" to the second parameter.

Raimo Niskanen raimo+erlang-bugs@REDACTED
Wed May 14 10:24:07 CEST 2008


Thank you for reporting this bug.

It seemd Erlang should check the return values of
OS calls mktime and gmtime better. Unfortunately the
gmtime function on e.g OpenBSD is not documented
to return NULL on failure. But in your case it is
mktime that returns -1 and Erlang does not notice that
but instead uses the value which results in
the funny time {1969,12,31},{23,59,59},
one second before the Unix Epoch start.

Asia/Saigon does not have any daylight saving time defined.
erlang:localtim_to_universaltime(DateTime, true) should
exit with badarg.

Using perl:
$ TZ='Asia/Saigon' perl -we 'use strict; use POSIX; tzset; my $t = mktime(1, 1, 1, 5, 4, 108, 0, 0, 1); if (defined $t) {my @g = gmtime($t); print "@g\n"} else {print "undef\n"};'
undef

$ TZ='Asia/Saigon' perl -we 'use strict; use POSIX; tzset; my @g = gmtime(-1); print "@g\n"'
59 59 23 31 11 69 3 364 0 # {{1969,12,31},{23,59,59}}

$ TZ='Asia/Saigon' perl -we 'use strict; use POSIX; tzset; my $t = mktime(1, 1, 1, 5, 4, 108, 0, 0, 0); if (defined $t) {my @g = gmtime($t); print "@g\n"} else {print "undef\n"};'
1 1 18 5 4 108 6 123 0 # {{2008,5,5},{18,1,1}}



On Tue, May 13, 2008 at 11:07:23PM +0700, tien lex wrote:
> Hi,
> Here is my environment:
> ti@~: uname -a
> FreeBSD  7.0-RELEASE FreeBSD 7.0-RELEASE #0: Tue Apr  8 07:57:43 ICT
> 2008     ti@REDACTED:/usr/obj/usr/src/sys/EXTCOMPAT  i386
> 
> 1> os:getenv("TZ").
> "Asia/Saigon"
> 7> DateTime = {{2008,5,5},{1,1,1}}.
> {{2008,5,5},{1,1,1}}
> 9> calendar:local_time_to_universal_time_dst(DateTime).
> ** exception error: bad argument
>      in function  erlang:universaltime_to_localtime/1
>         called as
> erlang:universaltime_to_localtime({{1969,12,31},{23,59,59}})
>      in call from calendar:local_time_to_universal_time_dst/1
> 
> 10> erlang:localtime_to_universaltime(DateTime, true).
> {{1969,12,31},{23,59,59}}
> 
> 11> erlang:localtime_to_universaltime(DateTime, false).
> {{2008,5,4},{18,1,1}}
> 
> And below is the result of zdump command on /etc/localtime file:
> ti@~: zdump -v /etc/localtime
> /etc/localtime  Fri Dec 13 20:45:52 1901 UTC = Sat Dec 14 03:52:32 1901 LMT
> isdst=0 gmtoff=25600
> /etc/localtime  Sat Dec 14 20:45:52 1901 UTC = Sun Dec 15 03:52:32 1901 LMT
> isdst=0 gmtoff=25600
> /etc/localtime  Fri Jun  8 16:53:19 1906 UTC = Fri Jun  8 23:59:59 1906 LMT
> isdst=0 gmtoff=25600
> /etc/localtime  Fri Jun  8 16:53:20 1906 UTC = Fri Jun  8 23:59:40 1906 SMT
> isdst=0 gmtoff=25580
> /etc/localtime  Fri Mar 10 16:54:39 1911 UTC = Sat Mar 11 00:00:59 1911 SMT
> isdst=0 gmtoff=25580
> /etc/localtime  Fri Mar 10 16:54:40 1911 UTC = Fri Mar 10 23:54:40 1911 ICT
> isdst=0 gmtoff=25200
> /etc/localtime  Tue Apr 30 16:59:59 1912 UTC = Tue Apr 30 23:59:59 1912 ICT
> isdst=0 gmtoff=25200
> /etc/localtime  Tue Apr 30 17:00:00 1912 UTC = Wed May  1 01:00:00 1912 ICT
> isdst=0 gmtoff=28800
> /etc/localtime  Thu Apr 30 15:59:59 1931 UTC = Thu Apr 30 23:59:59 1931 ICT
> isdst=0 gmtoff=28800
> /etc/localtime  Thu Apr 30 16:00:00 1931 UTC = Thu Apr 30 23:00:00 1931 ICT
> isdst=0 gmtoff=25200
> /etc/localtime  Mon Jan 18 03:14:07 2038 UTC = Mon Jan 18 10:14:07 2038 ICT
> isdst=0 gmtoff=25200
> /etc/localtime  Tue Jan 19 03:14:07 2038 UTC = Tue Jan 19 10:14:07 2038 ICT
> isdst=0 gmtoff=25200
> ti@~:
> 
> It worked great  before i change the time zone.
> 
> Regards,
> Tien

> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-bugs

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-bugs mailing list