Skip to content

Commit

Permalink
feat: display localtime in dashboard fields
Browse files Browse the repository at this point in the history
Converts UTC to user's localtime in the History and Peers screens.
  • Loading branch information
dan-da committed Jan 18, 2024
1 parent fa89d04 commit 3626465
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/bin/dashboard_src/history_screen.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::{
cmp::{max, min},
sync::{Arc, Mutex},
time::{Duration, UNIX_EPOCH},
time::Duration,
};

use super::{dashboard_app::DashboardEvent, screen::Screen};
use chrono::{DateTime, Utc};
use crossterm::event::{Event, KeyCode, KeyEventKind};
use itertools::Itertools;
use neptune_core::{
Expand Down Expand Up @@ -265,10 +264,10 @@ impl Widget for HistoryScreen {
.iter()
.rev()
.map(|bu| {
let (height, duration, amount, sign, balance) = *bu;
let (height, timestamp, amount, sign, balance) = *bu;
vec![
height.to_string(),
DateTime::<Utc>::from(UNIX_EPOCH + duration).to_string(),
neptune_core::utc_timestamp_to_localtime(timestamp.as_millis()).to_string(),
if sign == Sign::NonNegative {
"↘".to_string()
} else {
Expand Down
9 changes: 4 additions & 5 deletions src/bin/dashboard_src/peers_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
};

use super::{dashboard_app::DashboardEvent, screen::Screen};
use chrono::{DateTime, Utc};
use itertools::Itertools;
use neptune_core::{models::peer::PeerInfo, rpc_server::RPCClient};
use ratatui::{
Expand Down Expand Up @@ -177,12 +176,12 @@ impl Widget for PeersScreen {
.map(|pi| {
let latest_violation: Option<String> =
pi.standing.latest_sanction.map(|x| x.to_string());
let formatted_datetime = DateTime::<Utc>::from(pi.last_seen)
.format("%Y-%m-%d %H:%M")
.to_string();
let last_seen_timestamp =
pi.last_seen.duration_since(std::time::UNIX_EPOCH).unwrap();
vec![
pi.connected_address.to_string(),
formatted_datetime,
neptune_core::utc_timestamp_to_localtime(last_seen_timestamp.as_millis())
.to_string(),
pi.standing.standing.to_string(),
if pi.is_archival_node {
"✓".to_string()
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ where
(output, total_time)
}

/// Converts a UTC timestamp (seconds since 1970 UTC) into
/// Converts a UTC millisecond timestamp (millis since 1970 UTC) into
/// a `DateTime<Local>`, ie local-time.
pub fn utc_timestamp_to_localtime<T>(timestamp: T) -> DateTime<Local>
where
Expand Down

0 comments on commit 3626465

Please sign in to comment.