Skip to content

Commit

Permalink
Change timezone (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-21 authored Mar 21, 2023
1 parent 5e56f55 commit 1ca1ba5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
5 changes: 3 additions & 2 deletions eel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Invoice> {
Expand Down
4 changes: 4 additions & 0 deletions eel/src/payment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 17 additions & 7 deletions examples/3l-node/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Utc> = payment.created_at.timestamp.into();
let latest_state_change_at: DateTime<Utc> = 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<Utc> = 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);
Expand Down
4 changes: 2 additions & 2 deletions examples/3l-node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 1ca1ba5

Please sign in to comment.