Skip to main content

parse_time

Function parse_time 

Source
pub fn parse_time(time_str: &str) -> Result<DateTime<Utc>, TimeError>
Expand description

Parse human-readable time string to DateTime<Utc>.

Supports relative formats:

  • "7d", "7 days" — days ago
  • "2h", "2hr" — hours ago
  • "30m", "30min" — minutes ago
  • "30s" — seconds ago

And absolute formats:

  • "2024-05-01" — date-only (midnight UTC)
  • "2024-05-01 10:00" — date and hour:minute
  • "2024-05-01 10:00:00" — date and hour:minute:second

§Errors

Returns TimeError::EmptyInput, TimeError::UnknownSuffix, TimeError::InvalidNumber, or TimeError::InvalidDate.