refactored into impl and added get validity function
This commit is contained in:
parent
2878cbc595
commit
c2c83ff66f
1 changed files with 47 additions and 14 deletions
|
|
@ -1,16 +1,25 @@
|
|||
use chrono::NaiveDateTime;
|
||||
use regex::Regex;
|
||||
|
||||
pub struct Notice {
|
||||
pub affected_lines: Vec<String>,
|
||||
pub dest_1: String,
|
||||
pub dest_2: String,
|
||||
pub headline: String,
|
||||
pub detail: String,
|
||||
pub from: u32,
|
||||
pub to: u32,
|
||||
pub from: Option<NaiveDateTime>,
|
||||
pub to: Option<NaiveDateTime>,
|
||||
pub last_modified: String,
|
||||
}
|
||||
|
||||
pub fn get_line_color(line_number: &str) -> (u8, u8, u8) {
|
||||
match line_number {
|
||||
impl Notice {
|
||||
pub fn get_line_color(&self) -> (u8, u8, u8) {
|
||||
match self
|
||||
.affected_lines
|
||||
.first()
|
||||
.expect("Does not affect any line")
|
||||
.as_str()
|
||||
{
|
||||
// Rot: Linien 1, 2, 8
|
||||
"1" | "2" | "8" => (238, 66, 36),
|
||||
|
||||
|
|
@ -26,4 +35,28 @@ pub fn get_line_color(line_number: &str) -> (u8, u8, u8) {
|
|||
// Fallback (z.B. für das Standard-Blau aus deiner API)
|
||||
_ => (55, 101, 174),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_validity_period(&mut self) {
|
||||
let re = Regex::new(
|
||||
r"Gültig ab (\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}) bis (\d{2}\.\d{2}\.\d{4} \d{2}:\d{2})",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
if let Some(caps) = re.captures(&self.detail) {
|
||||
let valid_from = caps.get(1).unwrap().as_str();
|
||||
let valid_to = caps.get(1).unwrap().as_str();
|
||||
let format = "%d.%m.%Y %H:%M";
|
||||
|
||||
if let (Ok(start_dt), Ok(end_dt)) = (
|
||||
NaiveDateTime::parse_from_str(valid_from, format),
|
||||
NaiveDateTime::parse_from_str(valid_to, format),
|
||||
) {
|
||||
self.from = Some(start_dt);
|
||||
self.to = Some(end_dt);
|
||||
}
|
||||
} else {
|
||||
println!("No validity period found in the text.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue