ok that was fun
parent
1639286189
commit
3c132528e3
|
|
@ -11,7 +11,6 @@ fn main() {
|
|||
#[derive(Debug)]
|
||||
struct Task(serde_yaml::Mapping);
|
||||
//pub todo: String,
|
||||
//pub when: Option<When>,
|
||||
//pub detail: Option<String>,
|
||||
//pub sub: Vec<Task>,
|
||||
|
||||
|
|
@ -27,8 +26,7 @@ impl Task {
|
|||
fn is_due_now(&self, now: TS) -> bool {
|
||||
match self.when() {
|
||||
Some(when) => {
|
||||
eprintln!("next: {}", when.next(self.ts()).to_string());
|
||||
now.unix() <= when.next(self.ts()).unix()
|
||||
now.unix() >= when.next(self.ts()).unix()
|
||||
},
|
||||
None => true,
|
||||
}
|
||||
|
|
@ -95,14 +93,42 @@ mod test_task {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn is_due() {
|
||||
fn is_due_duration() {
|
||||
let mut t = Task::new();
|
||||
assert!(t.is_due());
|
||||
t.set("ts".to_string(), "61".to_string());
|
||||
t.set("schedule".to_string(), "* * * * *".to_string());
|
||||
assert!(!t.is_due_now(TS::from_unix(119)));
|
||||
assert!(t.is_due_now(TS::from_unix(120)));
|
||||
assert!(t.is_due_now(TS::from_unix(121)));
|
||||
let then = TS::new("2000-01-02T15:00Z".to_string()).unwrap();
|
||||
let now = TS::new("2000-01-02T16:00Z".to_string()).unwrap();
|
||||
t.set("ts".to_string(), then.to_string());
|
||||
t.set("schedule".to_string(), "1h".to_string());
|
||||
assert!(!t.is_due_now(TS::from_unix(now.unix()-1)));
|
||||
assert!(t.is_due_now(TS::from_unix(now.unix())));
|
||||
assert!(t.is_due_now(TS::from_unix(now.unix()+1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_due_schedule() {
|
||||
let mut t = Task::new();
|
||||
assert!(t.is_due());
|
||||
let then = TS::new("2000-01-02T15:00Z".to_string()).unwrap();
|
||||
let now = TS::new("2000-01-02T16:00Z".to_string()).unwrap();
|
||||
t.set("ts".to_string(), then.to_string());
|
||||
t.set("schedule".to_string(), "2000-01-02T16:00Z".to_string());
|
||||
assert!(!t.is_due_now(TS::from_unix(now.unix()-1)));
|
||||
assert!(t.is_due_now(TS::from_unix(now.unix())));
|
||||
assert!(t.is_due_now(TS::from_unix(now.unix()+1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn is_due_cron() {
|
||||
let mut t = Task::new();
|
||||
assert!(t.is_due());
|
||||
let then = TS::new("2000-01-02T15:00Z".to_string()).unwrap();
|
||||
let now = TS::new("2000-01-02T16:00Z".to_string()).unwrap();
|
||||
t.set("ts".to_string(), then.to_string());
|
||||
t.set("schedule".to_string(), "0 16 * * *".to_string());
|
||||
assert!(!t.is_due_now(TS::from_unix(now.unix()-1)));
|
||||
assert!(t.is_due_now(TS::from_unix(now.unix())));
|
||||
assert!(t.is_due_now(TS::from_unix(now.unix()+1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue