From e0ad2c4e7ddaaa60d7dc9d7f312bd69567fa5745 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sat, 3 Dec 2022 17:02:29 +0100 Subject: decode dates in fancy mode (rfc3339 is easier to read than unix timestamps) --- Cargo.lock | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/fancy.rs | 21 +++++++- 3 files changed, 182 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b0fb33..666f6d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.66" @@ -111,6 +120,21 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-integer", + "num-traits", + "time", + "wasm-bindgen", + "winapi", +] + [[package]] name = "clap" version = "4.0.19" @@ -148,6 +172,66 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "cxx" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdf07d07d6531bfcdbe9b8b739b104610c6508dcc4d63b410585faf338241daf" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2eb5b96ecdc99f72657332953d4d9c50135af1bac34277801cc3937906ebd39" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac040a39517fd1674e0f32177648334b0f4074625b5588a64519804ba0553b12" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1362b0ddcfc4eb0a1f57b68bd77dd99f0e826958a96abd0ae9bd092e114ffed6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "either" version = "1.8.0" @@ -234,7 +318,7 @@ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -357,6 +441,30 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "iana-time-zone" +version = "0.1.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "idna" version = "0.3.0" @@ -419,6 +527,15 @@ version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +[[package]] +name = "link-cplusplus" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] + [[package]] name = "lock_api" version = "0.4.9" @@ -498,10 +615,29 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys", ] +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + [[package]] name = "num_cpus" version = "1.14.0" @@ -815,6 +951,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "scratch" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + [[package]] name = "sct" version = "0.7.0" @@ -858,6 +1000,7 @@ dependencies = [ name = "showrt" version = "0.1.0" dependencies = [ + "chrono", "clap", "miette", "owo-colors", @@ -1024,6 +1167,17 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -1197,6 +1351,12 @@ dependencies = [ "try-lock", ] +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 8e44e62..62f8c5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,3 +18,4 @@ tokio = { version = "1", features = ["full"] } clap = { version = "4", features = ["derive"] } miette = { version = "5", features = ["fancy"] } owo-colors = { version = "3.5", features = ["supports-color"] } +chrono = "0.4" diff --git a/src/fancy.rs b/src/fancy.rs index 477018f..2058129 100644 --- a/src/fancy.rs +++ b/src/fancy.rs @@ -7,6 +7,8 @@ use std::fmt; use std::fmt::Display; use std::fmt::Write; use owo_colors::OwoColorize; +use chrono::naive::NaiveDateTime; +use chrono::{Utc, DateTime, Local}; use protobuf_support::text_format::quote_bytes_to; @@ -82,6 +84,7 @@ fn print_field( field_name: F, value: ReflectValueRef, ) { + let fieldname_str = field_name.to_string(); print_start_field(buf, pretty, indent, first, field_name); match value { @@ -116,13 +119,27 @@ fn print_field( write!(buf, ": {}", v.bright_yellow()).unwrap(); } ReflectValueRef::I64(v) => { - write!(buf, ": {}", v.bright_yellow()).unwrap(); + if fieldname_str.contains("time") { + match NaiveDateTime::from_timestamp_opt(v, 0) { + Some(t) => write!(buf, ": {}", DateTime::::from(t.and_local_timezone(Utc).unwrap()).to_rfc3339().bright_green()), + None => write!(buf, ": {}", "".bright_red()) + }.unwrap(); + } else { + write!(buf, ": {}", v.bright_yellow()).unwrap(); + } } ReflectValueRef::U32(v) => { write!(buf, ": {}", v.bright_yellow()).unwrap(); } ReflectValueRef::U64(v) => { - write!(buf, ": {}", v.bright_yellow()).unwrap(); + if fieldname_str.contains("time") { + match NaiveDateTime::from_timestamp_opt(v.try_into().unwrap(), 0) { + Some(t) => write!(buf, ": {}", DateTime::::from(t.and_local_timezone(Utc).unwrap()).to_rfc3339().bright_green()), + None => write!(buf, ": {}", "".bright_red()) + }.unwrap(); + } else { + write!(buf, ": {}", v.bright_yellow()).unwrap(); + } } ReflectValueRef::Bool(v) => { write!(buf, ": {}", v.bright_yellow()).unwrap(); -- cgit v1.2.3