0010-always-use-the-equivalent-year-to-determine-the-time-zone.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. From 903a79a1efff18fc7cc50db09a3fe5d768adc9a8 Mon 19 Mar 2018 09:58:06 +0100
  2. From: André Bargull <andrebargull@gmail.com>
  3. Date: Wed, 8 Nov 2017 03:23:41 -0800
  4. Subject: always use the equivalent year to determine the time zone offset and
  5. name
  6. Fixes: https://bugzilla.mozilla.org/show_bug.cgi?id=1415202
  7. Upsream-status: Applied
  8. See: https://hg.mozilla.org/mozilla-central/rev/ce9f1466ec78
  9. Reviewed-by: Jeff Walden
  10. Signed-off-by: André Bargull <andrebargull@gmail.com>
  11. Signed-off-by: Adam Duskett <aduskett@gmail.com>
  12. ---
  13. js/src/jsdate.cpp | 11 +++++++----
  14. js/src/vm/Time.cpp | 14 ++++----------
  15. js/src/vm/Time.h | 2 +-
  16. 3 files changed, 12 insertions(+), 15 deletions(-)
  17. diff --git a/js/src/jsdate.cpp b/js/src/jsdate.cpp
  18. index 07af3d18c865..ff8fd6c3763c 100644
  19. --- a/js/src/jsdate.cpp
  20. +++ b/js/src/jsdate.cpp
  21. @@ -2353,12 +2353,15 @@ static PRMJTime ToPRMJTime(double localTime, double utcTime) {
  22. static size_t FormatTime(char* buf, int buflen, const char* fmt, double utcTime,
  23. double localTime) {
  24. PRMJTime prtm = ToPRMJTime(localTime, utcTime);
  25. - int eqivalentYear = IsRepresentableAsTime32(utcTime)
  26. - ? prtm.tm_year
  27. - : EquivalentYearForDST(prtm.tm_year);
  28. + // If an equivalent year was used to compute the date/time components, use
  29. + // the same equivalent year to determine the time zone name and offset in
  30. + // PRMJ_FormatTime(...).
  31. + int timeZoneYear = IsRepresentableAsTime32(utcTime)
  32. + ? prtm.tm_year
  33. + : EquivalentYearForDST(prtm.tm_year);
  34. int offsetInSeconds = (int)floor((localTime - utcTime) / msPerSecond);
  35. - return PRMJ_FormatTime(buf, buflen, fmt, &prtm, eqivalentYear,
  36. + return PRMJ_FormatTime(buf, buflen, fmt, &prtm, timeZoneYear,
  37. offsetInSeconds);
  38. }
  39. diff --git a/js/src/vm/Time.cpp b/js/src/vm/Time.cpp
  40. index f59977f0d0e9..5ee4794b3e83 100644
  41. --- a/js/src/vm/Time.cpp
  42. +++ b/js/src/vm/Time.cpp
  43. @@ -247,7 +247,7 @@ static void PRMJ_InvalidParameterHandler(const wchar_t* expression,
  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. @@ -280,7 +280,8 @@ size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
  52. * Fill out |td| to the time represented by |prtm|, leaving the
  53. * timezone fields zeroed out. localtime_r will then fill in the
  54. * timezone fields for that local time according to the system's
  55. - * timezone parameters.
  56. + * timezone parameters. Use |timeZoneYear| for the year to ensure the
  57. + * time zone name matches the time zone offset used by the caller.
  58. */
  59. struct tm td;
  60. memset(&td, 0, sizeof(td));
  61. @@ -290,19 +291,12 @@ size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
  62. td.tm_mday = prtm->tm_mday;
  63. td.tm_mon = prtm->tm_mon;
  64. td.tm_wday = prtm->tm_wday;
  65. - td.tm_year = prtm->tm_year - 1900;
  66. + td.tm_year = timeZoneYear - 1900;
  67. td.tm_yday = prtm->tm_yday;
  68. td.tm_isdst = prtm->tm_isdst;
  69. time_t t = mktime(&td);
  70. - // If |prtm| cannot be represented in |time_t| the year is probably
  71. - // out of range, try again with the DST equivalent year.
  72. - if (t == static_cast<time_t>(-1)) {
  73. - td.tm_year = equivalentYear - 1900;
  74. - t = mktime(&td);
  75. - }
  76. -
  77. // If either mktime or localtime_r failed, fill in the fallback time
  78. // zone offset |offsetInSeconds| and set the time zone identifier to
  79. // the empty string.
  80. diff --git a/js/src/vm/Time.h b/js/src/vm/Time.h
  81. index 3a51d869c922..37b7faeec028 100644
  82. --- a/js/src/vm/Time.h
  83. +++ b/js/src/vm/Time.h
  84. @@ -49,7 +49,7 @@ inline void PRMJ_NowShutdown() {}
  85. /* Format a time value into a buffer. Same semantics as strftime() */
  86. extern size_t PRMJ_FormatTime(char* buf, int buflen, const char* fmt,
  87. - const PRMJTime* tm, int equivalentYear,
  88. + const PRMJTime* tm, int timeZoneYear,
  89. int offsetInSeconds);
  90. /**
  91. --
  92. 2.23.0