Skip to content

Commit a5d04c2

Browse files
committed
impl FromProto<super::Timestamp> for chrono::DateTime<chrono::Utc>
1 parent e2c5299 commit a5d04c2

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

mullvad-proc-macro/tests/struct.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![allow(unused)]
22

3+
use crate::proto::Timestamp;
34
use chrono::DateTime;
45
use mullvad_proc_macro::{IntoProto, UnwrapProto};
5-
use crate::proto::Timestamp;
66

77
#[derive(Debug)]
88
struct RelaySettings;
@@ -97,8 +97,6 @@ impl FromProto<proto::AppVersionInfo> for AppVersionInfo {
9797
}
9898
}
9999

100-
pub type AppVersion = String;
101-
102100
mod proto {
103101
use super::FromProto;
104102
use mullvad_proc_macro::{FromProto, IntoProto};
@@ -111,7 +109,7 @@ mod proto {
111109
pub suggested_upgrade: Option<String>,
112110
}
113111

114-
#[derive(Debug)]
112+
#[derive(Debug, FromProto)]
115113
pub struct Device {
116114
pub created: Timestamp,
117115
}
@@ -123,13 +121,29 @@ mod proto {
123121
}
124122

125123
mod mullvad_types {
124+
use crate::FromProto;
125+
use chrono::TimeZone;
126+
126127
#[derive(Debug)]
127128
pub struct AppVersionInfo {
128129
pub supported: bool,
129130
pub latest_stable: String,
130131
pub latest_beta: String,
131132
pub suggested_upgrade: Option<String>,
132133
}
134+
135+
pub struct Device {
136+
pub created: chrono::DateTime<chrono::Utc>,
137+
}
138+
139+
impl FromProto<super::Timestamp> for chrono::DateTime<chrono::Utc> {
140+
fn from_proto(other: super::Timestamp) -> Self {
141+
let naive_date_time =
142+
chrono::NaiveDateTime::from_timestamp_opt(other.seconds, other.nanos as u32)
143+
.unwrap();
144+
chrono::Utc.from_utc_datetime(&naive_date_time)
145+
}
146+
}
133147
}
134148
}
135149

0 commit comments

Comments
 (0)