According to the current Display implementation and its doc test:
assert_eq!(format!("{}", NWeekday::Every(Weekday::Mon)), "MO");
assert_eq!(format!("{}", NWeekday::Nth(1, Weekday::Mon)), "MO");
assert_eq!(format!("{}", NWeekday::Nth(2, Weekday::Mon)), "2MO");
|
impl Display for NWeekday { |
|
/// Returns a string representation of the [`NWeekday`] |
|
/// |
|
/// ``` |
|
/// use chrono::Weekday; |
|
/// use rrule::NWeekday; |
|
/// |
|
/// assert_eq!(format!("{}", NWeekday::Every(Weekday::Mon)), "MO"); |
|
/// assert_eq!(format!("{}", NWeekday::Nth(1, Weekday::Mon)), "MO"); |
|
/// assert_eq!(format!("{}", NWeekday::Nth(2, Weekday::Mon)), "2MO"); |
|
/// ``` |
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
|
let weekday = match self { |
|
Self::Every(wd) => weekday_to_str(*wd), |
|
Self::Nth(number, wd) => { |
|
let mut wd_str = weekday_to_str(*wd); |
|
if *number != 1 { |
|
wd_str = format!("{}{}", number, wd_str); |
|
}; |
|
wd_str |
|
} |
|
}; |
|
|
|
write!(f, "{}", weekday) |
|
} |
|
} |
Every(Mon) and Nth(1, Mon) both serialize to MO.
However, MO and 1MO are not equivalent. MO matches every Monday, while 1MO matches only the first Monday selected by the recurrence rule.
As a result, Nth(1, ...) cannot be represented correctly.
The implementation should always include the ordinal for Nth, including 1. The doc test should likewise expect:
assert_eq!(format!("{}", NWeekday::Nth(1, Weekday::Mon)), "1MO");
According to the current
Displayimplementation and its doc test:rust-rrule/rrule/src/core/rrule.rs
Lines 174 to 199 in 1c3420e
Every(Mon)andNth(1, Mon)both serialize toMO.However,
MOand1MOare not equivalent.MOmatches every Monday, while1MOmatches only the first Monday selected by the recurrence rule.As a result, Nth(1, ...) cannot be represented correctly.
The implementation should always include the ordinal for
Nth, including1. The doc test should likewise expect: