Skip to content

Commit e55de65

Browse files
committed
0.11.2
1 parent defd824 commit e55de65

File tree

6 files changed

+46
-38
lines changed

6 files changed

+46
-38
lines changed

.justfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ update:
5454
audit:
5555
cargo audit
5656

57-
# Run example with a cron expression (usage: just run-example "*/5 * * * *")
58-
run-example cron:
57+
# Run example with a cron expression (usage: just run-example "*/5 * * * *" --count 10)
58+
run-example cron +args:
5959
@echo "Parsing cron expression: {{cron}}"
60-
@cargo run --example parse -- "{{cron}}"
60+
@cargo run --example parse -- "{{cron}}" {{args}}
6161

6262
# Run timezone example showing cron parsing across different timezones
6363
run-timezone-example:

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.11.2] - 2025-12-17
9+
10+
### Changed
11+
- Improved `examples/parse.rs` argument handling (`--help`, `--count`/`-n`) and usage output
12+
- Updated `just run-example` recipe to pass through extra CLI args (e.g., `--count 10`)
13+
- Refactored `examples/timezone.rs` to reduce repetition and show parse errors per timezone
14+
15+
### Fixed
16+
- Fixed `examples/patterns.rs` header underline (removed the accidental `PPPP...` line)
17+
818
## [0.11.1] - 2025-12-15
919

1020
### Fixed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cron-parser"
3-
version = "0.11.1"
3+
version = "0.11.2"
44
authors = ["Nicolas Embriz <[email protected]>"]
55
description = "Library for parsing cron expressions with timezone support."
66
documentation = "https://docs.rs/cron-parser/latest/cron_parser/"

examples/parse.rs

965 Bytes
Binary file not shown.

examples/patterns.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use chrono::Utc;
22
use cron_parser::parse;
33

44
fn main() {
5-
println!("Common Cron Expression Patterns");
6-
println!("PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP");
5+
let title = "Common Cron Expression Patterns";
6+
println!("{title}");
7+
println!("{}", "-".repeat(title.len()));
78
println!();
89

910
let now = Utc::now();

examples/timezone.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,51 @@ fn main() {
1717
println!();
1818

1919
println!("Next execution time in different timezones:");
20-
println!("");
20+
println!("--------------------------------------------------------");
2121

2222
// UTC
23-
if let Ok(next) = parse(cron_expr, &utc_now) {
24-
println!("UTC: {}", next.format("%Y-%m-%d %H:%M:%S %Z"));
25-
}
23+
print_next("UTC", cron_expr, &utc_now, false);
2624

2725
// Pacific
2826
let pacific_now = utc_now.with_timezone(&Pacific);
29-
if let Ok(next) = parse(cron_expr, &pacific_now) {
30-
println!("US/Pacific: {}", next.format("%Y-%m-%d %H:%M:%S %Z"));
31-
println!(
32-
" (UTC: {})",
33-
next.with_timezone(&Utc).format("%Y-%m-%d %H:%M:%S %Z")
34-
);
35-
}
27+
print_next("US/Pacific", cron_expr, &pacific_now, true);
3628

3729
// New York
3830
let ny_now = utc_now.with_timezone(&New_York);
39-
if let Ok(next) = parse(cron_expr, &ny_now) {
40-
println!("America/New_York: {}", next.format("%Y-%m-%d %H:%M:%S %Z"));
41-
println!(
42-
" (UTC: {})",
43-
next.with_timezone(&Utc).format("%Y-%m-%d %H:%M:%S %Z")
44-
);
45-
}
31+
print_next("America/New_York", cron_expr, &ny_now, true);
4632

4733
// London
4834
let london_now = utc_now.with_timezone(&London);
49-
if let Ok(next) = parse(cron_expr, &london_now) {
50-
println!("Europe/London: {}", next.format("%Y-%m-%d %H:%M:%S %Z"));
51-
println!(
52-
" (UTC: {})",
53-
next.with_timezone(&Utc).format("%Y-%m-%d %H:%M:%S %Z")
54-
);
55-
}
35+
print_next("Europe/London", cron_expr, &london_now, true);
5636

5737
// Tokyo
5838
let tokyo_now = utc_now.with_timezone(&Tokyo);
59-
if let Ok(next) = parse(cron_expr, &tokyo_now) {
60-
println!("Asia/Tokyo: {}", next.format("%Y-%m-%d %H:%M:%S %Z"));
61-
println!(
62-
" (UTC: {})",
63-
next.with_timezone(&Utc).format("%Y-%m-%d %H:%M:%S %Z")
64-
);
65-
}
39+
print_next("Asia/Tokyo", cron_expr, &tokyo_now, true);
6640

6741
println!();
6842
println!("Note: The same cron expression produces different absolute times");
6943
println!("depending on the timezone, but represents the same local time.");
7044
}
45+
46+
fn print_next<TZ: chrono::TimeZone>(
47+
label: &str,
48+
cron_expr: &str,
49+
now: &chrono::DateTime<TZ>,
50+
also_print_utc: bool,
51+
) where
52+
TZ::Offset: std::fmt::Display,
53+
{
54+
match parse(cron_expr, now) {
55+
Ok(next) => {
56+
println!("{label:<16} {}", next.format("%Y-%m-%d %H:%M:%S %Z"));
57+
if also_print_utc {
58+
println!(
59+
"{:16} (UTC: {})",
60+
"",
61+
next.with_timezone(&Utc).format("%Y-%m-%d %H:%M:%S %Z")
62+
);
63+
}
64+
}
65+
Err(e) => println!("{label:<16} Error: {e:?}"),
66+
}
67+
}

0 commit comments

Comments
 (0)