@@ -29,7 +29,7 @@ pub use self::internals::YearFlags as __BenchYearFlags;
2929
3030/// A week represented by a [`NaiveDate`] and a [`Weekday`] which is the first
3131/// day of the week.
32- #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
32+ #[ derive( Clone , Copy , Debug , Eq , Hash ) ]
3333pub struct NaiveWeek {
3434 date : NaiveDate ,
3535 start : Weekday ,
@@ -206,6 +206,12 @@ impl NaiveWeek {
206206 }
207207}
208208
209+ impl PartialEq for NaiveWeek {
210+ fn eq ( & self , other : & Self ) -> bool {
211+ self . first_day ( ) == other. first_day ( )
212+ }
213+ }
214+
209215/// A duration in calendar days.
210216///
211217/// This is useful because when using `TimeDelta` it is possible that adding `TimeDelta::days(1)`
@@ -235,7 +241,7 @@ pub mod serde {
235241
236242#[ cfg( test) ]
237243mod test {
238- use crate :: { NaiveDate , Weekday } ;
244+ use crate :: { NaiveDate , NaiveWeek , Weekday } ;
239245 #[ test]
240246 fn test_naiveweek ( ) {
241247 let date = NaiveDate :: from_ymd_opt ( 2022 , 5 , 18 ) . unwrap ( ) ;
@@ -278,4 +284,17 @@ mod test {
278284 let _ = date_min. week ( Weekday :: Mon ) . checked_days ( ) ;
279285 let _ = date_max. week ( Weekday :: Mon ) . checked_days ( ) ;
280286 }
287+
288+ #[ test]
289+ fn test_naiveweek_eq ( ) {
290+ let a =
291+ NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 3 ) . unwrap ( ) , start : Weekday :: Mon } ;
292+ let b =
293+ NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 4 ) . unwrap ( ) , start : Weekday :: Mon } ;
294+ assert_eq ! ( a, b) ;
295+ let c =
296+ NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 3 ) . unwrap ( ) , start : Weekday :: Sun } ;
297+ assert_ne ! ( a, c) ;
298+ assert_ne ! ( b, c) ;
299+ }
281300}
0 commit comments