timezone correction
This commit is contained in:
parent
fe396a394b
commit
904f89f1b4
3 changed files with 8 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -522,6 +522,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
name = "hello-ratatui"
|
name = "hello-ratatui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"imap",
|
"imap",
|
||||||
"native-tls",
|
"native-tls",
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,4 @@ imap = "2.4"
|
||||||
native-tls = "0.2"
|
native-tls = "0.2"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
toml = "1.0"
|
toml = "1.0"
|
||||||
regex = "1.12"
|
chrono = "0.4"
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use regex::Regex;
|
use chrono::{DateTime, FixedOffset, Local};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::connect::ImapSession;
|
use crate::connect::ImapSession;
|
||||||
use crate::{connect, Email};
|
use crate::{connect, Email};
|
||||||
|
|
@ -77,7 +77,11 @@ fn parse_emails(fetches: &[imap::types::Fetch]) -> Vec<Email> {
|
||||||
} else if let Some(val) = line.strip_prefix("From: ") {
|
} else if let Some(val) = line.strip_prefix("From: ") {
|
||||||
from = val.to_string();
|
from = val.to_string();
|
||||||
} else if let Some(val) = line.strip_prefix("Date: ") {
|
} else if let Some(val) = line.strip_prefix("Date: ") {
|
||||||
date = Regex::new(r#" \(...\)$"#).unwrap().replace_all(val, "").to_string();
|
date = DateTime::parse_from_rfc2822(val)
|
||||||
|
.map(|dt: DateTime<FixedOffset>| {
|
||||||
|
dt.with_timezone(&Local).format("%Y-%m-%d %H:%M").to_string()
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|_| val.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue