bug1415202.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # HG changeset patch
  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
  8. diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp
  9. --- a/js/src/jsdate.cpp
  10. +++ b/js/src/jsdate.cpp
  11. @@ -2348,22 +2348,26 @@ static PRMJTime ToPRMJTime(double localT
  12. prtm.tm_isdst = (DaylightSavingTA(utcTime) != 0);
  13. return prtm;
  14. }
  15. static size_t FormatTime(char* buf, int buflen, const char* fmt, double utcTime,
  16. double localTime) {
  17. PRMJTime prtm = ToPRMJTime(localTime, utcTime);
  18. - int eqivalentYear = IsRepresentableAsTime32(utcTime)
  19. +
  20. + // If an equivalent year was used to compute the date/time components, use
  21. + // the same equivalent year to determine the time zone name and offset in
  22. + // PRMJ_FormatTime(...).
  23. + int timeZoneYear = IsRepresentableAsTime32(utcTime)
  24. ? prtm.tm_year
  25. : EquivalentYearForDST(prtm.tm_year);
  26. int offsetInSeconds = (int)floor((localTime - utcTime) / msPerSecond);
  27. - return PRMJ_FormatTime(buf, buflen, fmt, &prtm, eqivalentYear,
  28. + return PRMJ_FormatTime(buf, buflen, fmt, &prtm, timeZoneYear,
  29. offsetInSeconds);
  30. }
  31. enum class FormatSpec { DateTime, Date, Time };
  32. static bool FormatDate(JSContext* cx, double utcTime, FormatSpec format,
  33. MutableHandleValue rval) {
  34. JSString* str;
  35. diff --git a/js/src/vm/Time.cpp b/js/src/vm/Time.cpp
  36. --- a/js/src/vm/Time.cpp
  37. +++ b/js/src/vm/Time.cpp
  38. @@ -242,17 +242,17 @@ static void PRMJ_InvalidParameterHandler
  39. const wchar_t* file, unsigned int line,
  40. uintptr_t pReserved) {
  41. /* empty */
  42. }
  43. #endif
  44. /* Format a time value into a buffer. Same semantics as strftime() */
  45. size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
  46. - const PRMJTime* prtm, int equivalentYear,
  47. + const PRMJTime* prtm, int timeZoneYear,
  48. int offsetInSeconds) {
  49. size_t result = 0;
  50. #if defined(XP_UNIX) || defined(XP_WIN)
  51. struct tm a;
  52. #ifdef XP_WIN
  53. _invalid_parameter_handler oldHandler;
  54. #ifndef __MINGW32__
  55. int oldReportMode;
  56. @@ -275,39 +275,33 @@ size_t PRMJ_FormatTime(char* buf, int bu
  57. */
  58. #if defined(HAVE_LOCALTIME_R) && defined(HAVE_TM_ZONE_TM_GMTOFF)
  59. char emptyTimeZoneId[] = "";
  60. {
  61. /*
  62. * Fill out |td| to the time represented by |prtm|, leaving the
  63. * timezone fields zeroed out. localtime_r will then fill in the
  64. * timezone fields for that local time according to the system's
  65. - * timezone parameters.
  66. + * timezone parameters. Use |timeZoneYear| for the year to ensure the
  67. + * time zone name matches the time zone offset used by the caller.
  68. */
  69. struct tm td;
  70. memset(&td, 0, sizeof(td));
  71. td.tm_sec = prtm->tm_sec;
  72. td.tm_min = prtm->tm_min;
  73. td.tm_hour = prtm->tm_hour;
  74. td.tm_mday = prtm->tm_mday;
  75. td.tm_mon = prtm->tm_mon;
  76. td.tm_wday = prtm->tm_wday;
  77. - td.tm_year = prtm->tm_year - 1900;
  78. + td.tm_year = timeZoneYear - 1900;
  79. td.tm_yday = prtm->tm_yday;
  80. td.tm_isdst = prtm->tm_isdst;
  81. time_t t = mktime(&td);
  82. - // If |prtm| cannot be represented in |time_t| the year is probably
  83. - // out of range, try again with the DST equivalent year.
  84. - if (t == static_cast<time_t>(-1)) {
  85. - td.tm_year = equivalentYear - 1900;
  86. - t = mktime(&td);
  87. - }
  88. -
  89. // If either mktime or localtime_r failed, fill in the fallback time
  90. // zone offset |offsetInSeconds| and set the time zone identifier to
  91. // the empty string.
  92. if (t != static_cast<time_t>(-1) && localtime_r(&t, &td)) {
  93. a.tm_gmtoff = td.tm_gmtoff;
  94. a.tm_zone = td.tm_zone;
  95. } else {
  96. a.tm_gmtoff = offsetInSeconds;
  97. diff --git a/js/src/vm/Time.h b/js/src/vm/Time.h
  98. --- a/js/src/vm/Time.h
  99. +++ b/js/src/vm/Time.h
  100. @@ -44,17 +44,17 @@ inline void PRMJ_NowInit() {}
  101. #ifdef XP_WIN
  102. extern void PRMJ_NowShutdown();
  103. #else
  104. inline void PRMJ_NowShutdown() {}
  105. #endif
  106. /* Format a time value into a buffer. Same semantics as strftime() */
  107. extern size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
  108. - const PRMJTime* tm, int equivalentYear,
  109. + const PRMJTime* tm, int timeZoneYear,
  110. int offsetInSeconds);
  111. /**
  112. * Requesting the number of cycles from the CPU.
  113. *
  114. * `rdtsc`, or Read TimeStamp Cycle, is an instruction provided by
  115. * x86-compatible CPUs that lets processes request the number of
  116. * cycles spent by the CPU executing instructions since the CPU was