diff --git a/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs b/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs index 798042d18a..b46c85c983 100644 --- a/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs +++ b/applications/minotari_console_wallet/src/ui/components/transactions_tab.rs @@ -139,7 +139,7 @@ impl TransactionsTab { None => String::new(), Some(mined_timestamp) => format!( "{}", - DateTime::::from_utc(mined_timestamp, Local::now().offset().to_owned()) + DateTime::::from_naive_utc_and_offset(mined_timestamp, Local::now().offset().to_owned()) .format("%Y-%m-%d %H:%M:%S") ), }, @@ -246,7 +246,7 @@ impl TransactionsTab { None => String::new(), Some(mined_timestamp) => format!( "{}", - DateTime::::from_utc(mined_timestamp, Local::now().offset().to_owned()) + DateTime::::from_naive_utc_and_offset(mined_timestamp, Local::now().offset().to_owned()) .format("%Y-%m-%d %H:%M:%S") ), }, @@ -388,13 +388,14 @@ impl TransactionsTab { let status = Span::styled(status_msg, Style::default().fg(Color::White)); let message = Span::styled(tx.message.as_str(), Style::default().fg(Color::White)); - // let mined_time = DateTime::::from_utc(tx.mined_timestamp, Local::now().offset().to_owned()); + // let mined_time = DateTime::::from_naive_utc_and_offset(tx.mined_timestamp, + // Local::now().offset().to_owned()); let mined_timestamp = Span::styled( match tx.mined_timestamp { None => String::new(), Some(mined_timestamp) => format!( "{}", - DateTime::::from_utc(mined_timestamp, Local::now().offset().to_owned()) + DateTime::::from_naive_utc_and_offset(mined_timestamp, Local::now().offset().to_owned()) .format("%Y-%m-%d %H:%M:%S") ), }, @@ -402,7 +403,8 @@ impl TransactionsTab { Style::default().fg(Color::White), ); - let imported_time = DateTime::::from_utc(tx.timestamp, Local::now().offset().to_owned()); + let imported_time = + DateTime::::from_naive_utc_and_offset(tx.timestamp, Local::now().offset().to_owned()); let imported_timestamp = Span::styled( format!("{}", imported_time.format("%Y-%m-%d %H:%M:%S")), Style::default().fg(Color::White), diff --git a/applications/minotari_console_wallet/src/ui/ui_contact.rs b/applications/minotari_console_wallet/src/ui/ui_contact.rs index ddb49eede2..9851816f8b 100644 --- a/applications/minotari_console_wallet/src/ui/ui_contact.rs +++ b/applications/minotari_console_wallet/src/ui/ui_contact.rs @@ -47,7 +47,7 @@ impl From for UiContact { address: c.address.to_hex(), emoji_id: c.address.to_emoji_string(), last_seen: match c.last_seen { - Some(val) => DateTime::::from_utc(val, Local::now().offset().to_owned()) + Some(val) => DateTime::::from_naive_utc_and_offset(val, Local::now().offset().to_owned()) .format("%m-%dT%H:%M") .to_string(), None => "".to_string(), diff --git a/applications/minotari_miner/src/difficulty.rs b/applications/minotari_miner/src/difficulty.rs index 2166cb18e6..e2a5213d2d 100644 --- a/applications/minotari_miner/src/difficulty.rs +++ b/applications/minotari_miner/src/difficulty.rs @@ -94,7 +94,7 @@ pub mod test { #[allow(clippy::cast_sign_loss)] pub fn get_header() -> (grpc_header, BlockHeader) { let mut header = BlockHeader::new(0); - header.timestamp = (DateTime::::from_utc( + header.timestamp = (DateTime::::from_naive_utc_and_offset( NaiveDate::from_ymd_opt(2000, 1, 1) .unwrap() .and_hms_opt(1, 1, 1) diff --git a/applications/minotari_node/src/commands/command/header_stats.rs b/applications/minotari_node/src/commands/command/header_stats.rs index c6c5644a69..3a00ed16d2 100644 --- a/applications/minotari_node/src/commands/command/header_stats.rs +++ b/applications/minotari_node/src/commands/command/header_stats.rs @@ -140,7 +140,7 @@ impl CommandContext { solve_time, normalized_solve_time, pow_algo, - chrono::DateTime::::from_utc( + chrono::DateTime::::from_naive_utc_and_offset( NaiveDateTime::from_timestamp_opt(header.header().timestamp.as_u64() as i64, 0).unwrap_or_default(), Utc ), diff --git a/applications/minotari_node/src/commands/command/status.rs b/applications/minotari_node/src/commands/command/status.rs index 89ecf86ed7..e63e256b7b 100644 --- a/applications/minotari_node/src/commands/command/status.rs +++ b/applications/minotari_node/src/commands/command/status.rs @@ -70,7 +70,7 @@ impl CommandContext { .get_header(height) .await? .ok_or_else(|| anyhow!("No last header"))?; - let last_block_time = DateTime::::from_utc( + let last_block_time = DateTime::::from_naive_utc_and_offset( NaiveDateTime::from_timestamp_opt(last_header.header().timestamp.as_u64() as i64, 0).unwrap_or_default(), Utc, ); diff --git a/base_layer/contacts/src/contacts_service/handle.rs b/base_layer/contacts/src/contacts_service/handle.rs index 3ea70aeb89..877fb8a774 100644 --- a/base_layer/contacts/src/contacts_service/handle.rs +++ b/base_layer/contacts/src/contacts_service/handle.rs @@ -110,7 +110,7 @@ impl Display for ContactsLivenessData { self.address, self.node_id, if let Some(time) = self.last_seen { - let local_time = DateTime::::from_utc(time, Local::now().offset().to_owned()) + let local_time = DateTime::::from_naive_utc_and_offset(time, Local::now().offset().to_owned()) .format("%FT%T") .to_string(); format!("last seen {} is '{}'", local_time, self.online_status) diff --git a/base_layer/core/src/blocks/block_header.rs b/base_layer/core/src/blocks/block_header.rs index ce45fa2d41..ef37a3b21c 100644 --- a/base_layer/core/src/blocks/block_header.rs +++ b/base_layer/core/src/blocks/block_header.rs @@ -250,7 +250,7 @@ impl BlockHeader { pub fn to_chrono_datetime(&self) -> DateTime { let dt = NaiveDateTime::from_timestamp_opt(i64::try_from(self.timestamp.as_u64()).unwrap_or(i64::MAX), 0) .unwrap_or(NaiveDateTime::MAX); - DateTime::from_utc(dt, Utc) + DateTime::from_naive_utc_and_offset(dt, Utc) } #[inline] diff --git a/base_layer/core/src/proof_of_work/sha3x_pow.rs b/base_layer/core/src/proof_of_work/sha3x_pow.rs index 722db4db6b..6afa4c221c 100644 --- a/base_layer/core/src/proof_of_work/sha3x_pow.rs +++ b/base_layer/core/src/proof_of_work/sha3x_pow.rs @@ -82,7 +82,7 @@ pub mod test { let mut header = BlockHeader::new(2); #[allow(clippy::cast_sign_loss)] - let epoch_secs = DateTime::::from_utc( + let epoch_secs = DateTime::::from_naive_utc_and_offset( NaiveDate::from_ymd_opt(2000, 1, 1) .unwrap() .and_hms_opt(1, 1, 1) diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index cd178042f9..ea3e57314f 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -2981,9 +2981,10 @@ pub unsafe extern "C" fn liveness_data_get_last_seen( return ptr::null_mut(); } if let Some(last_seen) = (*liveness_data).last_ping_pong_received() { - let last_seen_local_time = DateTime::::from_utc(last_seen, Local::now().offset().to_owned()) - .format("%FT%T") - .to_string(); + let last_seen_local_time = + DateTime::::from_naive_utc_and_offset(last_seen, Local::now().offset().to_owned()) + .format("%FT%T") + .to_string(); let mut return_value = CString::new("").expect("Blank CString will not fail."); match CString::new(last_seen_local_time) { Ok(val) => { diff --git a/comms/core/src/peer_manager/identity_signature.rs b/comms/core/src/peer_manager/identity_signature.rs index 7e0bbd415d..3ee3b9aebb 100644 --- a/comms/core/src/peer_manager/identity_signature.rs +++ b/comms/core/src/peer_manager/identity_signature.rs @@ -168,7 +168,7 @@ impl TryFrom for IdentitySignature { .map_err(|_| PeerManagerError::InvalidIdentitySignature)?; let updated_at = NaiveDateTime::from_timestamp_opt(value.updated_at, 0).ok_or(PeerManagerError::InvalidIdentitySignature)?; - let updated_at = DateTime::::from_utc(updated_at, Utc); + let updated_at = DateTime::::from_naive_utc_and_offset(updated_at, Utc); Ok(Self { version, diff --git a/comms/core/src/utils/datetime.rs b/comms/core/src/utils/datetime.rs index f71a48b3d1..234cd865a7 100644 --- a/comms/core/src/utils/datetime.rs +++ b/comms/core/src/utils/datetime.rs @@ -47,7 +47,7 @@ pub fn format_duration(duration: Duration) -> String { } pub fn format_local_datetime(datetime: &NaiveDateTime) -> String { - let local_datetime = DateTime::::from_utc(*datetime, Local::now().offset().to_owned()); + let local_datetime = DateTime::::from_naive_utc_and_offset(*datetime, Local::now().offset().to_owned()); local_datetime.format("%Y-%m-%d %H:%M:%S").to_string() } diff --git a/comms/dht/src/envelope.rs b/comms/dht/src/envelope.rs index db72b1fcd9..d287f0bbcc 100644 --- a/comms/dht/src/envelope.rs +++ b/comms/dht/src/envelope.rs @@ -51,7 +51,7 @@ pub(crate) fn datetime_to_timestamp(datetime: DateTime) -> Timestamp { pub(crate) fn timestamp_to_datetime(timestamp: Timestamp) -> Option> { let naive = NaiveDateTime::from_timestamp_opt(timestamp.seconds, u32::try_from(cmp::max(0, timestamp.nanos)).unwrap())?; - Some(DateTime::from_utc(naive, Utc)) + Some(DateTime::from_naive_utc_and_offset(naive, Utc)) } /// Utility function that converts a `chrono::DateTime` to a `EpochTime` @@ -64,7 +64,7 @@ pub(crate) fn datetime_to_epochtime(datetime: DateTime) -> EpochTime { pub(crate) fn epochtime_to_datetime(datetime: EpochTime) -> DateTime { let dt = NaiveDateTime::from_timestamp_opt(i64::try_from(datetime.as_u64()).unwrap_or(i64::MAX), 0) .unwrap_or(NaiveDateTime::MAX); - DateTime::from_utc(dt, Utc) + DateTime::from_naive_utc_and_offset(dt, Utc) } /// Message errors that should be verified by every node diff --git a/comms/dht/src/proto/mod.rs b/comms/dht/src/proto/mod.rs index 9f7c35c419..33b2f4c536 100644 --- a/comms/dht/src/proto/mod.rs +++ b/comms/dht/src/proto/mod.rs @@ -162,7 +162,7 @@ impl TryFrom for IdentitySignature { CommsSecretKey::from_canonical_bytes(&value.signature).map_err(|e| anyhow!("Invalid signature: {}", e))?; let updated_at = NaiveDateTime::from_timestamp_opt(value.updated_at, 0) .ok_or_else(|| anyhow::anyhow!("updated_at overflowed"))?; - let updated_at = DateTime::::from_utc(updated_at, Utc); + let updated_at = DateTime::::from_naive_utc_and_offset(updated_at, Utc); Ok(Self::new(version, Signature::new(public_nonce, signature), updated_at)) } diff --git a/comms/dht/src/store_forward/message.rs b/comms/dht/src/store_forward/message.rs index bdce545204..8ffe8ee47e 100644 --- a/comms/dht/src/store_forward/message.rs +++ b/comms/dht/src/store_forward/message.rs @@ -76,7 +76,10 @@ impl TryFrom for StoredMessage { fn try_from(message: database::StoredMessage) -> Result { let dht_header = DhtHeader::decode(message.header.as_slice())?; Ok(Self { - stored_at: Some(datetime_to_timestamp(DateTime::from_utc(message.stored_at, Utc))), + stored_at: Some(datetime_to_timestamp(DateTime::from_naive_utc_and_offset( + message.stored_at, + Utc, + ))), version: message.version as u32, body: message.body, dht_header: Some(dht_header), diff --git a/comms/dht/src/store_forward/saf_handler/task.rs b/comms/dht/src/store_forward/saf_handler/task.rs index b1fc068f83..fa0d101985 100644 --- a/comms/dht/src/store_forward/saf_handler/task.rs +++ b/comms/dht/src/store_forward/saf_handler/task.rs @@ -424,7 +424,7 @@ where S: Service let stored_at = message .stored_at .map(|t| { - Result::<_, StoreAndForwardError>::Ok(DateTime::from_utc( + Result::<_, StoreAndForwardError>::Ok(DateTime::from_naive_utc_and_offset( NaiveDateTime::from_timestamp_opt(t.seconds, 0).ok_or_else(|| { StoreAndForwardError::InvalidSafResponseMessage { field: "stored_at",