summaryrefslogtreecommitdiffstats
path: root/source/l/mozjs60/patches/Always-use-the-equivalent-year-to-determine-the-time-zone.patch
blob: 81474a42b0d02987b1649c6775f3418c717d3294 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
From: =?utf-8?q?Andr=C3=A9_Bargull?= <andrebargull@googlemail.com>
Date: Wed, 8 Nov 2017 03:23:41 -0800
Subject: Always use the equivalent year to determine the time zone offset and
 name

Reviewed-by: Jeff Walden
Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1415202
Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1479687
Origin: upstream
Applied-upstream: 62, commit:https://hg.mozilla.org/mozilla-central/rev/ce9f1466ec78
---
 js/src/jsdate.cpp  | 11 +++++++----
 js/src/vm/Time.cpp | 14 ++++----------
 js/src/vm/Time.h   |  2 +-
 3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp
index 07af3d18c865..ff8fd6c3763c 100644
--- a/js/src/jsdate.cpp
+++ b/js/src/jsdate.cpp
@@ -2353,12 +2353,15 @@ static PRMJTime ToPRMJTime(double localTime, double utcTime) {
 static size_t FormatTime(char* buf, int buflen, const char* fmt, double utcTime,
                          double localTime) {
   PRMJTime prtm = ToPRMJTime(localTime, utcTime);
-  int eqivalentYear = IsRepresentableAsTime32(utcTime)
-                          ? prtm.tm_year
-                          : EquivalentYearForDST(prtm.tm_year);
+  // If an equivalent year was used to compute the date/time components, use
+  // the same equivalent year to determine the time zone name and offset in
+  // PRMJ_FormatTime(...).
+  int timeZoneYear = IsRepresentableAsTime32(utcTime)
+                     ? prtm.tm_year
+                     : EquivalentYearForDST(prtm.tm_year);
   int offsetInSeconds = (int)floor((localTime - utcTime) / msPerSecond);

-  return PRMJ_FormatTime(buf, buflen, fmt, &prtm, eqivalentYear,
+  return PRMJ_FormatTime(buf, buflen, fmt, &prtm, timeZoneYear,
                          offsetInSeconds);
 }

diff --git a/js/src/vm/Time.cpp b/js/src/vm/Time.cpp
index f59977f0d0e9..5ee4794b3e83 100644
--- a/js/src/vm/Time.cpp
+++ b/js/src/vm/Time.cpp
@@ -247,7 +247,7 @@ static void PRMJ_InvalidParameterHandler(const wchar_t* expression,

 /* Format a time value into a buffer. Same semantics as strftime() */
 size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
-                       const PRMJTime* prtm, int equivalentYear,
+                       const PRMJTime* prtm, int timeZoneYear,
                        int offsetInSeconds) {
   size_t result = 0;
 #if defined(XP_UNIX) || defined(XP_WIN)
@@ -280,7 +280,8 @@ size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
      * Fill out |td| to the time represented by |prtm|, leaving the
      * timezone fields zeroed out. localtime_r will then fill in the
      * timezone fields for that local time according to the system's
-     * timezone parameters.
+     * timezone parameters. Use |timeZoneYear| for the year to ensure the
+     * time zone name matches the time zone offset used by the caller.
      */
     struct tm td;
     memset(&td, 0, sizeof(td));
@@ -290,19 +291,12 @@ size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
     td.tm_mday = prtm->tm_mday;
     td.tm_mon = prtm->tm_mon;
     td.tm_wday = prtm->tm_wday;
-    td.tm_year = prtm->tm_year - 1900;
+    td.tm_year = timeZoneYear - 1900;
     td.tm_yday = prtm->tm_yday;
     td.tm_isdst = prtm->tm_isdst;

     time_t t = mktime(&td);

-    // If |prtm| cannot be represented in |time_t| the year is probably
-    // out of range, try again with the DST equivalent year.
-    if (t == static_cast<time_t>(-1)) {
-      td.tm_year = equivalentYear - 1900;
-      t = mktime(&td);
-    }
-
     // If either mktime or localtime_r failed, fill in the fallback time
     // zone offset |offsetInSeconds| and set the time zone identifier to
     // the empty string.
diff --git a/js/src/vm/Time.h b/js/src/vm/Time.h
index 3a51d869c922..37b7faeec028 100644
--- a/js/src/vm/Time.h
+++ b/js/src/vm/Time.h
@@ -49,7 +49,7 @@ inline void PRMJ_NowShutdown() {}

 /* Format a time value into a buffer. Same semantics as strftime() */
 extern size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
-                              const PRMJTime* tm, int equivalentYear,
+                              const PRMJTime* tm, int timeZoneYear,
                               int offsetInSeconds);

 /**
--
2.21.0