1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time: turn Time.unix to i64, so it can represent times before 1970-01-01, fix time operators, add more tests (#11050)

This commit is contained in:
Delyan Angelov
2021-08-04 13:12:02 +03:00
committed by GitHub
parent 1bf6d04e37
commit efa8dcf4d2
15 changed files with 107 additions and 40 deletions

View File

@ -160,18 +160,18 @@ fn test_add() {
t2 := time_to_test.add(duration)
assert t2.second == t1.second + d_seconds
assert t2.microsecond == t1.microsecond + d_microseconds
assert t2.unix == t1.unix + u64(d_seconds)
assert t2.unix == t1.unix + d_seconds
t3 := time_to_test.add(-duration)
assert t3.second == t1.second - d_seconds
assert t3.microsecond == t1.microsecond - d_microseconds
assert t3.unix == t1.unix - u64(d_seconds)
assert t3.unix == t1.unix - d_seconds
}
fn test_add_days() {
num_of_days := 3
t := time_to_test.add_days(num_of_days)
assert t.day == time_to_test.day + num_of_days
assert t.unix == time_to_test.unix + 86400 * u64(num_of_days)
assert t.unix == time_to_test.unix + 86400 * num_of_days
}
fn test_str() {
@ -217,8 +217,8 @@ fn test_unix_time() {
//
utm1 := t1.unix_time_milli()
utm2 := t2.unix_time_milli()
assert (utm1 - u64(ut1) * 1000) < 1000
assert (utm2 - u64(ut2) * 1000) < 1000
assert (utm1 - ut1 * 1000) < 1000
assert (utm2 - ut2 * 1000) < 1000
//
// println('utm1: $utm1 | utm2: $utm2')
assert utm2 - utm1 > 2