From 1010e910a8c8df55b9211ec0a8dcd4b5be3a93da Mon Sep 17 00:00:00 2001 From: mertcandav Date: Mon, 25 Nov 2024 16:19:47 +0300 Subject: [PATCH] std/time: add the addSec method to Time --- std/time/time.jule | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/std/time/time.jule b/std/time/time.jule index e270c714..c79739c2 100644 --- a/std/time/time.jule +++ b/std/time/time.jule @@ -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) {