$OpenBSD: patch-erts_emulator_beam_erl_time_sup_c,v 1.3 2012/07/18 13:44:31 jasper Exp $

[PATCH] Fix use of "clever" mktime.

Commit 1eef765 introduced regression (conditional _always_ evaluates
to true) in which erlang:localtime_to_universaltime/2 stopped working
on systems configured with timezone without DST (i.e. UTC) on *BSD
platforms:

1> erlang:localtime_to_universaltime({{2012,1,1},{0,0,0}}, true).
** exception error: bad argument


[PATCH] Fix support for leap seconds-aware timezones.

erlang:universaltime_to_localtime is leap seconds-aware (since 2008),
however erlang:localtime_to_universaltime is not, which gives
surprising results on systems configured with leap seconds-aware
timezones:

1> erlang:universaltime_to_localtime({{2012,1,1},{0,0,0}}).
{{2012,1,1},{0,0,0}}
2> erlang:localtime_to_universaltime({{2012,1,1},{0,0,0}}).
{{2012,1,1},{0,0,24}}

and completely breaks calendar:local_time_to_universal_time_dst:

3> calendar:local_time_to_universal_time_dst({{2011,1,1},{0,0,0}}).
[]
--- erts/emulator/beam/erl_time_sup.c.orig	Sun Apr  1 18:14:36 2012
+++ erts/emulator/beam/erl_time_sup.c	Fri Jul 13 05:52:50 2012
@@ -757,7 +757,7 @@
 	       refuses to give us a DST time, we simulate the Linux/Solaris
 	       behaviour of giving the same data as if is_dst was not set. */
 	    t.tm_isdst = 0;
-	    if (erl_mktime(&the_clock, &t)) {
+	    if (erl_mktime(&the_clock, &t) < 0) {
 		/* Failed anyway, something else is bad - will be a badarg */
 		return 0;
 	    }
@@ -766,6 +766,9 @@
 	    return 0;
 	}
     }
+
+    the_clock = time2posix(the_clock);
+
 #ifdef HAVE_GMTIME_R
     tm = gmtime_r(&the_clock, &tmbuf);
 #else
