Skip to content

Commit d69f60d

Browse files
committed
Fix timezone extraction to work in all locales
Followup to #21585
1 parent ecdca7b commit d69f60d

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

.circleci/config.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,9 @@ jobs:
918918
python: "$EMSDK_PYTHON"
919919
- run-tests:
920920
title: "crossplatform tests"
921-
test_targets: "--crossplatform-only"
921+
# Skipping test_strftime_zZ_gb_locale since this test forces the
922+
# locale to one that is not necessarily available on macOS.
923+
test_targets: "--crossplatform-only skip:other.test_strftime_zZ_gb_locale"
922924
- upload-test-results
923925

924926
test-mac-arm64:
@@ -940,7 +942,9 @@ jobs:
940942
# are currently missing arm64 macos binaries.
941943
- run-tests:
942944
title: "crossplatform tests"
943-
test_targets: "--crossplatform-only"
945+
# Skipping test_strftime_zZ_gb_locale since this test forces the
946+
# locale to one that is not necessarily available on macOS.
947+
test_targets: "--crossplatform-only skip:other.test_strftime_zZ_gb_locale"
944948
- upload-test-results
945949

946950
workflows:

src/library.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,12 @@ addToLibrary({
649649

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

652-
var extractZone = (date) => date.toLocaleTimeString(undefined, {timeZoneName:'short'}).split(' ')[2];
652+
var extractZone = (date) => date.toLocaleTimeString(undefined, {hour12:false, timeZoneName:'short'}).split(' ')[1];
653653
var winterName = extractZone(winter);
654654
var summerName = extractZone(summer);
655655
#if ASSERTIONS
656+
assert(winterName);
657+
assert(summerName);
656658
assert(lengthBytesUTF8(winterName) <= {{{ cDefs.TZNAME_MAX }}}, `timezone name truncated to fit in TZNAME_MAX (${winterName})`);
657659
assert(lengthBytesUTF8(summerName) <= {{{ cDefs.TZNAME_MAX }}}, `timezone name truncated to fit in TZNAME_MAX (${summerName})`);
658660
#endif

test/common.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,25 @@ def modified(self, *args, **kwargs):
365365
return decorated
366366

367367

368+
# Decorator version of env_modify
369+
def also_with_env_modify(name, updates):
370+
371+
def decorated(f):
372+
@wraps(f)
373+
def metafunc(self, modified, *args, **kwargs):
374+
if modified:
375+
with env_modify(updates):
376+
return f(self, *args, **kwargs)
377+
else:
378+
return f(self, *args, **kwargs)
379+
380+
metafunc._parameterize = {'': (False,),
381+
name: (True,)}
382+
return metafunc
383+
384+
return decorated
385+
386+
368387
def also_with_minimal_runtime(f):
369388
assert callable(f)
370389

test/test_other.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
from common import env_modify, no_mac, no_windows, only_windows, requires_native_clang, with_env_modify
3535
from common import create_file, parameterized, NON_ZERO, node_pthreads, TEST_ROOT, test_file
3636
from common import compiler_for, EMBUILDER, requires_v8, requires_node, requires_wasm64, requires_node_canary
37-
from common import requires_wasm_eh, crossplatform, with_both_eh_sjlj, with_both_sjlj, also_with_standalone_wasm
37+
from common import requires_wasm_eh, crossplatform, with_both_eh_sjlj, with_both_sjlj
38+
from common import also_with_standalone_wasm, also_with_env_modify
3839
from common import also_with_minimal_runtime, also_with_wasm_bigint, also_with_wasm64, flaky
3940
from common import EMTEST_BUILD_VERBOSE, PYTHON, WEBIDL_BINDER
4041
from common import requires_network
@@ -5717,6 +5718,8 @@ def test_only_force_stdlibs_2(self):
57175718
self.run_process([EMXX, 'src.cpp', '-sDISABLE_EXCEPTION_CATCHING=0'])
57185719
self.assertContained('Caught exception: std::exception', self.run_js('a.out.js'))
57195720

5721+
@crossplatform
5722+
@also_with_env_modify('gb_locale', {'LC_ALL': 'en_GB'})
57205723
def test_strftime_zZ(self):
57215724
create_file('src.c', r'''
57225725
#include <errno.h>

0 commit comments

Comments
 (0)