proper datetime
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m13s
CI/CD Pipeline / deploy (push) Successful in 1m16s

This commit is contained in:
Philipp Hofer
2025-10-13 15:27:29 +02:00
parent 6c84f98c31
commit bbc8cf2c80

View File

@@ -1,4 +1,4 @@
use chrono::NaiveDate; use chrono::DateTime;
use serde_json::Value; use serde_json::Value;
pub struct Feed { pub struct Feed {
@@ -50,13 +50,17 @@ impl Feed {
ret.push_str(&format!( ret.push_str(&format!(
"<title>{} ({})</title>", "<title>{} ({})</title>",
episode.title, episode.title,
episode.date.format("%d. %m.") episode.timestamp.format("%d.%m.")
)); ));
ret.push_str(&format!( ret.push_str(&format!(
"<enclosure url=\"{}\" length=\"0\" type=\"audio/mpeg\"/>\n", "<enclosure url=\"{}\" length=\"0\" type=\"audio/mpeg\"/>\n",
quick_xml::escape::escape(&episode.media_url) quick_xml::escape::escape(&episode.media_url)
)); ));
ret.push_str("<description>Journal</description>"); ret.push_str("<description>Journal</description>");
ret.push_str(&format!(
"<pubDate>{}</pubDate>",
episode.timestamp.to_rfc2822()
));
ret.push_str("</item>"); ret.push_str("</item>");
} }
@@ -98,7 +102,7 @@ pub struct Broadcast {
pub url: String, pub url: String,
pub media_url: String, pub media_url: String,
pub title: String, pub title: String,
pub date: NaiveDate, pub timestamp: DateTime<chrono::Utc>,
} }
impl Broadcast { impl Broadcast {
@@ -121,20 +125,22 @@ impl Broadcast {
return Err(format!("{url} has no title").into()); return Err(format!("{url} has no title").into());
}; };
let Some(date) = data["broadcastDay"].as_number() else { let Some(timestamp) = data["start"].as_number() else {
return Err(format!("{url} has no broadcastDay").into()); return Err(format!("{url} has no start").into());
}; };
let Ok(date) = NaiveDate::parse_from_str(&date.to_string(), "%Y%m%d") else { let Some(timestamp) = DateTime::from_timestamp(timestamp.as_i64().unwrap() / 1000, 0)
return Err( else {
format!("broadcastDay in {url} not in a valid format (%Y%m%d): {date}").into(), return Err(format!(
); "broadcastDay in {url} not in a valid format (unix timestamp): {timestamp}"
)
.into());
}; };
Ok(Some(Self { Ok(Some(Self {
url, url,
media_url, media_url,
title: title.into(), title: title.into(),
date, timestamp,
})) }))
} }
} }