MCPcopy Create free account
hub / github.com/cloudflare/saffron / dow_expr

Function dow_expr

saffron/src/parse.rs:927–1011  ·  view source on GitHub ↗
(input: &str)

Source from the content-addressed store, hash-verified

925}
926
927fn dow_expr(input: &str) -> IResult<&str, DayOfWeekExpr> {
928 fn dow(s: &str) -> IResult<&str, DayOfWeek> {
929 alt((
930 map_digit1::<DayOfWeek>(),
931 map(tag_no_case("SUN"), |_| DayOfWeek(chrono::Weekday::Sun)),
932 map(tag_no_case("MON"), |_| DayOfWeek(chrono::Weekday::Mon)),
933 map(tag_no_case("TUE"), |_| DayOfWeek(chrono::Weekday::Tue)),
934 map(tag_no_case("WED"), |_| DayOfWeek(chrono::Weekday::Wed)),
935 map(tag_no_case("THU"), |_| DayOfWeek(chrono::Weekday::Thu)),
936 map(tag_no_case("FRI"), |_| DayOfWeek(chrono::Weekday::Fri)),
937 map(tag_no_case("SAT"), |_| DayOfWeek(chrono::Weekday::Sat)),
938 ))(s)
939 }
940
941 let (input, start) = opt(alt((char('*'), char('L'))))(input)?;
942
943 match start {
944 Some('*') => {
945 let (input, maybe_step) = opt(tuple((char('/'), step_digit::<DayOfWeek>())))(input)?;
946 if let Some((_, step)) = maybe_step {
947 let exprs = Exprs::new(OrsExpr::Step {
948 start: DayOfWeek(chrono::Weekday::Sun),
949 end: ExprValue::max(),
950 step,
951 });
952
953 let (input, exprs) = tail_ors_exprs(input, dow, exprs)?;
954 Ok((input, DayOfWeekExpr::Many(exprs)))
955 } else {
956 Ok((input, DayOfWeekExpr::All))
957 }
958 }
959 Some('L') => Ok((
960 input,
961 DayOfWeekExpr::Many(Exprs::new(OrsExpr::One(DayOfWeek(chrono::Weekday::Sat)))),
962 )),
963 _ => {
964 let (input, day) = dow(input)?;
965 let (input, maybe_char) =
966 opt(alt((char('L'), char('#'), char('-'), char('/'))))(input)?;
967
968 match maybe_char {
969 Some('L') => Ok((input, DayOfWeekExpr::Last(day))),
970 Some('#') => map(map_digit1::<NthDay>(), move |nth| {
971 DayOfWeekExpr::Nth(day, nth)
972 })(input),
973 Some('-') => {
974 let (input, (end, slash)) = tuple((&dow, opt(char('/'))))(input)?;
975
976 let (input, exprs) = if slash.is_none() {
977 (input, Exprs::new(OrsExpr::Range(day, end)))
978 } else {
979 let (input, step) = step_digit::<DayOfWeek>()(input)?;
980 (
981 input,
982 Exprs::new(OrsExpr::Step {
983 start: day,
984 end,

Callers

nothing calls this directly

Calls 4

DayOfWeekClass · 0.85
tail_ors_exprsFunction · 0.85
dowFunction · 0.85
LastEnum · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…