From a05e8088f30b70ad1fa51f914fecbd8789d3c2d1 Mon Sep 17 00:00:00 2001 From: Simon Gurcke Date: Thu, 16 Apr 2026 11:20:41 +1000 Subject: [PATCH 1/2] Set default timezone in metrics command based on system settings --- Cargo.lock | 1 + Cargo.toml | 1 + skills/apitally-cli/references/commands.md | 2 +- src/main.rs | 2 +- src/metrics.rs | 8 +++++--- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41417a5..8e67798 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,6 +117,7 @@ dependencies = [ "clap", "dirs", "duckdb", + "iana-time-zone", "mockito", "open", "regex", diff --git a/Cargo.toml b/Cargo.toml index cc67620..7cb59cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ arrow-ipc = { version = "=58.1.0", features = ["lz4"] } clap = { version = "4", features = ["derive", "env"] } dirs = "6" duckdb = { version = "=1.10501.0", features = ["bundled", "appender-arrow"] } +iana-time-zone = "0.1" open = "5" regex = "1" serde = { version = "1", features = ["derive"] } diff --git a/skills/apitally-cli/references/commands.md b/skills/apitally-cli/references/commands.md index 359c8be..c9ccdca 100644 --- a/skills/apitally-cli/references/commands.md +++ b/skills/apitally-cli/references/commands.md @@ -99,7 +99,7 @@ Fetch aggregated metrics for an app. Outputs NDJSON to stdout by default. - `--interval`: Time interval for grouping (`month`, `day`, `hour`, `minute`). When omitted, returns a single row per group for the entire time range - `--group-by`: JSON array of field names to group by, in addition to time period - `--filters`: JSON array of filter objects (see below) -- `--timezone`: Timezone for intervals and to interpret since/until if not tz-aware (defaults to UTC) +- `--timezone`: Timezone for intervals and to interpret since/until if not tz-aware (defaults to system timezone) - `--db`: Write to `metrics` table in DuckDB instead of outputting NDJSON to stdout **Deduplication in DuckDB:** Deletes all existing rows for the same `app_id` within the fetched time range before inserting new data. diff --git a/src/main.rs b/src/main.rs index 8125cb9..b252ae3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -183,7 +183,7 @@ enum Command { /// Timezone for intervals and to interpret since/until if not tz-aware /// - /// Defaults to UTC. Example: America/New_York. + /// Defaults to system timezone. Example: America/New_York. #[arg(long)] timezone: Option, diff --git a/src/metrics.rs b/src/metrics.rs index 0752ae3..1d600cb 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -77,9 +77,11 @@ pub fn run( .map_err(|e| input_err(format!("invalid JSON for --filters: {e}")))?; body["filters"] = filters_value; } - if let Some(timezone) = timezone { - body["timezone"] = serde_json::json!(timezone); - } + let timezone = match timezone { + Some(tz) => tz.to_owned(), + None => iana_time_zone::get_timezone().unwrap_or_else(|_| "UTC".to_owned()), + }; + body["timezone"] = serde_json::json!(timezone); let url = format!("{api_base_url}/v1/apps/{app_id}/metrics"); let response = api_post(&url, &api_key, &body)?; From bc1a48fd92cdf598c63d2cd202be9487b423ec0b Mon Sep 17 00:00:00 2001 From: Simon Gurcke Date: Thu, 16 Apr 2026 11:45:47 +1000 Subject: [PATCH 2/2] Improve test --- src/metrics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/metrics.rs b/src/metrics.rs index 1d600cb..e5998ed 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -231,7 +231,7 @@ mod tests { Some("hour"), Some(r#"["method"]"#), None, - None, + Some("Australia/Brisbane"), None, Some("test-key"), Some(&server.url()),