diff --git a/Cargo.lock b/Cargo.lock index d997942..1e04f10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2177,6 +2177,7 @@ dependencies = [ "chrono", "chrono-tz", "clap", + "iana-time-zone", "runway-caldav", "runway-core", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 65e6c2d..467ab42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,6 +60,7 @@ leptos_router = "0.8" # CLI clap = { version = "4", features = ["derive", "env"] } +iana-time-zone = "0.1" # Dev pretty_assertions = "1" diff --git a/crates/runway-cli/Cargo.toml b/crates/runway-cli/Cargo.toml index 485f913..bbe9b8f 100644 --- a/crates/runway-cli/Cargo.toml +++ b/crates/runway-cli/Cargo.toml @@ -11,6 +11,7 @@ runway-caldav = { workspace = true } chrono = { workspace = true } chrono-tz = { workspace = true } clap = { workspace = true } +iana-time-zone = { workspace = true } tokio = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true } diff --git a/crates/runway-cli/src/main.rs b/crates/runway-cli/src/main.rs index 9033b3c..bf5ab95 100644 --- a/crates/runway-cli/src/main.rs +++ b/crates/runway-cli/src/main.rs @@ -33,13 +33,28 @@ struct Cli { password: String, /// The zone to show times in, and to read floating times as. - #[arg(long, default_value = "America/Denver")] + /// + /// Defaults to whatever the machine is set to. Baking in a zone would be + /// the same mistake in miniature that this project exists to correct: the + /// right zone is a property of the reader, and readers move. + #[arg(long, default_value_t = local_timezone())] timezone: Tz, #[command(subcommand)] command: Command, } +/// The system's own IANA zone, falling back to UTC when it cannot be read. +/// +/// UTC rather than a guess at somewhere populated: a wrong zone that looks +/// plausible is worse than an obviously neutral one, because nobody checks it. +fn local_timezone() -> Tz { + iana_time_zone::get_timezone() + .ok() + .and_then(|name| name.parse().ok()) + .unwrap_or(Tz::UTC) +} + #[derive(Subcommand)] enum Command { /// List the calendars the server offers.