Skip to content

Commit

Permalink
Remaining fn in Timer (bevyengine#5971)
Browse files Browse the repository at this point in the history
# Objective

Fixes bevyengine#5963 

## Solution

Add remaining fn in Timer class, this function only minus total duration with elapsed time.

Co-authored-by: Sergi-Ferrez <[email protected]>
  • Loading branch information
2 people authored and james7132 committed Oct 19, 2022
1 parent a6b540f commit a779fcf
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions crates/bevy_time/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,38 @@ impl Timer {
1.0 - self.percent()
}

/// Returns the remaining time in seconds
///
/// # Examples
/// ```
/// # use bevy_time::*;
/// use std::cmp::Ordering;
/// use std::time::Duration;
/// let mut timer = Timer::from_seconds(2.0, false);
/// timer.tick(Duration::from_secs_f32(0.5));
/// let result = timer.remaining_secs().total_cmp(&1.5);
/// assert_eq!(Ordering::Equal, result);
/// ```
#[inline]
pub fn remaining_secs(&self) -> f32 {
self.remaining().as_secs_f32()
}

/// Returns the remaining time using Duration
///
/// # Examples
/// ```
/// # use bevy_time::*;
/// use std::time::Duration;
/// let mut timer = Timer::from_seconds(2.0, false);
/// timer.tick(Duration::from_secs_f32(0.5));
/// assert_eq!(timer.remaining(), Duration::from_secs_f32(1.5));
/// ```
#[inline]
pub fn remaining(&self) -> Duration {
self.duration() - self.elapsed()
}

/// Returns the number of times a repeating timer
/// finished during the last [`tick`](Timer<T>::tick) call.
///
Expand Down

0 comments on commit a779fcf

Please sign in to comment.