Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
byrnedo committed Jul 20, 2024
1 parent 763fe59 commit 3fbafb7
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/cron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,25 @@ pub(crate) fn cron_to_systemd(cron_expr: &str, time_zone: &str) -> Result<String
let timer_format = format!(
//DOW Y-M-D H:M:S TZ
"{} *-{}-{} {}:{}:00 {}",
linearize_time_unit(schedule.days_of_week(), "", ToString::to_string),
linearize_time_unit(schedule.months(), "*", ToString::to_string),
linearize_time_unit(schedule.days_of_month(), "*", ToString::to_string),
linearize_time_unit(schedule.hours(), "*", ToString::to_string),
linearize_time_unit(schedule.minutes(), "*", ToString::to_string),
linearize_time_unit(schedule.days_of_week(), ""),
linearize_time_unit(schedule.months(), "*"),
linearize_time_unit(schedule.days_of_month(), "*"),
linearize_time_unit(schedule.hours(), "*"),
linearize_time_unit(schedule.minutes(), "*"),
time_zone,
);

return Ok(timer_format.trim().to_string());
}

fn linearize_time_unit<C>(input: &(impl TimeUnitSpec + Sized), star: &str, conv: C) -> String
where
C: Fn(&u32) -> String,
fn linearize_time_unit(input: &(impl TimeUnitSpec + Sized), star: &str) -> String
{
if input.is_all() {
star.to_owned()
} else {
let mut output = String::new();
for part in input.iter() {
output.push_str(&*conv(&part));
output.push_str(&part.to_string());
output.push(',');
}
output.pop();
Expand Down

0 comments on commit 3fbafb7

Please sign in to comment.