Skip to content

Commit e522bf8

Browse files
committed
fix(rust): show Last Activity in the report timezone and keep TZDIR in the Qwen CLI test
The Qwen CLI test clears the child environment, which drops the TZDIR that the sandboxed Nix test derivation sets so jiff can resolve named zones. The binary then rejected `--timezone America/Los_Angeles` on CI while passing locally, where the system zoneinfo is found without it. Forward TZDIR when it is set. The session table's Last Activity column truncated the RFC 3339 `lastActivity` to its UTC date, so a session selected for the 23rd in America/Los_Angeles rendered as the 24th. Format the date in the report timezone like every other date column; JSON output keeps the full timestamp, and existing table snapshots all report in UTC, so only the Qwen snapshot changes.
1 parent e254379 commit e522bf8

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎rust/crates/ccusage-core/src/output.rs‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ use std::{
33
io::{self, BufWriter, IsTerminal, Write},
44
};
55

6+
use jiff::tz::TimeZone as JiffTimeZone;
67
use serde_json::{Value, json};
78

89
use crate::{
910
Align, Color, ModelBreakdown, Result, SimpleTable, USAGE_COMPACT_WIDTH_THRESHOLD, UsageSummary,
10-
cli::SharedArgs, cli_error, color, format_breakdown_model_label, format_project_name,
11-
parse_project_aliases, print_box_title, short_model_name, terminal_width,
11+
cli::SharedArgs, cli_error, color, format_breakdown_model_label, format_date_tz,
12+
format_project_name, parse_project_aliases, parse_ts_timestamp, parse_tz, print_box_title,
13+
short_model_name, terminal_width,
1214
};
1315

1416
pub fn wants_json(shared: &SharedArgs) -> bool {
@@ -180,6 +182,7 @@ pub fn print_usage_table_with_options(
180182
USAGE_COMPACT_WIDTH_THRESHOLD,
181183
);
182184
let include_last_activity = rows.iter().any(|row| row.last_activity.is_some());
185+
let timezone = parse_tz(shared.timezone.as_deref());
183186
print_box_title(title, shared);
184187
let (mut headers, mut aligns) =
185188
usage_table_columns(first_column, compact, options.show_cache_creation);
@@ -242,8 +245,9 @@ pub fn print_usage_table_with_options(
242245
values.pop();
243246
}
244247
if include_last_activity {
245-
values.push(truncate_rfc3339_to_date(
248+
values.push(format_last_activity_date(
246249
row.last_activity.as_deref().unwrap_or_default(),
250+
timezone.as_ref(),
247251
));
248252
}
249253
table.push(values);
@@ -518,15 +522,32 @@ pub fn strip_cost_json(value: &mut Value) {
518522
}
519523
}
520524

521-
fn truncate_rfc3339_to_date(s: &str) -> String {
522-
s.get(..10).unwrap_or(s).to_string()
525+
fn format_last_activity_date(value: &str, timezone: Option<&JiffTimeZone>) -> String {
526+
parse_ts_timestamp(value).map_or_else(
527+
|| value.get(..10).unwrap_or(value).to_string(),
528+
|timestamp| format_date_tz(timestamp, timezone),
529+
)
523530
}
524531

525532
#[cfg(test)]
526533
mod tests {
527534
use super::*;
528535
use crate::ModelBreakdown;
529536

537+
#[test]
538+
fn last_activity_column_shows_the_date_in_the_report_timezone() {
539+
let timezone = parse_tz(Some("America/Los_Angeles"));
540+
541+
assert_eq!(
542+
format_last_activity_date("2026-02-24T02:00:00.000Z", timezone.as_ref()),
543+
"2026-02-23"
544+
);
545+
assert_eq!(
546+
format_last_activity_date("2026-02-24", timezone.as_ref()),
547+
"2026-02-24"
548+
);
549+
}
550+
530551
#[test]
531552
fn narrow_non_tty_output_does_not_auto_compact() {
532553
let shared = SharedArgs::default();

‎rust/crates/ccusage/tests/qwen_cli.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ fn run_cli(fixture: &Fixture, args: &[&str]) -> String {
5757
.env("USERPROFILE", fixture.path("userprofile"))
5858
.env("XDG_CONFIG_HOME", fixture.path("xdg-config"))
5959
.env("QWEN_DATA_DIR", fixture.path("qwen"))
60+
.envs(std::env::var_os("TZDIR").map(|zoneinfo| ("TZDIR", zoneinfo)))
6061
.env("NO_COLOR", "1")
6162
.env("COLUMNS", "240")
6263
.args(args)

‎rust/crates/ccusage/tests/snapshots/qwen_cli__qwen_cli_session_window_table.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ expression: "run_cli(&fixture, &WINDOW_ARGS)"
1212
┌───────────┬────────────────────┬───────────┬───────────┬───────────────┬─────────────┬───────────────┬─────────────┬───────────────┐
1313
│ Session │ Models │ Input │ Output │ Cache Create │ Cache Read │ Total Tokens │ Cost (USD) │ Last Activity │
1414
├───────────┼────────────────────┼───────────┼───────────┼───────────────┼─────────────┼───────────────┼─────────────┼───────────────┤
15-
│ until-day │ - qwen3-coder-plus │ 100 │ 50 │ 0 │ 0 │ 150 │ $0.00 │ 2026-02-24 │
15+
│ until-day │ - qwen3-coder-plus │ 100 │ 50 │ 0 │ 0 │ 150 │ $0.00 │ 2026-02-23 │
1616
├───────────┼────────────────────┼───────────┼───────────┼───────────────┼─────────────┼───────────────┼─────────────┼───────────────┤
1717
│ Total │ │ 100 │ 50 │ 0 │ 0 │ 150 │ $0.00 │ │
1818
└───────────┴────────────────────┴───────────┴───────────┴───────────────┴─────────────┴───────────────┴─────────────┴───────────────┘

0 commit comments

Comments
 (0)