@@ -29,7 +29,7 @@ pub use self::internals::YearFlags as __BenchYearFlags;
29
29
30
30
/// A week represented by a [`NaiveDate`] and a [`Weekday`] which is the first
31
31
/// day of the week.
32
- #[ derive( Clone , Copy , Debug , Eq , Hash , PartialEq ) ]
32
+ #[ derive( Clone , Copy , Debug , Eq , Hash ) ]
33
33
pub struct NaiveWeek {
34
34
date : NaiveDate ,
35
35
start : Weekday ,
@@ -206,6 +206,12 @@ impl NaiveWeek {
206
206
}
207
207
}
208
208
209
+ impl PartialEq for NaiveWeek {
210
+ fn eq ( & self , other : & Self ) -> bool {
211
+ self . first_day ( ) == other. first_day ( )
212
+ }
213
+ }
214
+
209
215
/// A duration in calendar days.
210
216
///
211
217
/// This is useful because when using `TimeDelta` it is possible that adding `TimeDelta::days(1)`
@@ -235,7 +241,7 @@ pub mod serde {
235
241
236
242
#[ cfg( test) ]
237
243
mod test {
238
- use crate :: { NaiveDate , Weekday } ;
244
+ use crate :: { NaiveDate , NaiveWeek , Weekday } ;
239
245
#[ test]
240
246
fn test_naiveweek ( ) {
241
247
let date = NaiveDate :: from_ymd_opt ( 2022 , 5 , 18 ) . unwrap ( ) ;
@@ -278,4 +284,14 @@ mod test {
278
284
let _ = date_min. week ( Weekday :: Mon ) . checked_days ( ) ;
279
285
let _ = date_max. week ( Weekday :: Mon ) . checked_days ( ) ;
280
286
}
287
+
288
+ #[ test]
289
+ fn test_naiveweek_eq ( ) {
290
+ let a = NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 3 ) . unwrap ( ) , start : Weekday :: Mon } ;
291
+ let b = NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 4 ) . unwrap ( ) , start : Weekday :: Mon } ;
292
+ assert_eq ! ( a, b) ;
293
+ let c = NaiveWeek { date : NaiveDate :: from_ymd_opt ( 2025 , 4 , 3 ) . unwrap ( ) , start : Weekday :: Sun } ;
294
+ assert_ne ! ( a, c) ;
295
+ assert_ne ! ( b, c) ;
296
+ }
281
297
}
0 commit comments