MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / parse

Method parse

nodedb/src/event/scheduler/cron.rs:55–73  ·  view source on GitHub ↗

Parse a 5-field cron expression.

(expr: &str)

Source from the content-addressed store, hash-verified

53impl CronExpr {
54 /// Parse a 5-field cron expression.
55 pub fn parse(expr: &str) -> crate::Result<Self> {
56 let fields: Vec<&str> = expr.split_whitespace().collect();
57 if fields.len() != 5 {
58 return Err(crate::Error::BadRequest {
59 detail: format!(
60 "expected 5 fields (minute hour dom month dow), got {}",
61 fields.len()
62 ),
63 });
64 }
65
66 Ok(Self {
67 minutes: parse_field(fields[0], 0, 59)?,
68 hours: parse_field(fields[1], 0, 23)?,
69 days_of_month: parse_field(fields[2], 1, 31)?,
70 months: parse_field(fields[3], 1, 12)?,
71 days_of_week: parse_field(fields[4], 0, 6)?,
72 })
73 }
74
75 /// Check if the given wall-clock time matches this cron expression.
76 pub fn matches(&self, minute: u8, hour: u8, day: u8, month: u8, weekday: u8) -> bool {

Callers 2

parse_fieldFunction · 0.45
parse_rangeFunction · 0.45

Calls 3

parse_fieldFunction · 0.85
collectMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected