diff --git a/mobile_config/src/gateway_info.rs b/mobile_config/src/gateway_info.rs index b0327b336..30a49b9e4 100644 --- a/mobile_config/src/gateway_info.rs +++ b/mobile_config/src/gateway_info.rs @@ -1,4 +1,4 @@ -use chrono::{DateTime, Utc}; +use chrono::{DateTime, TimeZone, Utc}; use futures::stream::BoxStream; use helium_crypto::PublicKeyBinary; use helium_proto::services::mobile_config::{ @@ -31,7 +31,7 @@ impl GatewayInfo { #[derive(thiserror::Error, Debug)] pub enum GatewayInfoProtoParseError { #[error("Invalid location string: {0}")] - InvalidLocation(String), + InvalidLocation(#[from] std::num::ParseIntError), #[error("Invalid created_at: {0}")] InvalidCreatedAt(u64), #[error("Invalid refreshed_at: {0}")] @@ -45,23 +45,26 @@ impl TryFrom for GatewayInfo { let metadata = if let Some(ref metadata) = info.metadata { Some( u64::from_str_radix(&metadata.location, 16) - .map(|location| GatewayMetadata { location }) - .map_err(|_| { - GatewayInfoProtoParseError::InvalidLocation(metadata.location.clone()) - })?, + .map(|location| GatewayMetadata { location })?, ) } else { None }; let device_type = info.device_type().into(); - let created_at = DateTime::::from_timestamp(info.created_at as i64, 0).ok_or( - GatewayInfoProtoParseError::InvalidCreatedAt(info.created_at), - )?; + let created_at = Utc + .timestamp_opt(info.created_at as i64, 0) + .single() + .ok_or(GatewayInfoProtoParseError::InvalidCreatedAt( + info.created_at, + ))?; - let refreshed_at = DateTime::::from_timestamp(info.refreshed_at as i64, 0).ok_or( - GatewayInfoProtoParseError::InvalidRefreshedAt(info.refreshed_at), - )?; + let refreshed_at = Utc + .timestamp_opt(info.refreshed_at as i64, 0) + .single() + .ok_or(GatewayInfoProtoParseError::InvalidRefreshedAt( + info.refreshed_at, + ))?; Ok(Self { address: info.address.into(), diff --git a/mobile_config/src/gateway_service.rs b/mobile_config/src/gateway_service.rs index 0aaa52bd1..9932f4341 100644 --- a/mobile_config/src/gateway_service.rs +++ b/mobile_config/src/gateway_service.rs @@ -3,7 +3,7 @@ use crate::{ key_cache::KeyCache, telemetry, verify_public_key, GrpcResult, GrpcStreamResult, }; -use chrono::{DateTime, Utc}; +use chrono::{TimeZone, Utc}; use file_store::traits::{MsgVerify, TimestampEncode}; use futures::{ stream::{Stream, StreamExt, TryStreamExt}, @@ -163,7 +163,9 @@ impl mobile_config::Gateway for GatewayService { let (tx, rx) = tokio::sync::mpsc::channel(100); let device_types: Vec = request.device_types().map(|v| v.into()).collect(); - let min_refreshed_at = DateTime::::from_timestamp(request.min_refreshed_at as i64, 0) + let min_refreshed_at = Utc + .timestamp_opt(request.min_refreshed_at as i64, 0) + .single() .ok_or(Status::invalid_argument( "Invalid min_refreshed_at argument", ))?;