From 3b295ccb8fd1f54474dc797db4578054936ab390 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Fri, 27 Dec 2019 11:29:57 -0500 Subject: [PATCH] Add doctest for comparison between timestamps with different time_zones --- CHANGELOG.md | 1 + src/datetime.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7035c8c..18191a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Versions with only mechanical changes will be omitted from the following list. * Support "negative UTC" in `parse_from_rfc2822` (@quodlibetor #368 reported in #102) +* Support comparisons of DateTimes with different timezones (@dlalic in #375) ### Internal improvements diff --git a/src/datetime.rs b/src/datetime.rs index 1e53753..ae2e1dc 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -576,6 +576,21 @@ impl Eq for DateTime { } impl PartialOrd> for DateTime { + /// Compare two DateTimes based on their true time, ignoring time zones + /// + /// # Example + /// + /// ``` + /// use chrono::prelude::*; + /// + /// let earlier = Utc.ymd(2015, 5, 15).and_hms(2, 0, 0).with_timezone(&FixedOffset::west(1 * 3600)); + /// let later = Utc.ymd(2015, 5, 15).and_hms(3, 0, 0).with_timezone(&FixedOffset::west(5 * 3600)); + /// + /// assert_eq!(earlier.to_string(), "2015-05-15 01:00:00 -01:00"); + /// assert_eq!(later.to_string(), "2015-05-14 22:00:00 -05:00"); + /// + /// assert!(later > earlier); + /// ``` fn partial_cmp(&self, other: &DateTime) -> Option { self.datetime.partial_cmp(&other.datetime) }