Date's time zone is incorrect when machine time zone is set to Caracas (Venezuela) on OS X. bug 411726. r=mrbkap
authorBrian Crowder <crowder@fiverocks.com>
Tue, 14 Apr 2009 15:26:09 -0400
changeset 24625 eb3206d9774e63b81d33701407c540ba7ecefc95
parent 24624 bf0aa09ab67c6d03cba470559880269abce22ad2
child 24626 735cdd9a31cf785df239a86937d0627b860ff9e5
push id1177
push userrsayre@mozilla.com
push dateTue, 14 Apr 2009 21:32:01 +0000
reviewersmrbkap
bugs411726
milestone1.9.1b4pre
Date's time zone is incorrect when machine time zone is set to Caracas (Venezuela) on OS X. bug 411726. r=mrbkap
configure.in
js/src/configure.in
js/src/jsdate.cpp
js/src/prmjtime.cpp
--- a/configure.in
+++ b/configure.in
@@ -3344,21 +3344,17 @@ fi
 
 
 dnl Checks for library functions.
 dnl ========================================================
 AC_PROG_GCC_TRADITIONAL
 AC_FUNC_MEMCMP
 AC_CHECK_FUNCS(random strerror lchown fchmod snprintf statvfs memmove rint stat64 lstat64 truncate64 statvfs64)
 AC_CHECK_FUNCS(flockfile getpagesize)
-
-dnl localtime_r and strtok_r are only present on MacOS version 10.2 and higher
-if test -z "$MACOS_DEPLOYMENT_TARGET" || test "$MACOS_DEPLOYMENT_TARGET" -ge "100200"; then
-  AC_CHECK_FUNCS(localtime_r strtok_r)
-fi
+AC_CHECK_FUNCS(localtime_r strtok_r)
 
 dnl check for wcrtomb/mbrtowc
 dnl =======================================================================
 if test -z "$MACOS_DEPLOYMENT_TARGET" || test "$MACOS_DEPLOYMENT_TARGET" -ge "100300"; then
 AC_LANG_SAVE
 AC_LANG_CPLUSPLUS
 AC_CACHE_CHECK(for wcrtomb,
     ac_cv_have_wcrtomb,
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -3175,21 +3175,17 @@ fi
 
 
 dnl Checks for library functions.
 dnl ========================================================
 AC_PROG_GCC_TRADITIONAL
 AC_FUNC_MEMCMP
 AC_CHECK_FUNCS(random strerror lchown fchmod snprintf statvfs memmove rint stat64 lstat64 truncate64 statvfs64)
 AC_CHECK_FUNCS(flockfile getpagesize)
-
-dnl localtime_r and strtok_r are only present on MacOS version 10.2 and higher
-if test -z "$MACOS_DEPLOYMENT_TARGET" || test "$MACOS_DEPLOYMENT_TARGET" -ge "100200"; then
-  AC_CHECK_FUNCS(localtime_r strtok_r)
-fi
+AC_CHECK_FUNCS(localtime_r strtok_r)
 
 dnl check for wcrtomb/mbrtowc
 dnl =======================================================================
 if test -z "$MACOS_DEPLOYMENT_TARGET" || test "$MACOS_DEPLOYMENT_TARGET" -ge "100300"; then
 AC_LANG_SAVE
 AC_LANG_CPLUSPLUS
 AC_CACHE_CHECK(for wcrtomb,
     ac_cv_have_wcrtomb,
@@ -4732,16 +4728,30 @@ AC_CACHE_CHECK(for correct overload reso
                     ],
                     ac_nscap_nonconst_opeq_bug="no",
                     ac_nscap_nonconst_opeq_bug="yes")])
 CXXFLAGS="$_SAVE_CXXFLAGS"
 
 if test "$ac_nscap_nonconst_opeq_bug" = "yes" ; then
     AC_DEFINE(NSCAP_DONT_PROVIDE_NONCONST_OPEQ)
 fi
