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

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