2 # User André Bargull <andre.bargull@gmail.com>
3 # Date 1510140221 28800
4 # Wed Nov 08 03:23:41 2017 -0800
5 # Node ID 8bf5e7460a7c5ba3430b501d1659c469a862a929
6 # Parent 60fd4a5b01ec70ded9ddfd560fd5be191b1c74b9
7 Bug 1415202: Always use the equivalent year to determine the time zone offset and name. r=Waldo
9 diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp
10 --- a/js/src/jsdate.cpp
11 +++ b/js/src/jsdate.cpp
12 @@ -2348,22 +2348,26 @@ static PRMJTime ToPRMJTime(double localT
13 prtm.tm_isdst = (DaylightSavingTA(utcTime) != 0);
18 static size_t FormatTime(char* buf, int buflen, const char* fmt, double utcTime,
20 PRMJTime prtm = ToPRMJTime(localTime, utcTime);
21 - int eqivalentYear = IsRepresentableAsTime32(utcTime)
23 + // If an equivalent year was used to compute the date/time components, use
24 + // the same equivalent year to determine the time zone name and offset in
25 + // PRMJ_FormatTime(...).
26 + int timeZoneYear = IsRepresentableAsTime32(utcTime)
28 : EquivalentYearForDST(prtm.tm_year);
29 int offsetInSeconds = (int)floor((localTime - utcTime) / msPerSecond);
31 - return PRMJ_FormatTime(buf, buflen, fmt, &prtm, eqivalentYear,
32 + return PRMJ_FormatTime(buf, buflen, fmt, &prtm, timeZoneYear,
36 enum class FormatSpec { DateTime, Date, Time };
38 static bool FormatDate(JSContext* cx, double utcTime, FormatSpec format,
39 MutableHandleValue rval) {
41 diff --git a/js/src/vm/Time.cpp b/js/src/vm/Time.cpp
42 --- a/js/src/vm/Time.cpp
43 +++ b/js/src/vm/Time.cpp
44 @@ -242,17 +242,17 @@ static void PRMJ_InvalidParameterHandler
45 const wchar_t* file, unsigned int line,
46 uintptr_t pReserved) {
51 /* Format a time value into a buffer. Same semantics as strftime() */
52 size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
53 - const PRMJTime* prtm, int equivalentYear,
54 + const PRMJTime* prtm, int timeZoneYear,
55 int offsetInSeconds) {
57 #if defined(XP_UNIX) || defined(XP_WIN)
60 _invalid_parameter_handler oldHandler;
63 @@ -275,39 +275,33 @@ size_t PRMJ_FormatTime(char* buf, int bu
65 #if defined(HAVE_LOCALTIME_R) && defined(HAVE_TM_ZONE_TM_GMTOFF)
66 char emptyTimeZoneId[] = "";
69 * Fill out |td| to the time represented by |prtm|, leaving the
70 * timezone fields zeroed out. localtime_r will then fill in the
71 * timezone fields for that local time according to the system's
72 - * timezone parameters.
73 + * timezone parameters. Use |timeZoneYear| for the year to ensure the
74 + * time zone name matches the time zone offset used by the caller.
77 memset(&td, 0, sizeof(td));
78 td.tm_sec = prtm->tm_sec;
79 td.tm_min = prtm->tm_min;
80 td.tm_hour = prtm->tm_hour;
81 td.tm_mday = prtm->tm_mday;
82 td.tm_mon = prtm->tm_mon;
83 td.tm_wday = prtm->tm_wday;
84 - td.tm_year = prtm->tm_year - 1900;
85 + td.tm_year = timeZoneYear - 1900;
86 td.tm_yday = prtm->tm_yday;
87 td.tm_isdst = prtm->tm_isdst;
89 time_t t = mktime(&td);
91 - // If |prtm| cannot be represented in |time_t| the year is probably
92 - // out of range, try again with the DST equivalent year.
93 - if (t == static_cast<time_t>(-1)) {
94 - td.tm_year = equivalentYear - 1900;
98 // If either mktime or localtime_r failed, fill in the fallback time
99 // zone offset |offsetInSeconds| and set the time zone identifier to
101 if (t != static_cast<time_t>(-1) && localtime_r(&t, &td)) {
102 a.tm_gmtoff = td.tm_gmtoff;
103 a.tm_zone = td.tm_zone;
105 a.tm_gmtoff = offsetInSeconds;
106 diff --git a/js/src/vm/Time.h b/js/src/vm/Time.h
107 --- a/js/src/vm/Time.h
108 +++ b/js/src/vm/Time.h
109 @@ -44,17 +44,17 @@ inline void PRMJ_NowInit() {}
111 extern void PRMJ_NowShutdown();
113 inline void PRMJ_NowShutdown() {}
116 /* Format a time value into a buffer. Same semantics as strftime() */
117 extern size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
118 - const PRMJTime* tm, int equivalentYear,
119 + const PRMJTime* tm, int timeZoneYear,
120 int offsetInSeconds);
123 * Requesting the number of cycles from the CPU.
125 * `rdtsc`, or Read TimeStamp Cycle, is an instruction provided by
126 * x86-compatible CPUs that lets processes request the number of
127 * cycles spent by the CPU executing instructions since the CPU was