Skip to content

Commit e40dae0

Browse files
committed
add is_subset and is_superset
1 parent 5e0bb2d commit e40dae0

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/weekdays.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,32 @@ impl Weekdays {
228228
Self(self.0 & !other.0)
229229
}
230230

231+
/// Returns `true` if `other` contains all days in `self`.
232+
///
233+
/// # Example
234+
/// ```
235+
/// # use chrono::Weekdays;
236+
/// assert!(Weekdays::MON.is_subset(Weekdays::ALL));
237+
/// assert!(!Weekdays::MON.is_subset(Weekdays::EMPTY));
238+
/// assert!(Weekdays::EMPTY.is_subset(Weekdays::MON));
239+
/// ```
240+
pub const fn is_subset(self, other: Self) -> bool {
241+
self.intersection(other).0 == self.0
242+
}
243+
244+
/// Returns `true` if `self` contains all days in `other`.
245+
///
246+
/// # Example
247+
/// ```
248+
/// # use chrono::Weekdays;
249+
/// assert!(Weekdays::ALL.is_superset(Weekdays::MON));
250+
/// assert!(Weekdays::MON.is_superset(Weekdays::EMPTY));
251+
/// assert!(!Weekdays::MON.is_superset(Weekdays::TUE));
252+
/// ```
253+
pub const fn is_superset(self, other: Self) -> bool {
254+
self.intersection(other).0 == other.0
255+
}
256+
231257
/// Adds a day to the collection.
232258
///
233259
/// Returns `true` if the day was new to the collection.

0 commit comments

Comments
 (0)