time: implement `pub fn since(t Time) Duration`
parent
bb71089b70
commit
49ebba535e
|
@ -121,10 +121,9 @@ pub fn (t Time) add_days(days int) Time {
|
||||||
return t.add(days * 24 * time.hour)
|
return t.add(days * 24 * time.hour)
|
||||||
}
|
}
|
||||||
|
|
||||||
// since returns a number of seconds elapsed since a given time.
|
// since returns the time duration elapsed since a given time.
|
||||||
fn since(t Time) int {
|
pub fn since(t Time) Duration {
|
||||||
// TODO Use time.Duration instead of seconds
|
return now() - t
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// relative returns a string representation of the difference between t
|
// relative returns a string representation of the difference between t
|
||||||
|
|
|
@ -244,3 +244,13 @@ fn test_offset() {
|
||||||
|
|
||||||
assert diff_seconds == time.offset()
|
assert diff_seconds == time.offset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_since() {
|
||||||
|
t1 := time.now()
|
||||||
|
time.sleep(20 * time.millisecond)
|
||||||
|
d1 := time.since(t1)
|
||||||
|
assert d1 >= 20_000_000
|
||||||
|
time.sleep(20 * time.millisecond)
|
||||||
|
d2 := time.since(t1)
|
||||||
|
assert d2 >= 40_000_000
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue