summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2023-06-21 15:05:33 +0200
committerEmīls <emils@mullvad.net>2023-06-27 16:01:48 +0200
commit7747e2e5bb755fa50d7b56ed8d9c63647e2ff112 (patch)
tree9af341e8c9db2c74995d986c1eec1bbe4738215d
parenta82fd53421b867a877c1d878368e99999e163aaa (diff)
downloadmullvadvpn-7747e2e5bb755fa50d7b56ed8d9c63647e2ff112.tar.xz
mullvadvpn-7747e2e5bb755fa50d7b56ed8d9c63647e2ff112.zip
Refactor use of deprecated `chrono` timestamp function
Since `chrono 0.4.23`, the use of `chrono::NaiveDateTime::from_timestamp` is deprecated in favor of `chrono::NaiveDateTime::from_timestamp_opt`, which returns an `Option` instead of panicking if number of seconds is out of range.
-rw-r--r--mullvad-management-interface/src/types/conversions/account.rs6
-rw-r--r--mullvad-management-interface/src/types/conversions/device.rs5
-rw-r--r--mullvad-management-interface/src/types/conversions/wireguard.rs3
3 files changed, 9 insertions, 5 deletions
diff --git a/mullvad-management-interface/src/types/conversions/account.rs b/mullvad-management-interface/src/types/conversions/account.rs
index 40c3e797be..4f1f6dc5c2 100644
--- a/mullvad-management-interface/src/types/conversions/account.rs
+++ b/mullvad-management-interface/src/types/conversions/account.rs
@@ -23,7 +23,8 @@ impl TryFrom<types::VoucherSubmission> for VoucherSubmission {
.new_expiry
.ok_or(FromProtobufTypeError::InvalidArgument("missing expiry"))?;
let ndt =
- chrono::NaiveDateTime::from_timestamp(new_expiry.seconds, new_expiry.nanos as u32);
+ chrono::NaiveDateTime::from_timestamp_opt(new_expiry.seconds, new_expiry.nanos as u32)
+ .unwrap();
Ok(VoucherSubmission {
new_expiry: chrono::DateTime::<chrono::Utc>::from_utc(ndt, chrono::Utc),
@@ -50,7 +51,8 @@ impl TryFrom<types::AccountData> for AccountData {
let expiry = data
.expiry
.ok_or(FromProtobufTypeError::InvalidArgument("missing expiry"))?;
- let ndt = chrono::NaiveDateTime::from_timestamp(expiry.seconds, expiry.nanos as u32);
+ let ndt =
+ chrono::NaiveDateTime::from_timestamp_opt(expiry.seconds, expiry.nanos as u32).unwrap();
Ok(AccountData {
expiry: chrono::DateTime::<chrono::Utc>::from_utc(ndt, chrono::Utc),
diff --git a/mullvad-management-interface/src/types/conversions/device.rs b/mullvad-management-interface/src/types/conversions/device.rs
index cd1aeb5e4f..12ae5b0434 100644
--- a/mullvad-management-interface/src/types/conversions/device.rs
+++ b/mullvad-management-interface/src/types/conversions/device.rs
@@ -16,7 +16,7 @@ impl TryFrom<proto::Device> for mullvad_types::device::Device {
.collect(),
hijack_dns: device.hijack_dns,
created: chrono::DateTime::from_utc(
- chrono::NaiveDateTime::from_timestamp(
+ chrono::NaiveDateTime::from_timestamp_opt(
device
.created
.ok_or(FromProtobufTypeError::InvalidArgument(
@@ -24,7 +24,8 @@ impl TryFrom<proto::Device> for mullvad_types::device::Device {
))?
.seconds,
0,
- ),
+ )
+ .unwrap(),
chrono::Utc,
),
})
diff --git a/mullvad-management-interface/src/types/conversions/wireguard.rs b/mullvad-management-interface/src/types/conversions/wireguard.rs
index 29cb8df465..13b94c1d52 100644
--- a/mullvad-management-interface/src/types/conversions/wireguard.rs
+++ b/mullvad-management-interface/src/types/conversions/wireguard.rs
@@ -23,7 +23,8 @@ impl TryFrom<proto::PublicKey> for mullvad_types::wireguard::PublicKey {
.ok_or(FromProtobufTypeError::InvalidArgument(
"missing 'created' timestamp",
))?;
- let ndt = chrono::NaiveDateTime::from_timestamp(created.seconds, created.nanos as u32);
+ let ndt = chrono::NaiveDateTime::from_timestamp_opt(created.seconds, created.nanos as u32)
+ .unwrap();
Ok(mullvad_types::wireguard::PublicKey {
key: talpid_types::net::wireguard::PublicKey::try_from(public_key.key.as_slice())