bstinson / rpms / mozjs60

Forked from rpms/mozjs60 5 years ago
Clone

Blame SOURCES/Always-use-the-equivalent-year-to-determine-the-time-zone.patch

e43f4b
From: =?utf-8?q?Andr=C3=A9_Bargull?= <andrebargull@googlemail.com>
e43f4b
Date: Wed, 8 Nov 2017 03:23:41 -0800
e43f4b
Subject: Always use the equivalent year to determine the time zone offset and
e43f4b
 name
e43f4b
e43f4b
Reviewed-by: Jeff Walden
e43f4b
Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1415202
e43f4b
Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1479687
e43f4b
Origin: upstream
e43f4b
Applied-upstream: 62, commit:https://hg.mozilla.org/mozilla-central/rev/ce9f1466ec78
e43f4b
---
e43f4b
 js/src/jsdate.cpp  | 11 +++++++----
e43f4b
 js/src/vm/Time.cpp | 14 ++++----------
e43f4b
 js/src/vm/Time.h   |  2 +-
e43f4b
 3 files changed, 12 insertions(+), 15 deletions(-)
e43f4b
e43f4b
diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp
e43f4b
index 07af3d18c865..ff8fd6c3763c 100644
e43f4b
--- a/js/src/jsdate.cpp
e43f4b
+++ b/js/src/jsdate.cpp
e43f4b
@@ -2353,12 +2353,15 @@ static PRMJTime ToPRMJTime(double localTime, double utcTime) {
e43f4b
 static size_t FormatTime(char* buf, int buflen, const char* fmt, double utcTime,
e43f4b
                          double localTime) {
e43f4b
   PRMJTime prtm = ToPRMJTime(localTime, utcTime);
e43f4b
-  int eqivalentYear = IsRepresentableAsTime32(utcTime)
e43f4b
-                          ? prtm.tm_year
e43f4b
-                          : EquivalentYearForDST(prtm.tm_year);
e43f4b
+  // If an equivalent year was used to compute the date/time components, use
e43f4b
+  // the same equivalent year to determine the time zone name and offset in
e43f4b
+  // PRMJ_FormatTime(...).
e43f4b
+  int timeZoneYear = IsRepresentableAsTime32(utcTime)
e43f4b
+                     ? prtm.tm_year
e43f4b
+                     : EquivalentYearForDST(prtm.tm_year);
e43f4b
   int offsetInSeconds = (int)floor((localTime - utcTime) / msPerSecond);
e43f4b
e43f4b
-  return PRMJ_FormatTime(buf, buflen, fmt, &prtm, eqivalentYear,
e43f4b
+  return PRMJ_FormatTime(buf, buflen, fmt, &prtm, timeZoneYear,
e43f4b
                          offsetInSeconds);
e43f4b
 }
e43f4b
e43f4b
diff --git a/js/src/vm/Time.cpp b/js/src/vm/Time.cpp
e43f4b
index f59977f0d0e9..5ee4794b3e83 100644
e43f4b
--- a/js/src/vm/Time.cpp
e43f4b
+++ b/js/src/vm/Time.cpp
e43f4b
@@ -247,7 +247,7 @@ static void PRMJ_InvalidParameterHandler(const wchar_t* expression,
e43f4b
e43f4b
 /* Format a time value into a buffer. Same semantics as strftime() */
e43f4b
 size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
e43f4b
-                       const PRMJTime* prtm, int equivalentYear,
e43f4b
+                       const PRMJTime* prtm, int timeZoneYear,
e43f4b
                        int offsetInSeconds) {
e43f4b
   size_t result = 0;
e43f4b
 #if defined(XP_UNIX) || defined(XP_WIN)
e43f4b
@@ -280,7 +280,8 @@ size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
e43f4b
      * Fill out |td| to the time represented by |prtm|, leaving the
e43f4b
      * timezone fields zeroed out. localtime_r will then fill in the
e43f4b
      * timezone fields for that local time according to the system's
e43f4b
-     * timezone parameters.
e43f4b
+     * timezone parameters. Use |timeZoneYear| for the year to ensure the
e43f4b
+     * time zone name matches the time zone offset used by the caller.
e43f4b
      */
e43f4b
     struct tm td;
e43f4b
     memset(&td, 0, sizeof(td));
e43f4b
@@ -290,19 +291,12 @@ size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
e43f4b
     td.tm_mday = prtm->tm_mday;
e43f4b
     td.tm_mon = prtm->tm_mon;
e43f4b
     td.tm_wday = prtm->tm_wday;
e43f4b
-    td.tm_year = prtm->tm_year - 1900;
e43f4b
+    td.tm_year = timeZoneYear - 1900;
e43f4b
     td.tm_yday = prtm->tm_yday;
e43f4b
     td.tm_isdst = prtm->tm_isdst;
e43f4b
e43f4b
     time_t t = mktime(&td);
e43f4b
e43f4b
-    // If |prtm| cannot be represented in |time_t| the year is probably
e43f4b
-    // out of range, try again with the DST equivalent year.
e43f4b
-    if (t == static_cast<time_t>(-1)) {
e43f4b
-      td.tm_year = equivalentYear - 1900;
e43f4b
-      t = mktime(&td);
e43f4b
-    }
e43f4b
-
e43f4b
     // If either mktime or localtime_r failed, fill in the fallback time
e43f4b
     // zone offset |offsetInSeconds| and set the time zone identifier to
e43f4b
     // the empty string.
e43f4b
diff --git a/js/src/vm/Time.h b/js/src/vm/Time.h
e43f4b
index 3a51d869c922..37b7faeec028 100644
e43f4b
--- a/js/src/vm/Time.h
e43f4b
+++ b/js/src/vm/Time.h
e43f4b
@@ -49,7 +49,7 @@ inline void PRMJ_NowShutdown() {}
e43f4b
e43f4b
 /* Format a time value into a buffer. Same semantics as strftime() */
e43f4b
 extern size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
e43f4b
-                              const PRMJTime* tm, int equivalentYear,
e43f4b
+                              const PRMJTime* tm, int timeZoneYear,
e43f4b
                               int offsetInSeconds);
e43f4b
e43f4b
 /**
e43f4b
--
e43f4b
2.21.0
e43f4b