Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 51 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ shlex = "1.3" # Shell-like parsing for quoted strings in CLI
reqwest = { version = "0.13", features = ["blocking", "gzip"] } # HTTP client for manifest downloads
flate2 = "1.1" # gzip compression/decompression
chrono = "0.4.44"
chrono-english = "0.1" # Natural language date parsing
interim = { version = "0.2", features = ["chrono_0_4"] } # Natural language date parsing
base64 = "0.22" # Base64 decoding for MIME-encoded email bodies

[[bin]]
Expand Down
27 changes: 13 additions & 14 deletions src/date_utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Date parsing utilities for lore email filtering
//!
//! Uses chrono-english for natural language date parsing, supporting formats like:
//! Uses interim for natural language date parsing, supporting formats like:
//! - Relative: "yesterday", "1 day ago", "2 weeks ago", "3 months ago"
//! - Absolute: "2024-01-01" (YYYY-MM-DD ISO format)
//!
Expand All @@ -16,28 +16,27 @@ use chrono::Utc;
/// The lore table stores dates in RFC 2822 format, so we must convert our
/// filter dates to the same format for SQL string comparison to work.
///
/// Uses chrono-english for flexible natural language date parsing. Examples:
/// Uses interim for flexible natural language date parsing. Examples:
/// - "yesterday", "today", "tomorrow"
/// - "7 days ago", "2 weeks ago", "3 months ago"
/// - "2024-01-15" (YYYY-MM-DD ISO format)
/// - And various other formats supported by chrono-english
/// - And various other formats supported by interim
pub fn parse_date(date_str: &str) -> Result<String> {
let date_str = date_str.trim();

// Use chrono-english to parse the date relative to current time
// Use interim to parse the date relative to current time
let parsed =
chrono_english::parse_date_string(date_str, Utc::now(), chrono_english::Dialect::Us)
.map_err(|e| {
anyhow!(
"Invalid date format: '{}'. Error: {}.\n\
interim::parse_date_string(date_str, Utc::now(), interim::Dialect::Us).map_err(|e| {
anyhow!(
"Invalid date format: '{}'. Error: {}.\n\
Supported formats include:\n\
- 'yesterday', 'today'\n\
- '7 days ago', '2 weeks ago', '3 months ago'\n\
- 'YYYY-MM-DD' (e.g., '2024-01-15')",
date_str,
e
)
})?;
date_str,
e
)
})?;

Ok(parsed.to_rfc2822())
}
Expand Down Expand Up @@ -125,8 +124,8 @@ mod tests {

#[test]
fn test_natural_language_formats() {
// Test additional natural language formats supported by chrono-english
// Note: chrono-english supports many formats, but not all intuitive ones work
// Test additional natural language formats supported by interim
// Note: interim supports many formats, but not all intuitive ones work
let test_cases = vec![
"3 months ago",
"2024-01-15", // Standard ISO format
Expand Down
Loading