time formatting

This commit is contained in:
Greg Shuflin
2025-07-21 23:02:37 -07:00
parent 5b752f10b8
commit b26c568f4f
3 changed files with 48 additions and 3 deletions

41
Cargo.lock generated
View File

@@ -131,6 +131,7 @@ dependencies = [
"ratatui",
"serde",
"serde_json",
"time",
"tokio",
"tokio-tungstenite",
"url",
@@ -348,6 +349,15 @@ version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476"
[[package]]
name = "deranged"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c9e6a11ca8224451684bc0d7d5a7adbf8f2fd6887261a1cfc3c0432f9d4068e"
dependencies = [
"powerfmt",
]
[[package]]
name = "digest"
version = "0.10.7"
@@ -843,6 +853,12 @@ dependencies = [
"tempfile",
]
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "object"
version = "0.36.7"
@@ -970,6 +986,12 @@ dependencies = [
"zerovec",
]
[[package]]
name = "powerfmt"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
@@ -1379,6 +1401,25 @@ dependencies = [
"syn",
]
[[package]]
name = "time"
version = "0.3.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a7619e19bc266e0f9c5e6686659d394bc57973859340060a69221e57dbc0c40"
dependencies = [
"deranged",
"num-conv",
"powerfmt",
"serde",
"time-core",
]
[[package]]
name = "time-core"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9e9a38711f559d9e3ce1cdb06dd7c5b8ea546bc90052da6d06bb76da74bb07c"
[[package]]
name = "tinystr"
version = "0.8.1"

View File

@@ -16,3 +16,4 @@ log = "0.4"
env_logger = "0.10"
rand = "0.8"
ratatui = "0.29.0"
time = "0.3.41"

View File

@@ -3,6 +3,7 @@ use colored::*;
use futures_util::StreamExt;
use log::{debug, warn};
use std::collections::HashMap;
use time::UtcDateTime;
use tokio_tungstenite::{connect_async, tungstenite::protocol::Message};
mod post;
@@ -80,7 +81,9 @@ impl BlueskyFirehosePrinter {
return true; // Continue processing
}
let ts = post.get_time_us().unwrap_or(0) / 10_000;
let ts = post.get_time_us().unwrap_or(0);
let date = UtcDateTime::from_unix_timestamp((ts as i64) / 100_000)
.unwrap_or_else(|_| UtcDateTime::UNIX_EPOCH);
// Generate HSV color based on timestamp
let h = ((ts as f64 / 4.0) % 255.0) / 255.0 * 360.0;
@@ -129,7 +132,7 @@ impl BlueskyFirehosePrinter {
println!(
"{}{}|type:{}|{}{}{}|hsv:{} type:{} kind:{} commit.type={} operation={}",
format!("{}", ts).color(info_color),
format!("{date}").color(info_color),
format!("").color(info_color),
type_str.color(info_color),
text.color(text_color),
@@ -144,7 +147,7 @@ impl BlueskyFirehosePrinter {
} else {
println!(
"{}{}|type:{}|{}{}|hsv:{} type:{} kind:{}",
format!("{}", ts).color(info_color),
format!("{date}").color(info_color),
format!("").color(info_color),
type_str.color(info_color),
text.color(text_color),