time: fix error for time.local() on windows (#13892)

pull/13893/head
yuyi 2022-04-01 22:16:46 +08:00 committed by GitHub
parent 02c80bd445
commit 6987f2c087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -446,6 +446,22 @@ jobs:
run: .\v.exe test-self run: .\v.exe test-self
# - name: Test # - name: Test
# run: .\v.exe test-all # 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 - name: Test v->js
run: ./v -o hi.js examples/hello_v_js.v && node hi.js run: ./v -o hi.js examples/hello_v_js.v && node hi.js
- name: Test v binaries - name: Test v binaries

View File

@ -97,6 +97,9 @@ fn local_as_unix_time() i64 {
// local - return the time `t`, converted to the currently active local timezone // local - return the time `t`, converted to the currently active local timezone
pub fn (t Time) local() Time { pub fn (t Time) local() Time {
if t.is_local {
return t
}
st_utc := SystemTime{ st_utc := SystemTime{
year: u16(t.year) year: u16(t.year)
month: u16(t.month) month: u16(t.month)
@ -140,6 +143,7 @@ fn win_now() Time {
second: st_local.second second: st_local.second
microsecond: st_local.millisecond * 1000 microsecond: st_local.millisecond * 1000
unix: st_local.unix_time() unix: st_local.unix_time()
is_local: true
} }
return t return t
} }
@ -161,6 +165,7 @@ fn win_utc() Time {
second: st_utc.second second: st_utc.second
microsecond: st_utc.millisecond * 1000 microsecond: st_utc.millisecond * 1000
unix: st_utc.unix_time() unix: st_utc.unix_time()
is_local: false
} }
return t return t
} }