mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-30 22:42:08 +00:00
Improve documentation for subsec_nanos() and add a test for the method.
Co-authored-by: Micha White <botahamec@outlook.com>
This commit is contained in:
parent
2b7a28ebe9
commit
f0f807d1b5
@ -304,8 +304,10 @@ impl TimeDelta {
|
||||
if self.secs < 0 && self.nanos > 0 { self.secs + 1 } else { self.secs }
|
||||
}
|
||||
|
||||
/// Returns the number of nanoseconds such that
|
||||
/// `subsec_nanos() + num_seconds() * NANOS_PER_SEC` is the total number of
|
||||
/// Returns the number of nanoseconds in the fractional part of the duration.
|
||||
///
|
||||
/// This is the number of nanoseconds such that
|
||||
/// `subsec_nanos() + num_seconds() * 1_000_000_000` is the total number of
|
||||
/// nanoseconds in the `TimeDelta`.
|
||||
pub const fn subsec_nanos(&self) -> i32 {
|
||||
if self.secs < 0 && self.nanos > 0 { self.nanos - NANOS_PER_SEC } else { self.nanos }
|
||||
@ -768,6 +770,15 @@ mod tests {
|
||||
let _ = TimeDelta::seconds(-i64::MAX / 1_000 - 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duration_subsec_nanos() {
|
||||
assert_eq!(TimeDelta::zero().subsec_nanos(), 0);
|
||||
assert_eq!(TimeDelta::nanoseconds(1).subsec_nanos(), 1);
|
||||
assert_eq!(TimeDelta::nanoseconds(-1).subsec_nanos(), -1);
|
||||
assert_eq!(TimeDelta::seconds(1).subsec_nanos(), 0);
|
||||
assert_eq!(TimeDelta::nanoseconds(1_000_000_001).subsec_nanos(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duration_num_milliseconds() {
|
||||
assert_eq!(TimeDelta::zero().num_milliseconds(), 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user