summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorstuebinm2022-12-03 17:02:29 +0100
committerstuebinm2022-12-03 17:02:29 +0100
commite0ad2c4e7ddaaa60d7dc9d7f312bd69567fa5745 (patch)
tree945963cc3d9d72695ebacec3eccd2eb08fa552a1 /src
parent037ec595a3926d7af5ae5816d4e791e7130c3696 (diff)
decode dates in fancy mode
(rfc3339 is easier to read than unix timestamps)
Diffstat (limited to 'src')
-rw-r--r--src/fancy.rs21
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();