use crate::{
ClassifiedDate, DateClassification, Dt, Lang, Token, classify_date,
generate_unambiguous_candidates, try_compatible_formats,
};
use alloc::string::ToString;
#[inline]
pub(crate) fn is_week_date_missing_weekday(cls: &DateClassification) -> bool {
cls.has_w && matches!(cls.date_tokens.first(), Some(Token::Digits(n)) if *n >= 4)
}
pub(crate) fn parse_week_date_no_weekday(
orig_class: &DateClassification,
lang: Lang,
ref_time: &Option<Dt>,
) -> Option<Dt> {
let date = &orig_class.date;
let w_pos = match date.find("-W") {
Some(pos) => pos + 1, None => date.find('W')?,
};
let mut week_end = w_pos + 1;
while week_end < date.len() && date.as_bytes()[week_end].is_ascii_digit() {
week_end += 1;
}
let mut new_date = date.to_string();
let after = &new_date[week_end..];
if after.is_empty() || after.starts_with([' ', 'T', '-', '.', '/', ',']) {
new_date.insert_str(week_end, "-1");
} else {
return None;
}
let classification = classify_date(&new_date.to_ascii_lowercase(), lang, ref_time).ok()?;
match classification {
ClassifiedDate::Cls(cls) => {
try_compatible_formats(&cls.date, generate_unambiguous_candidates(&cls))
}
_ => None,
}
}