MCPcopy Create free account
hub / github.com/Autoparallel/learner / parse_date

Function parse_date

crates/learnerd/src/commands/mod.rs:450–463  ·  view source on GitHub ↗

Parse a date string into a UTC DateTime Supports multiple date formats: - Year only (YYYY) - Year and month (YYYY-MM) - Full date (YYYY-MM-DD) # Arguments `date_str` - Date string to parse # Returns Returns a Result containing either the parsed UTC DateTime or an error if the date format is invalid.

(date_str: &str)

Source from the content-addressed store, hash-verified

448/// Returns a Result containing either the parsed UTC DateTime or an error
449/// if the date format is invalid.
450fn parse_date(date_str: &str) -> Result<DateTime<Utc>> {
451 let parsed = if date_str.len() == 4 {
452 // Just year provided
453 DateTime::parse_from_str(&format!("{}-01-01 00:00:00 +0000", date_str), "%Y-%m-%d %H:%M:%S %z")
454 } else if date_str.len() == 7 {
455 // Year and month provided
456 DateTime::parse_from_str(&format!("{}-01 00:00:00 +0000", date_str), "%Y-%m-%d %H:%M:%S %z")
457 } else {
458 // Full date provided
459 DateTime::parse_from_str(&format!("{} 00:00:00 +0000", date_str), "%Y-%m-%d %H:%M:%S %z")
460 }?;
461
462 Ok(parsed.with_timezone(&Utc))
463}

Callers 2

removeFunction · 0.85
searchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected