Skip to content

Commit

Permalink
Update deprecated function
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Sep 29, 2023
1 parent 6f8843e commit 52d931d
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl TransactionsTab {
None => String::new(),
Some(mined_timestamp) => format!(
"{}",
DateTime::<Local>::from_utc(mined_timestamp, Local::now().offset().to_owned())
DateTime::<Local>::from_naive_utc_and_offset(mined_timestamp, Local::now().offset().to_owned())
.format("%Y-%m-%d %H:%M:%S")
),
},
Expand Down Expand Up @@ -246,7 +246,7 @@ impl TransactionsTab {
None => String::new(),
Some(mined_timestamp) => format!(
"{}",
DateTime::<Local>::from_utc(mined_timestamp, Local::now().offset().to_owned())
DateTime::<Local>::from_naive_utc_and_offset(mined_timestamp, Local::now().offset().to_owned())
.format("%Y-%m-%d %H:%M:%S")
),
},
Expand Down Expand Up @@ -388,21 +388,23 @@ 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::<Local>::from_utc(tx.mined_timestamp, Local::now().offset().to_owned());
// let mined_time = DateTime::<Local>::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::<Local>::from_utc(mined_timestamp, Local::now().offset().to_owned())
DateTime::<Local>::from_naive_utc_and_offset(mined_timestamp, Local::now().offset().to_owned())
.format("%Y-%m-%d %H:%M:%S")
),
},
// format!("{}", mined_time.format("%Y-%m-%d %H:%M:%S")),
Style::default().fg(Color::White),
);

let imported_time = DateTime::<Local>::from_utc(tx.timestamp, Local::now().offset().to_owned());
let imported_time =
DateTime::<Local>::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),
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/src/ui/ui_contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl From<Contact> for UiContact {
address: c.address.to_hex(),
emoji_id: c.address.to_emoji_string(),
last_seen: match c.last_seen {
Some(val) => DateTime::<Local>::from_utc(val, Local::now().offset().to_owned())
Some(val) => DateTime::<Local>::from_naive_utc_and_offset(val, Local::now().offset().to_owned())
.format("%m-%dT%H:%M")
.to_string(),
None => "".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_miner/src/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Utc>::from_utc(
header.timestamp = (DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDate::from_ymd_opt(2000, 1, 1)
.unwrap()
.and_hms_opt(1, 1, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl CommandContext {
solve_time,
normalized_solve_time,
pow_algo,
chrono::DateTime::<Utc>::from_utc(
chrono::DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(header.header().timestamp.as_u64() as i64, 0).unwrap_or_default(),
Utc
),
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_node/src/commands/command/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl CommandContext {
.get_header(height)
.await?
.ok_or_else(|| anyhow!("No last header"))?;
let last_block_time = DateTime::<Utc>::from_utc(
let last_block_time = DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(last_header.header().timestamp.as_u64() as i64, 0).unwrap_or_default(),
Utc,
);
Expand Down
2 changes: 1 addition & 1 deletion base_layer/contacts/src/contacts_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Display for ContactsLivenessData {
self.address,
self.node_id,
if let Some(time) = self.last_seen {
let local_time = DateTime::<Local>::from_utc(time, Local::now().offset().to_owned())
let local_time = DateTime::<Local>::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)
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/blocks/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl BlockHeader {
pub fn to_chrono_datetime(&self) -> DateTime<Utc> {
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]
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/proof_of_work/sha3x_pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub mod test {
let mut header = BlockHeader::new(2);

#[allow(clippy::cast_sign_loss)]
let epoch_secs = DateTime::<Utc>::from_utc(
let epoch_secs = DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDate::from_ymd_opt(2000, 1, 1)
.unwrap()
.and_hms_opt(1, 1, 1)
Expand Down
7 changes: 4 additions & 3 deletions base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Local>::from_utc(last_seen, Local::now().offset().to_owned())
.format("%FT%T")
.to_string();
let last_seen_local_time =
DateTime::<Local>::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) => {
Expand Down
2 changes: 1 addition & 1 deletion comms/core/src/peer_manager/identity_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl TryFrom<proto::identity::IdentitySignature> 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::<Utc>::from_utc(updated_at, Utc);
let updated_at = DateTime::<Utc>::from_naive_utc_and_offset(updated_at, Utc);

Ok(Self {
version,
Expand Down
2 changes: 1 addition & 1 deletion comms/core/src/utils/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn format_duration(duration: Duration) -> String {
}

pub fn format_local_datetime(datetime: &NaiveDateTime) -> String {
let local_datetime = DateTime::<Local>::from_utc(*datetime, Local::now().offset().to_owned());
let local_datetime = DateTime::<Local>::from_naive_utc_and_offset(*datetime, Local::now().offset().to_owned());
local_datetime.format("%Y-%m-%d %H:%M:%S").to_string()
}

Expand Down
4 changes: 2 additions & 2 deletions comms/dht/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub(crate) fn datetime_to_timestamp(datetime: DateTime<Utc>) -> Timestamp {
pub(crate) fn timestamp_to_datetime(timestamp: Timestamp) -> Option<DateTime<Utc>> {
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`
Expand All @@ -64,7 +64,7 @@ pub(crate) fn datetime_to_epochtime(datetime: DateTime<Utc>) -> EpochTime {
pub(crate) fn epochtime_to_datetime(datetime: EpochTime) -> DateTime<Utc> {
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
Expand Down
2 changes: 1 addition & 1 deletion comms/dht/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl TryFrom<common::IdentitySignature> 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::<Utc>::from_utc(updated_at, Utc);
let updated_at = DateTime::<Utc>::from_naive_utc_and_offset(updated_at, Utc);

Ok(Self::new(version, Signature::new(public_nonce, signature), updated_at))
}
Expand Down
5 changes: 4 additions & 1 deletion comms/dht/src/store_forward/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ impl TryFrom<database::StoredMessage> for StoredMessage {
fn try_from(message: database::StoredMessage) -> Result<Self, Self::Error> {
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),
Expand Down
2 changes: 1 addition & 1 deletion comms/dht/src/store_forward/saf_handler/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ where S: Service<DecryptedDhtMessage, Response = (), Error = PipelineError>
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",
Expand Down

0 comments on commit 52d931d

Please sign in to comment.