From bd8db4ba5b43df59362f88e5349a55b9630cfaeb Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Fri, 12 Dec 2025 09:23:02 +0900 Subject: [PATCH] refactor: Replace handwritten `Ord` and `PartialOrd` for `DateTime` Use the derive macro to implement these. --- src/types.rs | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/types.rs b/src/types.rs index 1115fea82..d1b023e86 100644 --- a/src/types.rs +++ b/src/types.rs @@ -2,7 +2,6 @@ use crate::cp437::FromCp437; use crate::write::{FileOptionExtension, FileOptions}; use path::{Component, Path, PathBuf}; -use std::cmp::Ordering; use std::ffi::OsStr; use std::fmt; use std::fmt::{Debug, Formatter}; @@ -85,7 +84,7 @@ impl From for u8 { /// /// Modern zip files store more precise timestamps; see [`crate::extra_fields::ExtendedTimestamp`] /// for details. -#[derive(Clone, Copy, Eq, Hash, PartialEq)] +#[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct DateTime { datepart: u16, timepart: u16, @@ -108,33 +107,6 @@ impl Debug for DateTime { } } -impl Ord for DateTime { - fn cmp(&self, other: &Self) -> Ordering { - if let ord @ (Ordering::Less | Ordering::Greater) = self.year().cmp(&other.year()) { - return ord; - } - if let ord @ (Ordering::Less | Ordering::Greater) = self.month().cmp(&other.month()) { - return ord; - } - if let ord @ (Ordering::Less | Ordering::Greater) = self.day().cmp(&other.day()) { - return ord; - } - if let ord @ (Ordering::Less | Ordering::Greater) = self.hour().cmp(&other.hour()) { - return ord; - } - if let ord @ (Ordering::Less | Ordering::Greater) = self.minute().cmp(&other.minute()) { - return ord; - } - self.second().cmp(&other.second()) - } -} - -impl PartialOrd for DateTime { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - impl DateTime { /// Constructs a default datetime of 1980-01-01 00:00:00. pub const DEFAULT: Self = DateTime {