Skip to content

Commit 18f75a9

Browse files
committed
std: Add comments to the time module
1 parent dc8b23b commit 18f75a9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/libstd/time.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ macro_rules! earlyexit(
2929
($e:expr) => (match $e { Some(v) => v, None => return None })
3030
)
3131

32-
/// ISO 8601 duration
32+
/// The representation of a span of time.
33+
///
34+
/// This type has nanosecond precision, and conforms to the ISO 8601
35+
/// standard for Date interchange.
3336
#[deriving(PartialEq, Eq, PartialOrd, Ord)]
3437
pub struct Duration {
3538
days: i32,
@@ -38,6 +41,7 @@ pub struct Duration {
3841
}
3942

4043
impl Duration {
44+
/// Create a new `Duration`.
4145
pub fn new(days: i32, secs: i32, nanos: i32) -> Option<Duration> {
4246
let (secs_, nanos) = div_mod_floor(nanos, NANOS_PER_SEC);
4347
let secs = earlyexit!(secs.checked_add(&secs_));
@@ -46,67 +50,78 @@ impl Duration {
4650
Some(Duration { days: days, secs: secs as u32, nanos: nanos as u32 })
4751
}
4852

53+
/// Create a new `Duration` from an integer number of weeks.
4954
#[inline]
5055
pub fn weeks(weeks: i32) -> Duration {
5156
Duration::days(weeks * 7)
5257
}
5358

59+
/// Create a new `Duration` from an integer number of days.
5460
#[inline]
5561
pub fn days(days: i32) -> Duration {
5662
let days = days.to_i32().expect("Duration::days out of bounds");
5763
Duration { days: days, secs: 0, nanos: 0 }
5864
}
5965

66+
/// Create a new `Duration` from an integer number of hours.
6067
#[inline]
6168
pub fn hours(hours: i32) -> Duration {
6269
let (days, hours) = div_mod_floor(hours, (SECS_PER_DAY / 3600));
6370
let secs = hours * 3600;
6471
Duration { secs: secs as u32, ..Duration::days(days) }
6572
}
6673

74+
/// Create a new `Duration` from an integer number of minutes.
6775
#[inline]
6876
pub fn minutes(mins: i32) -> Duration {
6977
let (days, mins) = div_mod_floor(mins, (SECS_PER_DAY / 60));
7078
let secs = mins * 60;
7179
Duration { secs: secs as u32, ..Duration::days(days) }
7280
}
7381

82+
/// Create a new `Duration` from an integer number of seconds.
7483
#[inline]
7584
pub fn seconds(secs: i32) -> Duration {
7685
let (days, secs) = div_mod_floor(secs, SECS_PER_DAY);
7786
Duration { secs: secs as u32, ..Duration::days(days) }
7887
}
7988

89+
/// Create a new `Duration` from an integer number of milliseconds.
8090
#[inline]
8191
pub fn milliseconds(millis: i32) -> Duration {
8292
let (secs, millis) = div_mod_floor(millis, (NANOS_PER_SEC / 1_000_000));
8393
let nanos = millis * 1_000_000;
8494
Duration { nanos: nanos as u32, ..Duration::seconds(secs) }
8595
}
8696

97+
/// Create a new `Duration` from an integer number of microseconds.
8798
#[inline]
8899
pub fn microseconds(micros: i32) -> Duration {
89100
let (secs, micros) = div_mod_floor(micros, (NANOS_PER_SEC / 1_000));
90101
let nanos = micros * 1_000;
91102
Duration { nanos: nanos as u32, ..Duration::seconds(secs) }
92103
}
93104

105+
/// Create a new `Duration` from an integer number of nanoseconds.
94106
#[inline]
95107
pub fn nanoseconds(nanos: i32) -> Duration {
96108
let (secs, nanos) = div_mod_floor(nanos, NANOS_PER_SEC);
97109
Duration { nanos: nanos as u32, ..Duration::seconds(secs) }
98110
}
99111

112+
/// Return the number of whole days in the `Duration`.
100113
#[inline]
101114
pub fn ndays(&self) -> i32 {
102115
self.days as i32
103116
}
104117

118+
/// Return the fractional number of days in the `Duration` as seconds.
105119
#[inline]
106120
pub fn nseconds(&self) -> u32 {
107121
self.secs as u32
108122
}
109123

124+
/// Return the fractional number of seconds in the `Duration` as nanoseconds.
110125
#[inline]
111126
pub fn nnanoseconds(&self) -> u32 {
112127
self.nanos as u32

0 commit comments

Comments
 (0)