From 29f3459029e97f46b019eaeed76754f214b9918e Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 25 Oct 2024 14:38:22 -0700 Subject: [PATCH] [omdb] More concise timestamp formatting (#6933) --- dev-tools/omdb/src/bin/omdb/db.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/dev-tools/omdb/src/bin/omdb/db.rs b/dev-tools/omdb/src/bin/omdb/db.rs index ca4f7742b6..b713e35a66 100644 --- a/dev-tools/omdb/src/bin/omdb/db.rs +++ b/dev-tools/omdb/src/bin/omdb/db.rs @@ -2552,6 +2552,7 @@ async fn cmd_db_region_replacement_list( #[tabled(rename_all = "SCREAMING_SNAKE_CASE")] struct Row { pub id: Uuid, + #[tabled(display_with = "datetime_rfc3339_concise")] pub request_time: DateTime, pub replacement_state: String, } @@ -2677,6 +2678,7 @@ async fn cmd_db_region_replacement_info( #[derive(Tabled)] #[tabled(rename_all = "SCREAMING_SNAKE_CASE")] struct Row { + #[tabled(display_with = "datetime_rfc3339_concise")] pub time: DateTime, pub repair_id: String, @@ -2752,6 +2754,7 @@ async fn cmd_db_region_replacement_info( #[derive(Tabled)] #[tabled(rename_all = "SCREAMING_SNAKE_CASE")] struct StepRow { + #[tabled(display_with = "datetime_rfc3339_concise")] pub time: DateTime, pub step_type: String, pub details: String, @@ -3929,6 +3932,7 @@ async fn cmd_db_region_snapshot_replacement_list( #[tabled(rename_all = "SCREAMING_SNAKE_CASE")] struct Row { pub id: Uuid, + #[tabled(display_with = "datetime_rfc3339_concise")] pub request_time: DateTime, pub replacement_state: String, } @@ -5345,16 +5349,17 @@ async fn cmd_db_migrations_list( #[derive(Tabled)] #[tabled(rename_all = "SCREAMING_SNAKE_CASE")] struct VerboseMigrationRow { + #[tabled(display_with = "datetime_rfc3339_concise")] created: chrono::DateTime, id: Uuid, instance: Uuid, #[tabled(inline)] vmms: MigrationVmms, - #[tabled(display_with = "display_option_blank")] + #[tabled(display_with = "datetime_opt_rfc3339_concise")] src_updated: Option>, - #[tabled(display_with = "display_option_blank")] + #[tabled(display_with = "datetime_opt_rfc3339_concise")] tgt_updated: Option>, - #[tabled(display_with = "display_option_blank")] + #[tabled(display_with = "datetime_opt_rfc3339_concise")] deleted: Option>, } @@ -5390,6 +5395,7 @@ async fn cmd_db_migrations_list( #[derive(Tabled)] #[tabled(rename_all = "SCREAMING_SNAKE_CASE")] struct MigrationRow { + #[tabled(display_with = "datetime_rfc3339_concise")] created: chrono::DateTime, instance: Uuid, #[tabled(inline)] @@ -5416,6 +5422,7 @@ async fn cmd_db_migrations_list( #[derive(Tabled)] #[tabled(rename_all = "SCREAMING_SNAKE_CASE")] struct SingleInstanceMigrationRow { + #[tabled(display_with = "datetime_rfc3339_concise")] created: chrono::DateTime, #[tabled(inline)] vmms: MigrationVmms, @@ -5452,3 +5459,18 @@ impl From<&'_ Migration> for MigrationVmms { fn display_option_blank(opt: &Option) -> String { opt.as_ref().map(|x| x.to_string()).unwrap_or_else(|| "".to_string()) } + +// Format a `chrono::DateTime` in RFC3339 with milliseconds precision and using +// `Z` rather than the UTC offset for UTC timestamps, to save a few characters +// of line width in tabular output. +fn datetime_rfc3339_concise(t: &DateTime) -> String { + t.to_rfc3339_opts(chrono::format::SecondsFormat::Millis, true) +} + +// Format an optional `chrono::DateTime` in RFC3339 with milliseconds precision +// and using `Z` rather than the UTC offset for UTC timestamps, to save a few +// characters of line width in tabular output. +fn datetime_opt_rfc3339_concise(t: &Option>) -> String { + t.map(|t| t.to_rfc3339_opts(chrono::format::SecondsFormat::Millis, true)) + .unwrap_or_else(|| "-".to_string()) +}