Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more integer types when creating Instants #272

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ pub struct Instant {

impl Instant {
/// Create a new `Instant` from a number of milliseconds.
pub fn from_millis(millis: i64) -> Instant {
Instant { millis }
pub fn from_millis<T: Into<i64>>(millis: T) -> Instant {
Instant { millis: millis.into() }
}

/// Create a new `Instant` from a number of seconds.
pub fn from_secs(secs: i64) -> Instant {
Instant { millis: secs * 1000 }
pub fn from_secs<T: Into<i64>>(secs: T) -> Instant {
Instant { millis: secs.into() * 1000 }
}

/// Create a new `Instant` from the current [std::time::SystemTime].
Expand Down Expand Up @@ -279,7 +279,7 @@ mod test {
assert_eq!(Instant::from(::std::time::UNIX_EPOCH),
Instant::from_millis(0));
assert_eq!(epoc, ::std::time::UNIX_EPOCH);
epoc = Instant::from_millis(2085955200 * 1000).into();
epoc = Instant::from_millis(2085955200i64 * 1000).into();
assert_eq!(epoc, ::std::time::UNIX_EPOCH + ::std::time::Duration::from_secs(2085955200));
}

Expand Down