aboutsummaryrefslogtreecommitdiff
path: root/src/cli/test_command.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-05-23 00:40:12 -0700
committerGravatar GitHub <noreply@github.com> 2023-05-23 00:40:12 -0700
commit5b38c55c3db018a94505f61cd785f0dd40f442ac (patch)
treeaf522e38ffa9b6c400c500c76de1fdca4ab931db /src/cli/test_command.zig
parent83e7b9e198b25c7af7905c5dcabe1e325c5a38fb (diff)
downloadbun-5b38c55c3db018a94505f61cd785f0dd40f442ac.tar.gz
bun-5b38c55c3db018a94505f61cd785f0dd40f442ac.tar.zst
bun-5b38c55c3db018a94505f61cd785f0dd40f442ac.zip
Support setting a timezone with `process.env.TZ` and `Bun.env.TZ` (#3018)
* Support setting a timezone via `process.env.TZ` * Implement `setTimeZone` in `bun:jsc` module * [breaking] `bun:test` now defaults to `Etc/UTC` timezone --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/cli/test_command.zig')
-rw-r--r--src/cli/test_command.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig
index 996289ac4..8330a786b 100644
--- a/src/cli/test_command.zig
+++ b/src/cli/test_command.zig
@@ -382,6 +382,7 @@ const Scanner = struct {
pub const TestCommand = struct {
pub const name = "test";
pub const old_name = "wiptest";
+
pub fn exec(ctx: Command.Context) !void {
if (comptime is_bindgen) unreachable;
// print the version so you know its doing stuff if it takes a sec
@@ -460,6 +461,18 @@ pub const TestCommand = struct {
vm.is_main_thread = true;
JSC.VirtualMachine.is_main_thread_vm = true;
+ // For tests, we default to UTC time zone
+ // unless the user inputs TZ="", in which case we use local time zone
+ var TZ_NAME: string =
+ // We use the string "Etc/UTC" instead of "UTC" so there is no normalization difference.
+ "Etc/UTC";
+ if (vm.bundler.env.get("TZ")) |tz| {
+ TZ_NAME = tz;
+ }
+ if (TZ_NAME.len > 0) {
+ _ = vm.global.setTimeZone(&JSC.ZigString.init(TZ_NAME));
+ }
+
var scanner = Scanner{
.dirs_to_scan = Scanner.Fifo.init(ctx.allocator),
.options = &vm.bundler.options,