Skip to content

Commit

Permalink
add Time::with_time_base
Browse files Browse the repository at this point in the history
  • Loading branch information
gerwin3 committed Aug 8, 2023
1 parent 4ca51be commit b7d8f14
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ impl Time {
Self { time, time_base }
}

/// Align the timestamp with a different time base.
///
/// # Arguments
///
/// # Return value
///
/// The same timestamp, with the time base changed.
#[inline]
pub fn with_time_base(&self, time_base: AvRational) -> Self {
self.aligned_with_rational(time_base)
}

/// Creates a new timestamp that reprsents `nth` of a second.
///
/// # Arguments
Expand Down Expand Up @@ -255,6 +267,15 @@ mod tests {
assert_eq!(time.into_value(), Some(2));
}

#[test]
fn test_with_time_base() {
let time = Time::new(Some(2), AvRational::new(3, 9));
assert_eq!(time.as_secs(), 2.0 / 3.0);
let time = time.with_time_base(AvRational::new(1, 9));
assert_eq!(time.as_secs(), 2.0 / 3.0);
assert_eq!(time.into_value(), Some(6));
}

#[test]
fn test_from_nth_of_a_second() {
let time = Time::from_nth_of_a_second(4);
Expand Down

0 comments on commit b7d8f14

Please sign in to comment.