Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 43f99bd

Browse files
mergify[bot]mvines
andauthored
Improve vote-account "Recent Timestamp" output (#12971)
(cherry picked from commit 2cc3d75) Co-authored-by: Michael Vines <mvines@gmail.com>
1 parent 0008dc6 commit 43f99bd

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

cli-output/src/cli_output.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,8 @@ impl fmt::Display for CliStakeState {
661661
if lockup.unix_timestamp != UnixTimestamp::default() {
662662
writeln!(
663663
f,
664-
"Lockup Timestamp: {} (UnixTimestamp: {})",
665-
DateTime::<Utc>::from_utc(
666-
NaiveDateTime::from_timestamp(lockup.unix_timestamp, 0),
667-
Utc
668-
)
669-
.to_rfc3339_opts(SecondsFormat::Secs, true),
670-
lockup.unix_timestamp
664+
"Lockup Timestamp: {}",
665+
unix_timestamp_to_string(lockup.unix_timestamp)
671666
)?;
672667
}
673668
if lockup.epoch != Epoch::default() {
@@ -1008,7 +1003,12 @@ impl fmt::Display for CliVoteAccount {
10081003
None => "~".to_string(),
10091004
}
10101005
)?;
1011-
writeln!(f, "Recent Timestamp: {:?}", self.recent_timestamp)?;
1006+
writeln!(
1007+
f,
1008+
"Recent Timestamp: {} from slot {}",
1009+
unix_timestamp_to_string(self.recent_timestamp.timestamp),
1010+
self.recent_timestamp.slot
1011+
)?;
10121012
if !self.votes.is_empty() {
10131013
writeln!(f, "Recent Votes:")?;
10141014
for vote in &self.votes {
@@ -1093,19 +1093,22 @@ pub struct CliBlockTime {
10931093
impl QuietDisplay for CliBlockTime {}
10941094
impl VerboseDisplay for CliBlockTime {}
10951095

1096+
fn unix_timestamp_to_string(unix_timestamp: UnixTimestamp) -> String {
1097+
format!(
1098+
"{} (UnixTimestamp: {})",
1099+
match NaiveDateTime::from_timestamp_opt(unix_timestamp, 0) {
1100+
Some(ndt) =>
1101+
DateTime::<Utc>::from_utc(ndt, Utc).to_rfc3339_opts(SecondsFormat::Secs, true),
1102+
None => "unknown".to_string(),
1103+
},
1104+
unix_timestamp,
1105+
)
1106+
}
1107+
10961108
impl fmt::Display for CliBlockTime {
10971109
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10981110
writeln_name_value(f, "Block:", &self.slot.to_string())?;
1099-
writeln_name_value(
1100-
f,
1101-
"Date:",
1102-
&format!(
1103-
"{} (UnixTimestamp: {})",
1104-
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(self.timestamp, 0), Utc)
1105-
.to_rfc3339_opts(SecondsFormat::Secs, true),
1106-
self.timestamp
1107-
),
1108-
)
1111+
writeln_name_value(f, "Date:", &unix_timestamp_to_string(self.timestamp))
11091112
}
11101113
}
11111114

0 commit comments

Comments
 (0)