+
+dnl ========================================================
+dnl Check for tm_zone, tm_gmtoff in struct tm
+dnl ========================================================
+AC_CACHE_CHECK(for tm_zone tm_gmtoff in struct tm,
+    ac_cv_struct_tm_zone_tm_gmtoff,
+    [AC_TRY_COMPILE([#include <time.h>],
+                    [struct tm tm; tm.tm_zone = 0; tm.tm_gmtoff = 1;],
+                    [ac_cv_struct_tm_zone_tm_gmtoff="yes"],
+                    [ac_cv_struct_tm_zone_tm_gmtoff="no"])])
+if test "$ac_cv_struct_tm_zone_tm_gmtoff" = "yes" ; then
+    AC_DEFINE(HAVE_TM_ZONE_TM_GMTOFF)
+fi
+
 fi # SKIP_COMPILER_CHECKS
 
 dnl ========================================================
 dnl C++ rtti
 dnl Should be smarter and check that the compiler does indeed have rtti
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(cpp-rtti,
 [  --enable-cpp-rtti       Enable C++ RTTI ],
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -411,18 +411,23 @@ DaylightSavingTA(jsdouble t)
 
     offset = PRMJ_DSTOffset(PR_t);
 
     JSLL_DIV(offset, offset, ms2us);
     JSLL_L2D(result, offset);
     return result;
 }
 
-
-#define AdjustTime(t)   fmod(LocalTZA + DaylightSavingTA(t), msPerDay)
+static jsdouble
+AdjustTime(jsdouble date)
+{
+    jsdouble t = DaylightSavingTA(date) + LocalTZA;
+    t = (LocalTZA >= 0) ? fmod(t, msPerDay) : -fmod(msPerDay - t, msPerDay);
+    return t;
+}
 
 #define LocalTime(t)    ((t) + AdjustTime(t))
 
 static jsdouble
 UTC(jsdouble t)
 {
     return t - AdjustTime(t - LocalTZA);
 }
--- a/js/src/prmjtime.cpp
+++ b/js/src/prmjtime.cpp
@@ -536,21 +536,20 @@ PRMJ_DSTOffset(JSInt64 local_time)
         return 0;
     }
     tm = *ptm;
 #else
     localtime_r(&local,&tm); /* get dst information */
 #endif
 
     diff = ((tm.tm_hour - prtm.tm_hour) * PRMJ_HOUR_SECONDS) +
-	((tm.tm_min - prtm.tm_min) * 60);
+           ((tm.tm_min - prtm.tm_min) * 60);
 
-    if(diff < 0){
-	diff += PRMJ_DAY_SECONDS;
-    }
+    if (diff < 0)
+        diff += PRMJ_DAY_SECONDS;
 
     JSLL_UI2L(local_time,diff);
 
     JSLL_MUL(local_time,local_time,us2s);
 
     return(local_time);
 }
 
@@ -596,16 +595,26 @@ PRMJ_FormatTime(char *buf, int buflen, c
 
     a.tm_sec = prtm->tm_sec;
     a.tm_min = prtm->tm_min;
     a.tm_hour = prtm->tm_hour;
     a.tm_mday = prtm->tm_mday;
     a.tm_mon = prtm->tm_mon;
     a.tm_wday = prtm->tm_wday;
 
+#if defined(HAVE_LOCALTIME_R) && defined(HAVE_TM_ZONE_TM_GMTOFF)
+    {
+        struct tm td;
+        time_t bogus = 0;
+        localtime_r(&bogus, &td);
+        a.tm_gmtoff = td.tm_gmtoff;
+        a.tm_zone = td.tm_zone;
+    }
+#endif
+
     /*
      * Years before 1900 and after 9999 cause strftime() to abort on Windows.
      * To avoid that we replace it with FAKE_YEAR_BASE + year % 100 and then
      * replace matching substrings in the strftime() result with the real year.
      * Note that FAKE_YEAR_BASE should be a multiple of 100 to make 2-digit
      * year formats (%y) work correctly (since we won't find the fake year
      * in that case).
      * e.g. new Date(1873, 0).toLocaleFormat('%Y %y') => "1873 73"