From 1ca1ba5c9b6b42a4a768f4c743bc4d425ab6df68 Mon Sep 17 00:00:00 2001 From: Andrei <92177534+andrei-21@users.noreply.github.com> Date: Tue, 21 Mar 2023 15:20:45 +0000 Subject: [PATCH] Change timezone (#284) --- eel/src/lib.rs | 5 +++-- eel/src/payment_store.rs | 4 ++++ examples/3l-node/cli.rs | 24 +++++++++++++++++------- examples/3l-node/main.rs | 4 ++-- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/eel/src/lib.rs b/eel/src/lib.rs index 4d1672a6..2b659de0 100644 --- a/eel/src/lib.rs +++ b/eel/src/lib.rs @@ -548,8 +548,9 @@ impl LightningNode { task_manager.restart(FOREGROUND_PERIODS); } - pub fn change_timezone_config(&self, _timezone_config: TzConfig) { - // TODO: Change timezone in payment store. + pub fn change_timezone_config(&self, timezone_config: TzConfig) { + let mut payment_store = self.payment_store.lock().unwrap(); + payment_store.update_timezone_config(timezone_config); } fn parse_validate_invoice(&self, invoice: &str) -> Result { diff --git a/eel/src/payment_store.rs b/eel/src/payment_store.rs index 050125ce..0a3a4572 100644 --- a/eel/src/payment_store.rs +++ b/eel/src/payment_store.rs @@ -92,6 +92,10 @@ impl PaymentStore { }) } + pub fn update_timezone_config(&mut self, timezone_config: TzConfig) { + self.timezone_config = timezone_config; + } + #[allow(clippy::too_many_arguments)] pub fn new_incoming_payment( &mut self, diff --git a/examples/3l-node/cli.rs b/examples/3l-node/cli.rs index c9846a8d..7d19aea9 100644 --- a/examples/3l-node/cli.rs +++ b/examples/3l-node/cli.rs @@ -3,6 +3,7 @@ use crate::hinter::{CommandHint, CommandHinter}; use uniffi_lipalightninglib::TzConfig; use bitcoin::secp256k1::PublicKey; +use chrono::offset::FixedOffset; use chrono::{DateTime, Utc}; use colored::Colorize; use rustyline::config::{Builder, CompletionType}; @@ -357,16 +358,25 @@ fn list_payments(node: &LightningNode) -> Result<(), String> { Err(e) => return Err(e.to_string()), }; - println!("Total of {} payments\n", payments.len()); - + println!("Total of {} payments\n", payments.len().to_string().bold()); for payment in payments { + let payment_type = format!("{:?}", payment.payment_type); let created_at: DateTime = payment.created_at.timestamp.into(); - let latest_state_change_at: DateTime = payment.latest_state_change_at.timestamp.into(); + let timezone = FixedOffset::east_opt(payment.created_at.timezone_utc_offset_secs).unwrap(); + let created_at = created_at.with_timezone(&timezone); + + let latest_change_at: DateTime = payment.latest_state_change_at.timestamp.into(); + let timezone = + FixedOffset::east_opt(payment.latest_state_change_at.timezone_utc_offset_secs).unwrap(); + let latest_change_at = latest_change_at.with_timezone(&timezone); + println!( + "{} payment created at {created_at} {}", + payment_type.bold(), + payment.created_at.timezone_id + ); println!( - "{:?} payment created at {} and with latest state change at {}", - payment.payment_type, - created_at.format("%d/%m/%Y %T"), - latest_state_change_at.format("%d/%m/%Y %T") + "and with latest state change at {latest_change_at} {}", + payment.latest_state_change_at.timezone_id ); println!(" State: {:?}", payment.payment_state); println!(" Amount msat: {}", payment.amount_msat); diff --git a/examples/3l-node/main.rs b/examples/3l-node/main.rs index 56fdd46c..b0efaea7 100644 --- a/examples/3l-node/main.rs +++ b/examples/3l-node/main.rs @@ -42,8 +42,8 @@ fn main() { lsp_token: "iQUvOsdk4ognKshZB/CKN2vScksLhW8i13vTO+8SPvcyWJ+fHi8OLgUEvW1N3k2l".to_string(), local_persistence_path: BASE_DIR.to_string(), timezone_config: TzConfig { - timezone_id: String::from("example_timezone_id"), - timezone_utc_offset_secs: 1234, + timezone_id: String::from("Europe/Zurich"), + timezone_utc_offset_secs: 1 * 60 * 60, }, graphql_url: get_backend_url(), backend_health_url: get_backend_health_url(),