We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents d59d97c + 0b4912b commit c95aa99Copy full SHA for c95aa99
src/libtime/lib.rs
@@ -103,6 +103,9 @@ impl Add<Duration, Timespec> for Timespec {
103
if nsec >= NSEC_PER_SEC {
104
nsec -= NSEC_PER_SEC;
105
sec += 1;
106
+ } else if nsec < 0 {
107
+ nsec += NSEC_PER_SEC;
108
+ sec -= 1;
109
}
110
Timespec::new(sec, nsec)
111
@@ -1533,6 +1536,12 @@ mod tests {
1533
1536
let w = u + v;
1534
1537
assert_eq!(w.sec, 4);
1535
1538
assert_eq!(w.nsec, 1);
1539
+
1540
+ let k = Timespec::new(1, 0);
1541
+ let l = Duration::nanoseconds(-1);
1542
+ let m = k + l;
1543
+ assert_eq!(m.sec, 0);
1544
+ assert_eq!(m.nsec, 999_999_999);
1545
1546
1547
fn test_timespec_sub() {
0 commit comments