2024-02-04 16:09:59 +01:00
|
|
|
use std::io;
|
|
|
|
|
2024-02-04 21:15:15 +01:00
|
|
|
use time::{format_description, OffsetDateTime};
|
|
|
|
|
2024-02-04 16:09:59 +01:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Error {
|
|
|
|
msg: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<ureq::Error> for Error {
|
|
|
|
fn from(value: ureq::Error) -> Self {
|
|
|
|
Self {
|
|
|
|
msg: value.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(value: io::Error) -> Self {
|
|
|
|
Self {
|
|
|
|
msg: value.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl From<serde_json::Error> for Error {
|
|
|
|
fn from(value: serde_json::Error) -> Self {
|
|
|
|
Self {
|
|
|
|
msg: value.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl From<roxmltree::Error> for Error {
|
|
|
|
fn from(value: roxmltree::Error) -> Self {
|
|
|
|
Self {
|
|
|
|
msg: value.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-04 21:15:15 +01:00
|
|
|
|
|
|
|
/// Returns the current date in YYYY-MM-DD format. Needed for RIS API query to get current version of the overview.
|
|
|
|
pub(crate) fn current_date() -> String {
|
|
|
|
let local_date = OffsetDateTime::now_utc();
|
|
|
|
let format = format_description::parse("[year]-[month]-[day]").unwrap(); //unwrap okay, supplied format is fine
|
|
|
|
local_date.format(&format).expect("Failed to format date")
|
|
|
|
}
|