pub fn parse_duration(duration: &str) -> Result<DateTime<Utc>>Expand description
Parse a duration string (e.g., “7d”, “24h”, “30m”) into a DateTime
Supported units:
d: daysh: hoursm: minutess: secondsw: weeks
§Arguments
duration- Duration string in format like “7d”, “24h”, “30m”, “5w”
§Returns
A DateTime representing the current time minus the specified duration
§Errors
Returns InvalidInput error if:
- Duration string is empty or too short
- Number part is not a valid integer
- Unit is not one of d/h/m/s/w
§Examples
ⓘ
use crate::time_utils::parse_duration;
let seven_days_ago = parse_duration("7d").unwrap();
let one_week_ago = parse_duration("1w").unwrap();