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 std::env;
|
||||
use time::macros::format_description;
|
||||
use time::{Date, OffsetDateTime};
|
||||
use time::{Date, OffsetDateTime, UtcOffset};
|
||||
|
||||
fn main() {
|
||||
dotenvy::dotenv().expect("Need a .env file");
|
||||
|
@ -22,6 +22,8 @@ fn main() {
|
|||
|
||||
let date = last_announcement.get(1).unwrap().as_str().replace(",", "");
|
||||
|
||||
dbg!(&date);
|
||||
|
||||
let announcements = last_announcement
|
||||
.get(2)
|
||||
.unwrap()
|
||||
|
@ -38,11 +40,16 @@ fn main() {
|
|||
|
||||
// println!("{}", pretty_announcements);
|
||||
|
||||
let description = &format_description!("[weekday] [month repr:long] [day] [year]");
|
||||
let parsed_date = Date::parse(&format!("{} 2025", date), description).unwrap();
|
||||
let description = &format_description!("[weekday] [month repr:long] [day padding:none] [year]");
|
||||
let parsed_date =
|
||||
Date::parse(&format!("{} 2025", date), description).expect("Date parse failed!");
|
||||
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!");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue