Skip to content

Commit a98f6de

Browse files
committed
Use short timezone names in _tzset_js
Without this change then timezone names will be the long form (Pacific Standard Time) rather than the short form (PST), and since TZNAME_MAX in musl is 6 (same in POSIX) the long names were getting truncated. Fixes emscripten-core#21582
1 parent 2316d8a commit a98f6de

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/library.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,13 @@ addToLibrary({
645645

646646
{{{ makeSetValue('daylight', '0', 'Number(winterOffset != summerOffset)', 'i32') }}};
647647

648-
function extractZone(date) {
649-
var match = date.toTimeString().match(/\(([A-Za-z ]+)\)$/);
650-
return match ? match[1] : "GMT";
651-
};
648+
var extractZone = (date) => date.toLocaleTimeString(undefined, {timeZoneName:'short'}).split(' ')[2];
652649
var winterName = extractZone(winter);
653650
var summerName = extractZone(summer);
651+
#if ASSERTIONS
652+
assert(lengthBytesUTF8(winterName) <= {{{ cDefs.TZNAME_MAX }}}, `timezone name truncated to fix in TZNAME_MAX (${winterName})`);
653+
assert(lengthBytesUTF8(summerName) <= {{{ cDefs.TZNAME_MAX }}}, `timezone name truncated to fix in TZNAME_MAX (${summerName})`);
654+
#endif
654655
if (summerOffset < winterOffset) {
655656
// Northern hemisphere
656657
stringToUTF8(winterName, std_name, {{{ cDefs.TZNAME_MAX + 1 }}});

test/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def get_all_tests(modules):
135135

136136

137137
def get_crossplatform_tests(modules):
138-
suites = ['core2', 'other'] # We don't need all versions of every test
138+
suites = ['core0', 'other'] # We don't need all versions of every test
139139
crossplatform_tests = []
140140
# Walk over the test suites and find the test functions with the
141141
# is_crossplatform_test attribute applied by @crossplatform decorator

test/test_core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,7 @@ def test_strptime_reentrant(self):
26562656
self.set_setting('EXIT_RUNTIME')
26572657
self.do_core_test('test_strptime_reentrant.c')
26582658

2659+
@crossplatform
26592660
def test_strftime(self):
26602661
self.do_core_test('test_strftime.c')
26612662

0 commit comments

Comments
 (0)