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 15, 2023
1 parent 3c4846a commit 861d4e1
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 @@ -415,12 +415,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 861d4e1

Please sign in to comment.