From 6531cc293def967f63cb737b2ca5547b95bb3d9a Mon Sep 17 00:00:00 2001 From: edouardparis Date: Wed, 22 May 2024 16:43:22 +0200 Subject: [PATCH] fix local date time and bump chrono close #1057 --- gui/Cargo.lock | 36 +++++++++----------------- gui/Cargo.toml | 2 +- gui/src/app/state/settings/bitcoind.rs | 4 +-- gui/src/app/view/home.rs | 9 ++++--- gui/src/app/view/transactions.rs | 22 +++++++++------- gui/ui/src/component/event.rs | 22 +++++++++++----- 6 files changed, 48 insertions(+), 47 deletions(-) diff --git a/gui/Cargo.lock b/gui/Cargo.lock index 81bd9085..d1d0b87c 100644 --- a/gui/Cargo.lock +++ b/gui/Cargo.lock @@ -140,6 +140,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -630,17 +636,16 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.24" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ + "android-tzdata", "iana-time-zone", "js-sys", - "num-integer", "num-traits", - "time", "wasm-bindgen", - "winapi", + "windows-targets 0.52.5", ] [[package]] @@ -1667,7 +1672,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "wasm-bindgen", ] @@ -2938,7 +2943,7 @@ checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.45.0", ] @@ -4686,17 +4691,6 @@ dependencies = [ "weezl", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "tiny-keccak" version = "2.0.2" @@ -5154,12 +5148,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/gui/Cargo.toml b/gui/Cargo.toml index c9cbb672..40bfc06f 100644 --- a/gui/Cargo.toml +++ b/gui/Cargo.toml @@ -39,7 +39,7 @@ log = "0.4" dirs = "3.0.1" toml = "0.5" -chrono = "0.4" +chrono = "0.4.38" # Used for managing internal bitcoind base64 = "0.21" diff --git a/gui/src/app/state/settings/bitcoind.rs b/gui/src/app/state/settings/bitcoind.rs index caf683bb..430b1fe5 100644 --- a/gui/src/app/state/settings/bitcoind.rs +++ b/gui/src/app/state/settings/bitcoind.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use std::str::FromStr; use std::sync::Arc; -use chrono::prelude::*; +use chrono::{NaiveDate, Utc}; use iced::Command; use tracing::info; @@ -368,7 +368,7 @@ impl RescanSetting { u32::from_str(&self.day.value).unwrap_or(1), ) .and_then(|d| d.and_hms_opt(0, 0, 0)) - .map(|d| d.timestamp()) + .map(|d| d.and_utc().timestamp()) { match cache.network { Network::Bitcoin => { diff --git a/gui/src/app/view/home.rs b/gui/src/app/view/home.rs index 7714aa70..7adc4f90 100644 --- a/gui/src/app/view/home.rs +++ b/gui/src/app/view/home.rs @@ -1,4 +1,4 @@ -use chrono::NaiveDateTime; +use chrono::{DateTime, Local, Utc}; use std::collections::HashMap; use iced::{alignment, widget::Space, Alignment, Length}; @@ -172,7 +172,7 @@ fn event_list_view(i: usize, event: &HistoryTransaction) -> Column<'_, Message> } else if let Some(t) = event.time { col.push(event::confirmed_incoming_event( label, - NaiveDateTime::from_timestamp_opt(t as i64, 0).unwrap(), + DateTime::::from_timestamp(t as i64, 0).unwrap(), &output.value, Message::SelectSub(i, output_index), )) @@ -188,7 +188,7 @@ fn event_list_view(i: usize, event: &HistoryTransaction) -> Column<'_, Message> } else if let Some(t) = event.time { col.push(event::confirmed_outgoing_event( label, - NaiveDateTime::from_timestamp_opt(t as i64, 0).unwrap(), + DateTime::::from_timestamp(t as i64, 0).unwrap(), &output.value, Message::SelectSub(i, output_index), )) @@ -286,8 +286,9 @@ pub fn payment_view<'a>( .push(card::simple( Column::new() .push_maybe(tx.time.map(|t| { - let date = NaiveDateTime::from_timestamp_opt(t as i64, 0) + let date = DateTime::::from_timestamp(t as i64, 0) .unwrap() + .with_timezone(&Local) .format("%b. %d, %Y - %T"); Row::new() .width(Length::Fill) diff --git a/gui/src/app/view/transactions.rs b/gui/src/app/view/transactions.rs index cab1064c..f1e1437d 100644 --- a/gui/src/app/view/transactions.rs +++ b/gui/src/app/view/transactions.rs @@ -1,6 +1,6 @@ -use chrono::NaiveDateTime; use std::collections::{HashMap, HashSet}; +use chrono::{DateTime, Local, Utc}; use iced::{alignment, widget::tooltip, Alignment, Length}; use liana_ui::{ @@ -105,12 +105,13 @@ fn tx_list_view(i: usize, tx: &HistoryTransaction) -> Element<'_, Message> { }) .push_maybe(tx.time.map(|t| { Container::new( - text(format!( - "{}", - NaiveDateTime::from_timestamp_opt(t as i64, 0) - .unwrap() - .format("%b. %d, %Y - %T"), - )) + text( + DateTime::::from_timestamp(t as i64, 0) + .expect("Correct unix timestamp") + .with_timezone(&Local) + .format("%b. %d, %Y - %T") + .to_string(), + ) .style(color::GREY_3) .small(), ) @@ -374,9 +375,10 @@ pub fn tx_view<'a>( .push(card::simple( Column::new() .push_maybe(tx.time.map(|t| { - let date = NaiveDateTime::from_timestamp_opt(t as i64, 0) - .unwrap() - .format("%b. %d, %Y - %T"); + let date = DateTime::::from_timestamp(t as i64, 0) + .expect("Correct unix timestamp") + .with_timezone(&Local) + .format("%b. %d, %Y - %T"); Row::new() .width(Length::Fill) .push(Container::new(text("Date:").bold()).width(Length::Fill)) diff --git a/gui/ui/src/component/event.rs b/gui/ui/src/component/event.rs index 1ee62995..53e5db99 100644 --- a/gui/ui/src/component/event.rs +++ b/gui/ui/src/component/event.rs @@ -10,6 +10,8 @@ use iced::{ Alignment, Length, }; +use chrono::{DateTime, Local, Utc}; + pub fn unconfirmed_outgoing_event<'a, T: Clone + 'a>( label: Option>, amount: &Amount, @@ -39,7 +41,7 @@ pub fn unconfirmed_outgoing_event<'a, T: Clone + 'a>( pub fn confirmed_outgoing_event<'a, T: Clone + 'a>( label: Option>, - date: chrono::NaiveDateTime, + date: DateTime, amount: &Amount, msg: T, ) -> Container<'a, T> { @@ -49,8 +51,12 @@ pub fn confirmed_outgoing_event<'a, T: Clone + 'a>( row!( badge::spend(), Column::new().push_maybe(label).push( - text::p2_regular(date.format("%b. %d, %Y - %T").to_string()) - .style(color::GREY_3) + text::p2_regular( + date.with_timezone(&Local) + .format("%b. %d, %Y - %T") + .to_string() + ) + .style(color::GREY_3) ) ) .spacing(10) @@ -99,7 +105,7 @@ pub fn unconfirmed_incoming_event<'a, T: Clone + 'a>( pub fn confirmed_incoming_event<'a, T: Clone + 'a>( label: Option>, - date: chrono::NaiveDateTime, + date: DateTime, amount: &Amount, msg: T, ) -> Container<'a, T> { @@ -109,8 +115,12 @@ pub fn confirmed_incoming_event<'a, T: Clone + 'a>( row!( badge::receive(), Column::new().push_maybe(label).push( - text::p2_regular(date.format("%b. %d, %Y - %T").to_string()) - .style(color::GREY_3) + text::p2_regular( + date.with_timezone(&Local) + .format("%b. %d, %Y - %T") + .to_string() + ) + .style(color::GREY_3) ) ) .spacing(10)