Fix date parsing (again)
This is still very brittle and maybe i should find a better crate or just use GPT
This commit is contained in:
parent
3b289b5e2f
commit
8a20d43f21
1 changed files with 11 additions and 4 deletions
15
src/main.rs
15
src/main.rs
|
@ -2,7 +2,7 @@ use discord_webhook_rs::Webhook;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::env;
|
use std::env;
|
||||||
use time::macros::format_description;
|
use time::macros::format_description;
|
||||||
use time::{Date, OffsetDateTime};
|
use time::{Date, OffsetDateTime, UtcOffset};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
dotenvy::dotenv().expect("Need a .env file");
|
dotenvy::dotenv().expect("Need a .env file");
|
||||||
|
@ -22,6 +22,8 @@ fn main() {
|
||||||
|
|
||||||
let date = last_announcement.get(1).unwrap().as_str().replace(",", "");
|
let date = last_announcement.get(1).unwrap().as_str().replace(",", "");
|
||||||
|
|
||||||
|
dbg!(&date);
|
||||||
|
|
||||||
let announcements = last_announcement
|
let announcements = last_announcement
|
||||||
.get(2)
|
.get(2)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -38,11 +40,16 @@ fn main() {
|
||||||
|
|
||||||
// println!("{}", pretty_announcements);
|
// println!("{}", pretty_announcements);
|
||||||
|
|
||||||
let description = &format_description!("[weekday] [month repr:long] [day] [year]");
|
let description = &format_description!("[weekday] [month repr:long] [day padding:none] [year]");
|
||||||
let parsed_date = Date::parse(&format!("{} 2025", date), description).unwrap();
|
let parsed_date =
|
||||||
|
Date::parse(&format!("{} 2025", date), description).expect("Date parse failed!");
|
||||||
println!("Date: {:}", parsed_date);
|
println!("Date: {:}", parsed_date);
|
||||||
|
|
||||||
if OffsetDateTime::now_utc().date() != parsed_date {
|
if OffsetDateTime::now_utc()
|
||||||
|
.to_offset(UtcOffset::from_hms(-5, 0, 0).unwrap())
|
||||||
|
.date()
|
||||||
|
!= parsed_date
|
||||||
|
{
|
||||||
println!("Last date is not today!");
|
println!("Last date is not today!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue