Skip to content

Commit b0c831b

Browse files
authored
fix(cli): show full date in rule history (#5576)
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
1 parent b62ec53 commit b0c831b

2 files changed

Lines changed: 14 additions & 21 deletions

File tree

‎crates/openshell-cli/src/commands/common.rs‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,6 @@ pub fn format_timestamp(d: Duration) -> String {
142142
format!("[{secs:.1}s]")
143143
}
144144

145-
/// Format a millisecond timestamp into a readable string.
146-
pub fn format_timestamp_ms(ms: i64) -> String {
147-
if ms <= 0 {
148-
return "-".to_string();
149-
}
150-
let secs = ms / 1000;
151-
let mins = (secs / 60) % 60;
152-
let hours = (secs / 3600) % 24;
153-
let days = secs / 86400;
154-
if days > 0 {
155-
format!("{days}d {hours:02}:{mins:02}")
156-
} else {
157-
format!("{hours:02}:{mins:02}")
158-
}
159-
}
160-
161145
pub fn truncate_status_field(value: &str, max_chars: usize) -> String {
162146
if value.is_empty() {
163147
return "-".to_string();
@@ -1152,6 +1136,15 @@ mod tests {
11521136
assert!(err.to_string().contains("--annotation key cannot be empty"));
11531137
}
11541138

1139+
#[test]
1140+
fn format_optional_epoch_ms_shows_date_or_dash() {
1141+
assert_eq!(
1142+
format_optional_epoch_ms(1_794_000_000_000),
1143+
"2026-11-06 21:20:00"
1144+
);
1145+
assert_eq!(format_optional_epoch_ms(0), "-");
1146+
}
1147+
11551148
#[test]
11561149
fn parse_duration_to_ms_parses_supported_units() {
11571150
assert_eq!(parse_duration_to_ms("30s").expect("parse"), 30_000);

‎crates/openshell-cli/src/run.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ pub use crate::commands::common::{
99
};
1010
use crate::commands::common::{
1111
ProvisioningDisplay, ProvisioningStep, confirm_global_setting_delete,
12-
confirm_global_setting_takeover, format_epoch_ms, format_setting_value, format_timestamp,
13-
format_timestamp_ms, handle_platform_progress_event, is_provisioning_progress_event,
14-
non_empty_or, parse_cli_setting_value, parse_duration_to_ms, phase_name,
15-
print_policy_merge_warnings, print_sandbox_header, print_sandbox_policy,
12+
confirm_global_setting_takeover, format_epoch_ms, format_optional_epoch_ms,
13+
format_setting_value, format_timestamp, handle_platform_progress_event,
14+
is_provisioning_progress_event, non_empty_or, parse_cli_setting_value, parse_duration_to_ms,
15+
phase_name, print_policy_merge_warnings, print_sandbox_header, print_sandbox_policy,
1616
provisioning_blocker_message, provisioning_timeout_message, scrub_git_env, short_hash,
1717
truncate_status_field,
1818
};
@@ -7072,7 +7072,7 @@ pub async fn sandbox_draft_history(
70727072

70737073
println!(
70747074
" {} {} [{}] {}",
7075-
format_timestamp_ms(proto_timestamp_ms(entry.event_time.as_ref())).dimmed(),
7075+
format_optional_epoch_ms(proto_timestamp_ms(entry.event_time.as_ref())).dimmed(),
70767076
event_colored,
70777077
entry.chunk_id.get(..8).unwrap_or(&entry.chunk_id),
70787078
entry.description,

0 commit comments

Comments
 (0)