From 6987f2c08758c0a8cc20583371571290c2f7054f Mon Sep 17 00:00:00 2001 From: yuyi Date: Fri, 1 Apr 2022 22:16:46 +0800 Subject: [PATCH] time: fix error for time.local() on windows (#13892) --- .github/workflows/ci.yml | 16 ++++++++++++++++ vlib/time/time_windows.c.v | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70464b1ea9..df3ab6cb2c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -446,6 +446,22 @@ jobs: run: .\v.exe test-self # - name: Test # run: .\v.exe test-all + - name: Test time functions in a timezone UTC-12 + run: | + tzutil /s "Dateline Standard Time" + ./v test vlib/time/ + - name: Test time functions in a timezone UTC-3 + run: | + tzutil /s "Greenland Standard Time" + ./v test vlib/time/ + - name: Test time functions in a timezone UTC+3 + run: | + tzutil /s "Russian Standard Time" + ./v test vlib/time/ + - name: Test time functions in a timezone UTC+12 + run: | + tzutil /s "New Zealand Standard Time" + ./v test vlib/time/ - name: Test v->js run: ./v -o hi.js examples/hello_v_js.v && node hi.js - name: Test v binaries diff --git a/vlib/time/time_windows.c.v b/vlib/time/time_windows.c.v index 19d2e71e36..7d0620c2fe 100644 --- a/vlib/time/time_windows.c.v +++ b/vlib/time/time_windows.c.v @@ -97,6 +97,9 @@ fn local_as_unix_time() i64 { // local - return the time `t`, converted to the currently active local timezone pub fn (t Time) local() Time { + if t.is_local { + return t + } st_utc := SystemTime{ year: u16(t.year) month: u16(t.month) @@ -140,6 +143,7 @@ fn win_now() Time { second: st_local.second microsecond: st_local.millisecond * 1000 unix: st_local.unix_time() + is_local: true } return t } @@ -161,6 +165,7 @@ fn win_utc() Time { second: st_utc.second microsecond: st_utc.millisecond * 1000 unix: st_utc.unix_time() + is_local: false } return t }