Skip to content

Commit efb2ffc

Browse files
authored
Use short timezone names in _tzset_js (#21585)
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 #21582
1 parent 618ed94 commit efb2ffc

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/library.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,11 @@ addToLibrary({
618618
return ret;
619619
},
620620

621-
_tzset_js__deps: ['$stringToUTF8'],
621+
_tzset_js__deps: ['$stringToUTF8',
622+
#if ASSERTIONS
623+
'$lengthBytesUTF8',
624+
#endif
625+
],
622626
_tzset_js__internal: true,
623627
_tzset_js: (timezone, daylight, std_name, dst_name) => {
624628
// TODO: Use (malleable) environment variables instead of system settings.
@@ -645,12 +649,13 @@ addToLibrary({
645649

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

648-
function extractZone(date) {
649-
var match = date.toTimeString().match(/\(([A-Za-z ]+)\)$/);
650-
return match ? match[1] : "GMT";
651-
};
652+
var extractZone = (date) => date.toLocaleTimeString(undefined, {timeZoneName:'short'}).split(' ')[2];
652653
var winterName = extractZone(winter);
653654
var summerName = extractZone(summer);
655+
#if ASSERTIONS
656+
assert(lengthBytesUTF8(winterName) <= {{{ cDefs.TZNAME_MAX }}}, `timezone name truncated to fit in TZNAME_MAX (${winterName})`);
657+
assert(lengthBytesUTF8(summerName) <= {{{ cDefs.TZNAME_MAX }}}, `timezone name truncated to fit in TZNAME_MAX (${summerName})`);
658+
#endif
654659
if (summerOffset < winterOffset) {
655660
// Northern hemisphere
656661
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)