use std::time::{Duration, SystemTime};
mod cron;
pub use cron::CronSchedule;
pub trait Schedule {
fn next_call_at(&self, last_run_at: Option<SystemTime>) -> Option<SystemTime>;
}
pub struct DeltaSchedule {
interval: Duration,
}
impl DeltaSchedule {
pub fn new(interval: Duration) -> DeltaSchedule {
DeltaSchedule { interval }
}
}
impl Schedule for DeltaSchedule {
fn next_call_at(&self, last_run_at: Option<SystemTime>) -> Option<SystemTime> {
match last_run_at {
Some(last_run_at) => Some(
last_run_at
.checked_add(self.interval)
.expect("Invalid SystemTime encountered"),
),
None => Some(SystemTime::now()),
}
}
}