diff options
Diffstat (limited to '')
-rw-r--r-- | src/fancy.rs | 21 |
1 files changed, 19 insertions, 2 deletions
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<F: FieldName>( 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<F: FieldName>( 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::<Local>::from(t.and_local_timezone(Utc).unwrap()).to_rfc3339().bright_green()), + None => write!(buf, ": {}", "<invalid timestamp>".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::<Local>::from(t.and_local_timezone(Utc).unwrap()).to_rfc3339().bright_green()), + None => write!(buf, ": {}", "<invalid timestamp>".bright_red()) + }.unwrap(); + } else { + write!(buf, ": {}", v.bright_yellow()).unwrap(); + } } ReflectValueRef::Bool(v) => { write!(buf, ": {}", v.bright_yellow()).unwrap(); |