Skip to content

Commit 71db71b

Browse files
committed
Add iter_from and iter_after. Documentation.
1 parent 020673b commit 71db71b

File tree

8 files changed

+265
-73
lines changed

8 files changed

+265
-73
lines changed

examples/iter_demo.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use chrono::Local;
2+
use croner::Cron;
3+
4+
fn main() {
5+
// Parse cron expression
6+
let cron: Cron = "* * * * * *".parse().expect("Couldn't parse cron string");
7+
8+
// Compare to time now
9+
let time = Local::now();
10+
11+
// Get next 5 matches using iter_from
12+
// There is also iter_after, which does not match starting time
13+
println!("Finding matches of pattern '{}' starting from {}:", cron.pattern.to_string(), time);
14+
15+
for time in cron.clone().iter_from(time).take(5) {
16+
println!("{}", time);
17+
}
18+
}

examples/pattern_demo.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/scheduler_demo.rs

Lines changed: 0 additions & 50 deletions
This file was deleted.

examples/simple_demo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
let matches_all = cron_all.is_time_matching(&time).unwrap();
1111

1212
// Get next match
13-
let next = cron_all.find_next_occurrence(&time).unwrap();
13+
let next = cron_all.find_next_occurrence(&time, false).unwrap();
1414

1515
// Output results
1616
println!("Time is: {}", time);

examples/timezone_demo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111

1212
// Find the next occurrence in EST
1313
let time_est = Local::now().with_timezone(&est_timezone);
14-
let next_est = cron.find_next_occurrence(&time_est).unwrap();
14+
let next_est = cron.find_next_occurrence(&time_est, false).unwrap();
1515

1616
// Output results for EST
1717
println!("EST time is: {}", time_est);

src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub const NTH_ALL: u8 = NTH_1ST_BIT | NTH_2ND_BIT | NTH_3RD_BIT | NTH_4TH_BIT |
1515
// Used for last day of month
1616
pub const LAST_BIT: u8 = 1 << 6;
1717

18-
#[derive(Debug, Default)]
18+
#[derive(Debug, Default, Clone)]
1919
pub struct CronComponent {
2020
bitfields: Vec<u8>, // Vector of u8 to act as multiple bitfields
2121
pub min: u8, // Minimum value this component can take

0 commit comments

Comments
 (0)