From 861d4e12487181e71744478a320db20f56bd61af Mon Sep 17 00:00:00 2001 From: Eden Mikitas Date: Tue, 12 Sep 2023 20:47:50 +0300 Subject: [PATCH] Make TimeZone::timestamp_millis_opt use NaiveDateTime::from_timestamp_millis to reduce code duplication --- src/offset/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/offset/mod.rs b/src/offset/mod.rs index 7f5857b234..df688b22bb 100644 --- a/src/offset/mod.rs +++ b/src/offset/mod.rs @@ -415,12 +415,10 @@ pub trait TimeZone: Sized + Clone { /// }; /// ``` fn timestamp_millis_opt(&self, millis: i64) -> LocalResult> { - 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