mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
time: Time.add (#7262)
This commit is contained in:
@@ -171,15 +171,22 @@ pub fn (t Time) unix_time_milli() u64 {
|
||||
return t.unix * 1000 + u64(t.microsecond / 1000)
|
||||
}
|
||||
|
||||
// add returns a new time that duration is added
|
||||
pub fn (t Time) add(d Duration) Time {
|
||||
microseconds := i64(t.unix) * 1000 * 1000 + t.microsecond + d.microseconds()
|
||||
unix := microseconds / (1000 * 1000)
|
||||
micro := microseconds % (1000 * 1000)
|
||||
return unix2(int(unix), int(micro))
|
||||
}
|
||||
|
||||
// add_seconds returns a new time struct with an added number of seconds.
|
||||
pub fn (t Time) add_seconds(seconds int) Time {
|
||||
// TODO Add(d time.Duration)
|
||||
return unix(int(t.unix + u64(seconds)))
|
||||
return t.add(seconds * second)
|
||||
}
|
||||
|
||||
// add_days returns a new time struct with an added number of days.
|
||||
pub fn (t Time) add_days(days int) Time {
|
||||
return unix(int(t.unix + u64(i64(days) * 3600 * 24)))
|
||||
return t.add(days * 24 * hour)
|
||||
}
|
||||
|
||||
// since returns a number of seconds elapsed since a given time.
|
||||
|
||||
Reference in New Issue
Block a user