Skip to content

Commit 62a55da

Browse files
committed
Changed time format to exclude timezone, since it is discarded anyway
1 parent 64ee2c0 commit 62a55da

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/events.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ use std::fs;
22
use std::path::Path;
33

44
use anyhow::Context as _;
5-
use chrono::{DateTime, FixedOffset};
6-
use serde::Deserialize;
5+
use chrono::NaiveDateTime;
6+
use serde::{Deserialize, Serialize};
77

88
use crate::generate_ics::{EventStatus, SoonToBeIcsEvent};
99

10-
#[derive(Deserialize, Debug)]
10+
#[derive(Serialize, Deserialize, Debug)]
1111
#[serde(rename_all = "PascalCase")]
1212
pub struct EventEntry {
1313
pub name: String,
1414
pub location: String,
1515
pub description: String,
16-
pub start_time: DateTime<FixedOffset>,
17-
pub end_time: DateTime<FixedOffset>,
16+
pub start_time: NaiveDateTime,
17+
pub end_time: NaiveDateTime,
1818
}
1919

2020
pub const FOLDER: &str = "eventfiles";
@@ -32,8 +32,8 @@ pub fn read(name: &str) -> anyhow::Result<Vec<EventEntry>> {
3232
impl From<EventEntry> for SoonToBeIcsEvent {
3333
fn from(event: EventEntry) -> Self {
3434
Self {
35-
start_time: event.start_time.naive_local(),
36-
end_time: event.end_time.naive_local(),
35+
start_time: event.start_time,
36+
end_time: event.end_time,
3737
name: event.name.clone(),
3838
pretty_name: event.name,
3939
status: EventStatus::Confirmed,
@@ -46,20 +46,26 @@ impl From<EventEntry> for SoonToBeIcsEvent {
4646

4747
#[test]
4848
fn can_deserialize_event_entry() -> Result<(), serde_json::Error> {
49+
use chrono::DateTime;
50+
4951
let test: EventEntry = serde_json::from_str(
50-
r#"{"Name": "BTI1-TI", "Location": "1060", "Description": "Dozent: HTM", "StartTime": "2022-01-13T11:40:00+01:00", "EndTime": "2022-01-13T12:00:00+01:00"}"#,
52+
r#"{"Id": "1", "Name": "BTI1-TI", "Location": "1060", "Description": "Dozent: HTM", "StartTime": "2022-01-13T11:40:00", "EndTime": "2022-01-13T12:00:00"}"#,
5153
)?;
5254

5355
assert_eq!(test.name, "BTI1-TI");
5456
assert_eq!(test.location, "1060");
5557
assert_eq!(test.description, "Dozent: HTM");
5658
assert_eq!(
5759
test.start_time,
58-
DateTime::parse_from_rfc3339("2022-01-13T11:40:00+01:00").unwrap()
60+
DateTime::parse_from_rfc3339("2022-01-13T11:40:00+00:00")
61+
.unwrap()
62+
.naive_local()
5963
);
6064
assert_eq!(
6165
test.end_time,
62-
DateTime::parse_from_rfc3339("2022-01-13T12:00:00+01:00").unwrap()
66+
DateTime::parse_from_rfc3339("2022-01-13T12:00:00+00:00")
67+
.unwrap()
68+
.naive_local()
6369
);
6470

6571
Ok(())

0 commit comments

Comments
 (0)