Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
aterga committed Dec 5, 2024
1 parent 5a5a9ad commit 5276bd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/lib/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub fn format_timestamp_seconds(seconds: u64) -> String {
format_datetime(Utc.timestamp_opt(seconds.try_into().unwrap(), 0).unwrap())
}

pub fn format_timestamp_nanoseconds(nanoseconds: u64) -> String {
format_datetime(Utc.timestamp_nanos(nanoseconds.try_into().unwrap()))
}

pub fn format_duration_seconds(mut seconds: u64) -> String {
// Required for magic numbers like '8 years' to show up as such instead of '8 years 2 days'.
const SECONDS_PER_YEAR: u64 = 31557600; // 365.25 * 24 * 60 * 60
Expand Down
6 changes: 3 additions & 3 deletions src/lib/format/sns_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::fmt::Write;

use crate::lib::{e8s_to_tokens, AnyhowResult};

use super::{format_timestamp_seconds, icrc1_account};
use super::{format_timestamp_nanoseconds, icrc1_account};

pub fn display_get_buyer_state(blob: &[u8]) -> AnyhowResult<String> {
let response = Decode!(blob, GetBuyerStateResponse)?;
Expand Down Expand Up @@ -50,7 +50,7 @@ Successfully created ticket with ID {id}
Creation time: {time}
Ticket amount: {amount} ICP",
id = ticket.ticket_id,
time = format_timestamp_seconds(ticket.creation_time),
time = format_timestamp_nanoseconds(ticket.creation_time),
amount = e8s_to_tokens(ticket.amount_icp_e8s.into()),
);
if let Some(account) = ticket.account {
Expand Down Expand Up @@ -105,7 +105,7 @@ Ticket ID: {id}
Creation time: {time}
Ticket amount: {amount} ICP",
id = ticket.ticket_id,
time = format_timestamp_seconds(ticket.creation_time),
time = format_timestamp_nanoseconds(ticket.creation_time),
amount = e8s_to_tokens(ticket.amount_icp_e8s.into())
);
if let Some(account) = ticket.account {
Expand Down

0 comments on commit 5276bd1

Please sign in to comment.