Skip to content

Commit

Permalink
std/time: add the Second method to Time
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Nov 21, 2024
1 parent 4dac5b3 commit c215038
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions std/time/time.jule
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ impl Time {
ret int(self.abs()%secPerDay) / secPerHour
}

// Returns the second offset within the minute specified by the time, in the range [0, 59].
fn Second(self): int {
ret int(self.abs() % secPerMinute)
}

// Returns the minute offset within the hour specified by the time, in the range [0, 59].
fn Minute(self): int {
ret int(self.abs()%secPerHour) / secPerMinute
Expand Down
12 changes: 12 additions & 0 deletions std/time/time_test.jule
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ fn testTimeMinute(t: &testing::T) {
}
}

#test
fn testTimeSecond(t: &testing::T) {
for i, test in unixAbsTests {
time := Unix(test.sec, 0)
second := time.Second()
if second != test.abs.Second {
t.Errorf("#{} conversion failed", i)
continue
}
}
}

#test
fn testUnix(t: &testing::T) {
for i, test in unixAbsTests {
Expand Down

0 comments on commit c215038

Please sign in to comment.