jdx/mise · error

Invalid date or duration

Error message

Invalid date or duration: {s}. Expected formats: '2024-06-01', '2024-06-01T12:00:00Z', '90d', '1y'

What it means

`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.

Solutions

  1. Use one of the documented formats: `2024-06-01`, `2024-06-01T12:00:00Z`, `90d`, `1y`
  2. Check for typos like `o` instead of `0` or a trailing space
  3. Convert human phrases to span syntax (`3 weeks` → `21d`)

Example fix

// before
--before "June 1 2024"
// after
--before 2024-06-01
Defensive patterns

Strategy: validation

Validate before calling

function isValidDateOrDuration(s) {
  const span = /^\d+(?:\.\d+)?(?:s|m|h|d|w|mo|y)$/;
  const iso = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}:\d{2}Z?)?$/;
  return span.test(s.trim()) || iso.test(s.trim()) || !Number.isNaN(Date.parse(s));
}

Try / catch

try {
  runMise(['outdated', '--before', raw]);
} catch (e) {
  if (String(e).includes('Invalid date or duration')) {
    const normalized = toSpanOrIso(raw); // convert e.g. '3 weeks' -> '21d'
    runMise(['outdated', '--before', normalized]);
  } else throw e;
}

Prevention

When it happens

Trigger: 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"`.

Common situations: Typos in CLI `--before`/min-age flags; locale-formatted dates; empty or quoted-but-malformed config values; assuming natural language dates are supported.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/9ac32270e996951c. Report an issue: GitHub.

Appendix: source

Thrown at src/duration.rs:90

        let datetime = civil_date.at(23, 59, 59, 0);
        let ts = datetime.to_zoned(jiff::tz::TimeZone::UTC)?.timestamp();
        return Ok(ts);
    }

    // Subtract the duration from `process_now` so the same relative
    // duration resolves to the same absolute Timestamp every time.
    if let Ok(span) = s.parse::<Span>() {
        // Validate that duration is positive (negative would result in future date)
        let duration = span.to_duration(date(2025, 1, 1))?;
        if duration.is_negative() {
            bail!("duration must not be negative: {}", s);
        }
        let now_zoned = process_now().to_zoned(jiff::tz::TimeZone::UTC);
        let past = now_zoned.checked_sub(span)?;
        return Ok(past.timestamp());
    }

    bail!(
        "Invalid date or duration: {s}. Expected formats: '2024-06-01', '2024-06-01T12:00:00Z', '90d', '1y'"
    )
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_process_now_is_stable() {
        let a = process_now();
        std::thread::sleep(std::time::Duration::from_millis(5));
        let b = process_now();
        assert_eq!(a, b);
    }

    #[test]
    fn test_parse_into_timestamp_relative_is_stable() {

View on GitHub (pinned to 533346cc37)