Skip to content

Commit

Permalink
std/time: add the addSec method to Time
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Nov 25, 2024
1 parent 1e5dd18 commit 1010e91
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions std/time/time.jule
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ impl Time {
ret absSeconds(self.abs())
}

// Adds d seconds to the time.
fn addSec(mut self, d: i64) {
// Check if the sum of self.sec and d overflows and handle it properly.
sum := self.sec + d
if (sum > self.sec) == (d > 0) {
self.sec = sum
} else if d > 0 {
self.sec = 1<<63 - 1
} else {
self.sec = -(1<<63 - 1)
}
}

// Computes the time zone in effect at time specification, returning the abbreviated
// name of the zone (such as "CET") and its offset in seconds east of UTC.
fn Zone(self): (name: str, offset: int) {
Expand Down

0 comments on commit 1010e91

Please sign in to comment.