Skip to content

Commit 39a8e99

Browse files
committed
fix date parsing
1 parent a7eccf3 commit 39a8e99

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/modules/lessons.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,19 @@ impl Lesson {
376376
let text = text.replace(" ", "").trim().to_string();
377377
let text = text.replace("bis ", "").trim().to_string();
378378
let text = text.replace("um", "").trim().to_string();
379+
let text = text.replace(",", "").trim().to_string();
380+
let text = text.replace(" den", "").trim().to_string();
381+
let text = text.replace(" Uhr", "").trim().to_string();
382+
let split = text.split(" ");
383+
let date = format!(
384+
"{}{}",
385+
split.clone().nth(1).unwrap_or_default(),
386+
chrono::Local::now().year(),
387+
);
388+
let time = format!("{}:00", split.last().unwrap_or_default());
389+
println!("text is: {}", text);
379390

380-
date_time_string_to_datetime(text.as_str(), "02:00:00")
391+
date_time_string_to_datetime(date.as_str(), time.as_str())
381392
.map_err(|e| {
382393
Error::DateTime(format!(
383394
"failed to convert date to DateTime '{:?}'",
@@ -1383,6 +1394,9 @@ pub async fn get_lessons(account: &Account) -> Result<Vec<Lesson>, Error> {
13831394
let topic_title =
13841395
collect_text(school_class.select(&topic_title_selector).next())
13851396
.unwrap_or("".to_string());
1397+
if topic_title.is_empty() {
1398+
continue;
1399+
}
13861400

13871401
let teacher_short_selector = Selector::parse(
13881402
".teacher .btn.btn-primary.dropdown-toggle.btn-xs",

src/utils/datetime.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ pub(crate) fn date_time_string_to_datetime(
5555
DateTime::parse_from_str(&format!("{} {} +02:00", date, time), "%d.%m.%Y %H:%M:%S %z")
5656
.map_err(|e| {
5757
DateTimeError::DateTimeInvalid(format!(
58-
"converting '{} {}') +02:00 failed with error '{}'",
58+
"converting '{} {}' +02:00 failed with error '{}'",
5959
date, time, e
6060
))
61-
})?;
61+
})
62+
.unwrap();
6263
Ok(date_time)
6364
}
6465

0 commit comments

Comments
 (0)