time: add test to reproduce the issue #13828
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>pull/13861/head
parent
9c1981a309
commit
5e3a916afe
|
|
@ -20,7 +20,8 @@ struct C.tm {
|
|||
|
||||
fn C.timegm(&C.tm) C.time_t
|
||||
|
||||
// fn C.gmtime_r(&tm, &gbuf)
|
||||
// prefering localtime_r over the localtime because
|
||||
// from docs localtime_r is thread safe,
|
||||
fn C.localtime_r(t &C.time_t, tm &C.tm)
|
||||
|
||||
fn make_unix_time(t C.tm) i64 {
|
||||
|
|
|
|||
|
|
@ -254,3 +254,28 @@ fn test_since() {
|
|||
d2 := time.since(t1)
|
||||
assert d2 >= 40_000_000
|
||||
}
|
||||
|
||||
// issue relate https://github.com/vlang/v/issues/13828
|
||||
// problem: the local method add 2h on the time in a Linux machine
|
||||
// the other machine are not tested in a local env
|
||||
fn test_recursive_local_call() {
|
||||
assert time.now().unix == time.now().local().unix
|
||||
assert time.now().str() == time.now().local().str()
|
||||
assert time.now().local().str() == time.now().local().local().str()
|
||||
}
|
||||
|
||||
fn test_local_method_with_time_operation() {
|
||||
//FIXME: add a fixed TIMEZONE here
|
||||
assert time.now().str() != time.utc().str()
|
||||
assert time.now().str() == time.utc().local().str()
|
||||
|
||||
utc := time.utc()
|
||||
utc_plus_1h := time.utc().add(time.hour).local()
|
||||
|
||||
// check if the utc local is increased by 1h
|
||||
assert utc_plus_1h.hour == time.now().local().hour - 1
|
||||
// trivial check
|
||||
assert utc.hour < utc_plus_1h.hour
|
||||
// normal utc vs an 1h alterate utc + local convertion
|
||||
assert utc.hour == utc_plus_1h.hour - 3
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ pub fn (t Time) local() Time {
|
|||
hour: u16(t.hour)
|
||||
minute: u16(t.minute)
|
||||
second: u16(t.second)
|
||||
millisecond: u16(t.microsecond / 1000)
|
||||
}
|
||||
st_local := SystemTime{}
|
||||
C.SystemTimeToTzSpecificLocalTime(voidptr(0), &st_utc, &st_local)
|
||||
|
|
|
|||
Loading…
Reference in New Issue