Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Display nanosecond timestamps in NewSaleTicketResponse instances #247

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading