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

time: rewrite unix() function

This commit is contained in:
lutherwenxu
2020-01-01 00:11:47 +08:00
committed by Alexander Medvednikov
parent 67912c692b
commit 286a0a1371
8 changed files with 186 additions and 109 deletions

View File

@ -46,6 +46,38 @@ fn test_unix() {
assert t.hour == 2
assert t.minute == 14
assert t.second == 59
t2 := time.unix(1078058096)
assert t2.year == 2004
assert t2.month == 2
assert t2.day == 29
assert t2.hour == 12
assert t2.minute == 34
assert t2.second == 56
t3 := time.unix(1070236799)
assert t3.year == 2003
assert t3.month == 11
assert t3.day == 30
assert t3.hour == 23
assert t3.minute == 59
assert t3.second == 59
t4 := time.unix(1577783439)
assert t4.year == 2019
assert t4.month == 12
assert t4.day == 31
assert t4.hour == 9
assert t4.minute == 10
assert t4.second == 39
t5 := time.unix(-1824922433)
assert t5.year == 1912
assert t5.month == 3
assert t5.day == 4
assert t5.hour == 5
assert t5.minute == 6
assert t5.second == 7
}
fn test_format_ss() {
@ -63,7 +95,7 @@ fn test_smonth() {
t := time.Time {
year: 1980, month: month_num, day: 1,
hour: 0, minute: 0, second: 0, uni: 0
hour: 0, minute: 0, second: 0, unix: 0
}
assert t.smonth() == name
@ -105,7 +137,7 @@ fn test_day_of_week() {
// 2 Dec 2019 is Monday
t := time.Time {
year: 2019, month: 12, day: 2 + i,
hour: 0, minute: 0, second: 0, uni: 0
hour: 0, minute: 0, second: 0, unix: 0
}
assert day_of_week == t.day_of_week()
@ -119,7 +151,7 @@ fn test_weekday_str() {
// 2 Dec 2019 is Monday
t := time.Time {
year: 2019, month: 12, day: 2 + i,
hour: 0, minute: 0, second: 0, uni: 0
hour: 0, minute: 0, second: 0, unix: 0
}
assert t.weekday_str() == name