sharkdp/fd · error · anyhow::Error

' ' is not a valid date or duration. See 'fd --help'.

Error message

'{}' is not a valid date or duration. See 'fd --help'.

What it means

extract_time_constraints (main.rs:496) parses --changed-within through TimeFilter::after, which tries four parsers in order (filter/time.rs:29): a jiff Span duration (e.g. '1d', '30min'), a Timestamp, a civil DateTime, or '@<unix-secs>'. If all four return None, the value is rejected at main.rs:502 with this message.

Solutions

  1. Use a duration string: `fd --changed-within 1d`, `fd --changed-within 2h30min`, `fd --changed-within 1week`.
  2. Use an ISO datetime or timestamp: `fd --changed-within 2024-01-01`, `fd --changed-within @1700000000`.
  3. Consult `fd --help` for the accepted duration/date grammar.

Example fix

# before
fd --changed-within 5

# after
fd --changed-within 5d      # within last 5 days
fd --changed-within 2h      # within last 2 hours
Defensive patterns

Strategy: validation

Validate before calling

validate_within() {
  # accept jiff span (e.g. 1d, 2h30min), ISO datetime, or @<epoch>
  printf '%s' "$1" | grep -Eq '^(@[0-9]+|[0-9]{4}-[0-9]{2}-[0-9]{2}|[0-9]+[a-z]+)$' \
    && fd --changed-within "$1" \
    || { echo "invalid duration/date" >&2; exit 1; }
}

Prevention

When it happens

Trigger: Passing `fd --changed-within foo`, `fd --changed-within 5` (bare number, no unit), `fd --changed-within 2024-13-99` (bad date), or any value jiff cannot parse as span/timestamp/datetime/@epoch.

Common situations: Forgetting the duration unit; locale-specific date formats jiff doesn't accept; typos; confusing fd's duration grammar with find -mtime days (which is a count, not a duration string).

Related errors


AI-assisted analysis of sharkdp/fd@ee20f426dd (2026-08-09). Data as JSON: /api/errors/bb539ede51511de2. Report an issue: GitHub.

Appendix: source

Thrown at src/main.rs:502

            return Err(anyhow!(
                "'fd --list-details' is not supported on Windows unless GNU 'ls' is installed."
            ));
        }
    } else {
        return Err(anyhow!(
            "'fd --list-details' is not supported on this platform."
        ));
    };
    Ok(cmd)
}

fn extract_time_constraints(opts: &Opts) -> Result<Vec<TimeFilter>> {
    let mut time_constraints: Vec<TimeFilter> = Vec::new();
    if let Some(ref t) = opts.changed_within {
        if let Some(f) = TimeFilter::after(t) {
            time_constraints.push(f);
        } else {
            return Err(anyhow!(
                "'{}' is not a valid date or duration. See 'fd --help'.",
                t
            ));
        }
    }
    if let Some(ref t) = opts.changed_before {
        if let Some(f) = TimeFilter::before(t) {
            time_constraints.push(f);
        } else {
            return Err(anyhow!(
                "'{}' is not a valid date or duration. See 'fd --help'.",
                t
            ));
        }
    }
    Ok(time_constraints)
}

View on GitHub (pinned to ee20f426dd)