1 | use serde::{Serialize, Deserialize}; |
2 | use chrono::{DateTime, TimeZone, Utc}; |
3 | |
4 | use super::{Condition, AirQuality, Location}; |
5 | |
6 | |
7 | #[derive (Debug, Serialize, Deserialize, PartialEq)] |
8 | pub struct Current { |
9 | pub last_updated: String, |
10 | pub last_updated_epoch: i64, |
11 | pub temp_c: f32, |
12 | pub temp_f: f32, |
13 | pub feelslike_c: f32, |
14 | pub feelslike_f: f32, |
15 | pub condition: Condition, |
16 | pub wind_mph: f32, |
17 | pub wind_kph: f32, |
18 | pub wind_degree: f32, |
19 | pub wind_dir: String, |
20 | pub pressure_mb: f32, |
21 | pub pressure_in: f32, |
22 | pub precip_mm: f32, |
23 | pub precip_in: f32, |
24 | pub humidity: u32, |
25 | pub cloud: u32, |
26 | pub is_day: u8, |
27 | pub uv: f32, |
28 | pub gust_mph: f32, |
29 | pub gust_kph: f32, |
30 | pub air_quality: Option<AirQuality> |
31 | } |
32 | |
33 | impl Current { |
34 | pub fn last_updated(&self) -> DateTime<Utc> { |
35 | Utc.datetime_from_str(&self.last_updated, fmt:"%Y-%m-%d %H:%M" ).unwrap() |
36 | } |
37 | |
38 | pub fn last_updated_epoch(&self) -> DateTime<Utc> { |
39 | Utc.timestamp(self.last_updated_epoch, nsecs:0) |
40 | } |
41 | |
42 | pub fn is_day(&self) -> bool { |
43 | self.is_day == 1 |
44 | } |
45 | } |
46 | |
47 | |
48 | #[derive (Debug, Serialize, Deserialize, PartialEq)] |
49 | pub struct Realtime { |
50 | pub location: Location, |
51 | pub current: Current |
52 | } |
53 | |