{"record":{"id":"9ac32270e996951c","repo":"jdx/mise","slug":"invalid-date-or-duration-s-expected-formats","errorCode":null,"errorMessage":"Invalid date or duration: {s}. Expected formats: '2024-06-01', '2024-06-01T12:00:00Z', '90d', '1y'","messagePattern":"Invalid date or duration: (.+?)\\. Expected formats: '2024-06-01', '2024-06-01T12:00:00Z', '90d', '1y'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/duration.rs","lineNumber":90,"sourceCode":"        let datetime = civil_date.at(23, 59, 59, 0);\n        let ts = datetime.to_zoned(jiff::tz::TimeZone::UTC)?.timestamp();\n        return Ok(ts);\n    }\n\n    // Subtract the duration from `process_now` so the same relative\n    // duration resolves to the same absolute Timestamp every time.\n    if let Ok(span) = s.parse::<Span>() {\n        // Validate that duration is positive (negative would result in future date)\n        let duration = span.to_duration(date(2025, 1, 1))?;\n        if duration.is_negative() {\n            bail!(\"duration must not be negative: {}\", s);\n        }\n        let now_zoned = process_now().to_zoned(jiff::tz::TimeZone::UTC);\n        let past = now_zoned.checked_sub(span)?;\n        return Ok(past.timestamp());\n    }\n\n    bail!(\n        \"Invalid date or duration: {s}. Expected formats: '2024-06-01', '2024-06-01T12:00:00Z', '90d', '1y'\"\n    )\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    #[test]\n    fn test_process_now_is_stable() {\n        let a = process_now();\n        std::thread::sleep(std::time::Duration::from_millis(5));\n        let b = process_now();\n        assert_eq!(a, b);\n    }\n\n    #[test]\n    fn test_parse_into_timestamp_relative_is_stable() {","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/duration.rs#L72-L108","documentation":"`parse_into_timestamp` accepts only relative jiff spans (`90d`, `1y`) or absolute dates (ISO `2024-06-01`, RFC3339 `2024-06-01T12:00:00Z`). If the input matches neither grammar (span parse fails and it's not a valid date), this bail lists all accepted formats.","triggerScenarios":"Calling `parse_into_timestamp` with a string that is neither a jiff `Span`, nor an ISO/RFC3339 date — e.g. `\"3 weeks\"`, `\"June 2024\"`, `\"abc\"`.","commonSituations":"Typos in CLI `--before`/min-age flags; locale-formatted dates; empty or quoted-but-malformed config values; assuming natural language dates are supported.","solutions":["Use one of the documented formats: `2024-06-01`, `2024-06-01T12:00:00Z`, `90d`, `1y`","Check for typos like `o` instead of `0` or a trailing space","Convert human phrases to span syntax (`3 weeks` → `21d`)"],"exampleFix":"// before\n--before \"June 1 2024\"\n// after\n--before 2024-06-01","handlingStrategy":"validation","validationCode":"function isValidDateOrDuration(s) {\n  const span = /^\\d+(?:\\.\\d+)?(?:s|m|h|d|w|mo|y)$/;\n  const iso = /^\\d{4}-\\d{2}-\\d{2}(?:[T ]\\d{2}:\\d{2}:\\d{2}Z?)?$/;\n  return span.test(s.trim()) || iso.test(s.trim()) || !Number.isNaN(Date.parse(s));\n}","typeGuard":null,"tryCatchPattern":"try {\n  runMise(['outdated', '--before', raw]);\n} catch (e) {\n  if (String(e).includes('Invalid date or duration')) {\n    const normalized = toSpanOrIso(raw); // convert e.g. '3 weeks' -> '21d'\n    runMise(['outdated', '--before', normalized]);\n  } else throw e;\n}","preventionTips":["Stick to the four documented formats: '2024-06-01', RFC3339, '90d', '1y'","Avoid natural-language dates in flags and configs","Add CLI flag validation in wrapper scripts"],"tags":["duration","date","parse"],"backgroundTag":"invalid-date-format","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}