Skip to content

Commit 5dbc880

Browse files
authored
browser(webkit): print friendly tz names (#969)
1 parent c19a7be commit 5dbc880

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

browser_patches/webkit/BUILD_NUMBER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1147
1+
1148

browser_patches/webkit/patches/bootstrap.diff

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ index 9e2bee913d37c79fedbb918176a43022b84fa45b..ad8926d773144114dad3842fa0fe2391
13141314
},
13151315
{
13161316
diff --git a/Source/JavaScriptCore/runtime/DateConversion.cpp b/Source/JavaScriptCore/runtime/DateConversion.cpp
1317-
index 955756ba405f400970610f9a68c7ed42a67cb015..6e281fc075425a324fd30a4608e9e97d547044f2 100644
1317+
index 955756ba405f400970610f9a68c7ed42a67cb015..1520c0a1475a90de2795e4ccd8919c1bb1384066 100644
13181318
--- a/Source/JavaScriptCore/runtime/DateConversion.cpp
13191319
+++ b/Source/JavaScriptCore/runtime/DateConversion.cpp
13201320
@@ -100,17 +100,23 @@ String formatDateTime(const GregorianDateTime& t, DateTimeFormat format, bool as
@@ -1327,8 +1327,8 @@ index 955756ba405f400970610f9a68c7ed42a67cb015..6e281fc075425a324fd30a4608e9e97d
13271327
- const WCHAR* winTimeZoneName = t.isDST() ? timeZoneInformation.DaylightName : timeZoneInformation.StandardName;
13281328
- String timeZoneName(winTimeZoneName);
13291329
+ String timeZoneName;
1330-
+ if (!WTF::timeZoneForAutomation().isEmpty()) {
1331-
+ timeZoneName = WTF::timeZoneForAutomation();
1330+
+ if (!WTF::timeZoneDisplayNameForAutomation().isEmpty()) {
1331+
+ timeZoneName = WTF::timeZoneDisplayNameForAutomation();
13321332
+ } else {
13331333
+ #if OS(WINDOWS)
13341334
+ TIME_ZONE_INFORMATION timeZoneInformation;
@@ -1374,16 +1374,17 @@ index 9817a45ea2f3a22844ed3e56816cff94eb051423..67f7459a556ed22740fbfcd2b1b7b530
13741374
// The DefaultTimeZone abstract operation returns a String value representing the valid (6.4.1) and canonicalized (6.4.2) time zone name for the host environment’s current time zone.
13751375

13761376
diff --git a/Source/WTF/wtf/DateMath.cpp b/Source/WTF/wtf/DateMath.cpp
1377-
index 1999737341553001d5246b8190e9ea11d615a158..1b09b2a2a6b78a80aaf8a45dad984e7628fc5188 100644
1377+
index 1999737341553001d5246b8190e9ea11d615a158..540ed892bca8110f8013477da7bd9b459a17e60d 100644
13781378
--- a/Source/WTF/wtf/DateMath.cpp
13791379
+++ b/Source/WTF/wtf/DateMath.cpp
1380-
@@ -77,11 +77,15 @@
1380+
@@ -77,11 +77,16 @@
13811381
#include <limits>
13821382
#include <stdint.h>
13831383
#include <time.h>
13841384
+#include <unicode/ucal.h>
13851385
#include <wtf/Assertions.h>
13861386
#include <wtf/ASCIICType.h>
1387+
+#include <wtf/Language.h>
13871388
#include <wtf/MathExtras.h>
13881389
+#include <wtf/NeverDestroyed.h>
13891390
#include <wtf/StdLibExtras.h>
@@ -1393,13 +1394,14 @@ index 1999737341553001d5246b8190e9ea11d615a158..1b09b2a2a6b78a80aaf8a45dad984e76
13931394

13941395
#if OS(WINDOWS)
13951396
#include <windows.h>
1396-
@@ -107,6 +111,17 @@ template<unsigned length> inline bool startsWithLettersIgnoringASCIICase(const c
1397+
@@ -107,6 +112,18 @@ template<unsigned length> inline bool startsWithLettersIgnoringASCIICase(const c
13971398
return equalLettersIgnoringASCIICase(string, lowercaseLetters, length - 1);
13981399
}
13991400

14001401
+struct TimeZoneForAutomation {
14011402
+ UCalendar* cal;
1402-
+ String name;
1403+
+ String id;
1404+
+ String displayName;
14031405
+};
14041406
+
14051407
+static TimeZoneForAutomation& innerTimeZoneForAutomation()
@@ -1411,7 +1413,7 @@ index 1999737341553001d5246b8190e9ea11d615a158..1b09b2a2a6b78a80aaf8a45dad984e76
14111413
/* Constants */
14121414

14131415
const char* const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
1414-
@@ -333,6 +348,14 @@ static double calculateDSTOffset(time_t localTime, double utcOffset)
1416+
@@ -333,6 +350,14 @@ static double calculateDSTOffset(time_t localTime, double utcOffset)
14151417
// Returns combined offset in millisecond (UTC + DST).
14161418
LocalTimeOffset calculateLocalTimeOffset(double ms, TimeType inputTimeType)
14171419
{
@@ -1426,18 +1428,19 @@ index 1999737341553001d5246b8190e9ea11d615a158..1b09b2a2a6b78a80aaf8a45dad984e76
14261428
#if HAVE(TM_GMTOFF)
14271429
double localToUTCTimeOffset = inputTimeType == LocalTime ? calculateUTCOffset() : 0;
14281430
#else
1429-
@@ -1034,4 +1057,46 @@ String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, u
1431+
@@ -1034,4 +1059,65 @@ String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, u
14301432
return stringBuilder.toString();
14311433
}
14321434

14331435
+bool setTimeZoneForAutomation(const String& timeZone)
14341436
+{
1437+
+ innerTimeZoneForAutomation().displayName = String();
14351438
+ if (innerTimeZoneForAutomation().cal) {
14361439
+ ucal_close(innerTimeZoneForAutomation().cal);
14371440
+ innerTimeZoneForAutomation().cal = nullptr;
14381441
+ }
14391442
+ if (timeZone.isEmpty()) {
1440-
+ innerTimeZoneForAutomation().name = String();
1443+
+ innerTimeZoneForAutomation().id = String();
14411444
+ return true;
14421445
+ }
14431446
+
@@ -1459,30 +1462,49 @@ index 1999737341553001d5246b8190e9ea11d615a158..1b09b2a2a6b78a80aaf8a45dad984e76
14591462
+ if (!U_SUCCESS(status))
14601463
+ return false;
14611464
+
1462-
+ innerTimeZoneForAutomation().cal = ucal_open(canonicalBuffer.data(), canonicalLength, nullptr, UCAL_TRADITIONAL, &status);
1465+
+ UCalendar* cal = ucal_open(canonicalBuffer.data(), canonicalLength, nullptr, UCAL_TRADITIONAL, &status);
14631466
+ if (!U_SUCCESS(status))
14641467
+ return false;
14651468
+
1466-
+ innerTimeZoneForAutomation().name = String(canonicalBuffer.data(), canonicalLength);
1469+
+ Vector<UChar, 32> displayNameBuffer(32);
1470+
+ auto displayNameLength = ucal_getTimeZoneDisplayName(cal, UCAL_STANDARD, defaultLanguage().utf8().data(), displayNameBuffer.data(), displayNameBuffer.size(), &status);
1471+
+ if (status == U_BUFFER_OVERFLOW_ERROR) {
1472+
+ status = U_ZERO_ERROR;
1473+
+ displayNameBuffer.grow(displayNameLength);
1474+
+ ucal_getTimeZoneDisplayName(cal, UCAL_STANDARD, defaultLanguage().utf8().data(), displayNameBuffer.data(), displayNameLength, &status);
1475+
+ }
1476+
+ if (!U_SUCCESS(status))
1477+
+ return false;
1478+
+
1479+
+ TimeZoneForAutomation& tzfa = innerTimeZoneForAutomation();
1480+
+ tzfa.cal = cal;
1481+
+ tzfa.id = String(canonicalBuffer.data(), canonicalLength);
1482+
+ tzfa.displayName = String(displayNameBuffer.data(), displayNameLength);
14671483
+ return true;
14681484
+}
14691485
+
14701486
+String timeZoneForAutomation()
14711487
+{
1472-
+ return innerTimeZoneForAutomation().name;
1488+
+ return innerTimeZoneForAutomation().id;
1489+
+}
1490+
+
1491+
+String timeZoneDisplayNameForAutomation()
1492+
+{
1493+
+ return innerTimeZoneForAutomation().displayName;
14731494
+}
14741495
+
14751496
} // namespace WTF
14761497
diff --git a/Source/WTF/wtf/DateMath.h b/Source/WTF/wtf/DateMath.h
1477-
index 602f89a49d454cc5e5acd030024227d49d98c61f..66da6661c0c7e2c13808b90ecce19884157487a7 100644
1498+
index 602f89a49d454cc5e5acd030024227d49d98c61f..41811e65bd0f15b443fb90d37ee4d0a21780a518 100644
14781499
--- a/Source/WTF/wtf/DateMath.h
14791500
+++ b/Source/WTF/wtf/DateMath.h
1480-
@@ -389,6 +389,9 @@ inline int dayInMonthFromDayInYear(int dayInYear, bool leapYear)
1501+
@@ -389,6 +389,10 @@ inline int dayInMonthFromDayInYear(int dayInYear, bool leapYear)
14811502
return d - step;
14821503
}
14831504

14841505
+WTF_EXPORT_PRIVATE bool setTimeZoneForAutomation(const String& timeZone);
14851506
+WTF_EXPORT_PRIVATE String timeZoneForAutomation();
1507+
+WTF_EXPORT_PRIVATE String timeZoneDisplayNameForAutomation();
14861508
+
14871509
// Returns combined offset in millisecond (UTC + DST).
14881510
WTF_EXPORT_PRIVATE LocalTimeOffset calculateLocalTimeOffset(double utcInMilliseconds, TimeType = UTCTime);

0 commit comments

Comments
 (0)