Skip to content

Commit

Permalink
Make TimeZone::timestamp_millis_opt use
Browse files Browse the repository at this point in the history
NaiveDateTime::from_timestamp_millis to reduce code duplication
  • Loading branch information
Eden Mikitas authored and pitdicker committed Sep 13, 2023
1 parent 21f9ccc commit 86c257a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/offset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,10 @@ pub trait TimeZone: Sized + Clone {
/// };
/// ```
fn timestamp_millis_opt(&self, millis: i64) -> LocalResult<DateTime<Self>> {
let (mut secs, mut millis) = (millis / 1000, millis % 1000);
if millis < 0 {
secs -= 1;
millis += 1000;
match NaiveDateTime::from_timestamp_millis(millis) {
Some(dt) => LocalResult::Single(self.from_utc_datetime(&dt)),
None => LocalResult::None,
}
self.timestamp_opt(secs, millis as u32 * 1_000_000)
}

/// Makes a new `DateTime` from the number of non-leap nanoseconds
Expand Down

0 comments on commit 86c257a

Please sign in to comment.