Skip to content

Commit 0add471

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 163434 b: refs/heads/snap-stage3 c: b5537fa h: refs/heads/master v: v3
1 parent 053f8d0 commit 0add471

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 9126a24e423a8339230f1dde7e36f79faaeaa9d3
4+
refs/heads/snap-stage3: b5537fa838112192f0ed1f1593c574fe621497a6
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libtime/lib.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ impl Timespec {
9999
}
100100
}
101101

102+
// NOTE(stage0): Remove impl after a snapshot
103+
#[cfg(stage0)]
102104
impl Add<Duration, Timespec> for Timespec {
103105
fn add(&self, other: &Duration) -> Timespec {
104106
let d_sec = other.num_seconds();
@@ -119,6 +121,29 @@ impl Add<Duration, Timespec> for Timespec {
119121
}
120122
}
121123

124+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
125+
impl Add<Duration, Timespec> for Timespec {
126+
fn add(self, other: Duration) -> Timespec {
127+
let d_sec = other.num_seconds();
128+
// It is safe to unwrap the nanoseconds, because there cannot be
129+
// more than one second left, which fits in i64 and in i32.
130+
let d_nsec = (other - Duration::seconds(d_sec))
131+
.num_nanoseconds().unwrap() as i32;
132+
let mut sec = self.sec + d_sec;
133+
let mut nsec = self.nsec + d_nsec;
134+
if nsec >= NSEC_PER_SEC {
135+
nsec -= NSEC_PER_SEC;
136+
sec += 1;
137+
} else if nsec < 0 {
138+
nsec += NSEC_PER_SEC;
139+
sec -= 1;
140+
}
141+
Timespec::new(sec, nsec)
142+
}
143+
}
144+
145+
// NOTE(stage0): Remove impl after a snapshot
146+
#[cfg(stage0)]
122147
impl Sub<Timespec, Duration> for Timespec {
123148
fn sub(&self, other: &Timespec) -> Duration {
124149
let sec = self.sec - other.sec;
@@ -127,6 +152,15 @@ impl Sub<Timespec, Duration> for Timespec {
127152
}
128153
}
129154

155+
#[cfg(not(stage0))] // NOTE(stage0): Remove cfg after a snapshot
156+
impl Sub<Timespec, Duration> for Timespec {
157+
fn sub(self, other: Timespec) -> Duration {
158+
let sec = self.sec - other.sec;
159+
let nsec = self.nsec - other.nsec;
160+
Duration::seconds(sec) + Duration::nanoseconds(nsec as i64)
161+
}
162+
}
163+
130164
/// Returns the current time as a `timespec` containing the seconds and
131165
/// nanoseconds since 1970-01-01T00:00:00Z.
132166
pub fn get_time() -> Timespec {

0 commit comments

Comments
 (0)