Skip to content

Commit

Permalink
std/time: add the Compare method to Time
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Nov 28, 2024
1 parent 401cf47 commit def785c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion std/time/time.jule
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,23 @@ impl Time {

// Reports whether the time instant is before u.
fn Before(self, u: Time): bool {
ret self.sec < u.sec || self.sec == s.sec && self.nsec < u.nsec
ret self.sec < u.sec || self.sec == u.sec && self.nsec < u.nsec
}

// Compares the time instant t(self) with u. If t is before u, it returns -1;
// if t is after u, it returns +1; if they're the same, it returns 0.
fn Compare(self, u: Time): int {
mut tc, mut uc := self.sec, u.sec
if tc == uc {
tc, uc = i64(self.nsec), i64(u.nsec)
}
match {
| tc < uc:
ret -1
| tc > uc:
ret +1
}
ret 0
}

fn appendTo(self, mut b: []byte)!: []byte {
Expand Down

0 comments on commit def785c

Please sign in to comment.