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

time: - operator overloading (#7259)

This commit is contained in:
Takahiro Yaota
2020-12-11 14:54:23 +09:00
committed by GitHub
parent d319fe14f0
commit a2f7e0636d
2 changed files with 21 additions and 0 deletions

View File

@@ -348,6 +348,13 @@ pub fn (t Time) str() string {
return t.format_ss()
}
// Time subtract using eperator overloading
pub fn (lhs Time) -(rhs Time) Duration {
lhs_micro := lhs.unix * 1000 * 1000 + u64(lhs.microsecond)
rhs_micro := rhs.unix * 1000 * 1000 + u64(rhs.microsecond)
return (i64(lhs_micro) - i64(rhs_micro)) * microsecond
}
fn convert_ctime(t C.tm, microsecond int) Time {
return Time{
year: t.tm_year + 1900