mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: fix time offset (#9449)
This commit is contained in:
parent
d9240bd983
commit
1b7fd2cf00
@ -1,4 +1,5 @@
|
||||
import time
|
||||
import math
|
||||
|
||||
const (
|
||||
time_to_test = time.Time{
|
||||
@ -223,3 +224,24 @@ fn test_unix_time() {
|
||||
assert utm2 - utm1 > 2
|
||||
assert utm2 - utm1 < 999
|
||||
}
|
||||
|
||||
fn test_offset() {
|
||||
u := time.utc()
|
||||
n := time.now()
|
||||
//
|
||||
mut diff_seconds := 0
|
||||
if u.day != n.day {
|
||||
if u.day > n.day {
|
||||
diff_seconds = int(math.abs(((u.hour * 60 + u.minute) - (n.hour * 60 + n.minute)) * 60)) - 86400
|
||||
} else {
|
||||
diff_seconds = 86400 - int(math.abs(((u.hour * 60 + u.minute) - (n.hour * 60 + n.minute)) * 60))
|
||||
}
|
||||
if math.abs(u.day - n.day) > 1 { // different month
|
||||
diff_seconds = diff_seconds * -1
|
||||
}
|
||||
} else { // same day
|
||||
diff_seconds = ((n.hour * 60 + n.minute) - (u.hour * 60 + u.minute)) * 60
|
||||
}
|
||||
|
||||
assert diff_seconds == time.offset()
|
||||
}
|
||||
|
@ -114,8 +114,8 @@ pub fn (t Time) local() Time {
|
||||
hour: st_local.hour
|
||||
minute: st_local.minute
|
||||
second: st_local.second // These are the same
|
||||
microsecond: t.microsecond
|
||||
unix: t.unix
|
||||
microsecond: st_local.millisecond * 1000
|
||||
unix: u64(st_local.unix_time())
|
||||
}
|
||||
return t_local
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user