diff --git a/energiatili-model/src/measurement.rs b/energiatili-model/src/measurement.rs index 9763969..d403343 100644 --- a/energiatili-model/src/measurement.rs +++ b/energiatili-model/src/measurement.rs @@ -216,7 +216,7 @@ where } fn convert_timestamp(timestamp: i64) -> DateTime { - let naive_date = NaiveDateTime::from_timestamp((timestamp / 1000) as i64, 0); + let naive_date = NaiveDateTime::from_timestamp_opt((timestamp / 1000) as i64, 0).expect("parse NaiveDateTime"); let localtime = match Helsinki.from_local_datetime(&naive_date) { LocalResult::None => panic!("Couldn't convert local time"), LocalResult::Single(t) => t, diff --git a/energiatili-model/src/utils.rs b/energiatili-model/src/utils.rs index 21077f7..11e0adf 100644 --- a/energiatili-model/src/utils.rs +++ b/energiatili-model/src/utils.rs @@ -14,7 +14,7 @@ pub(crate) fn fix_new_date(buf: &str) -> String { // Javascript's "new Date()" supposed to be seconds since UNIX epoch UTC, // but it seems Energiatili's numbers are in finnish timezone instead. - let naive_date = NaiveDateTime::from_timestamp(date_int / 1000, 0); + let naive_date = NaiveDateTime::from_timestamp_opt(date_int / 1000, 0).expect("parse NaiveDateTime"); let localtime = Helsinki.from_local_datetime(&naive_date).unwrap(); let timestamp: DateTime = localtime.with_timezone(&Utc);