{"id":"bb539ede51511de2","repo":"sharkdp/fd","slug":"is-not-a-valid-date-or-duration-see-fd-he","errorCode":null,"errorMessage":"'{}' is not a valid date or duration. See 'fd --help'.","messagePattern":"'(.+?)' is not a valid date or duration\\. See 'fd --help'\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":502,"sourceCode":"            return Err(anyhow!(\n                \"'fd --list-details' is not supported on Windows unless GNU 'ls' is installed.\"\n            ));\n        }\n    } else {\n        return Err(anyhow!(\n            \"'fd --list-details' is not supported on this platform.\"\n        ));\n    };\n    Ok(cmd)\n}\n\nfn extract_time_constraints(opts: &Opts) -> Result<Vec<TimeFilter>> {\n    let mut time_constraints: Vec<TimeFilter> = Vec::new();\n    if let Some(ref t) = opts.changed_within {\n        if let Some(f) = TimeFilter::after(t) {\n            time_constraints.push(f);\n        } else {\n            return Err(anyhow!(\n                \"'{}' is not a valid date or duration. See 'fd --help'.\",\n                t\n            ));\n        }\n    }\n    if let Some(ref t) = opts.changed_before {\n        if let Some(f) = TimeFilter::before(t) {\n            time_constraints.push(f);\n        } else {\n            return Err(anyhow!(\n                \"'{}' is not a valid date or duration. See 'fd --help'.\",\n                t\n            ));\n        }\n    }\n    Ok(time_constraints)\n}\n","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/sharkdp/fd/blob/41532d114e2ba565fb5367d606c111b29b96450c/src/main.rs#L484-L520","documentation":"Thrown by extract_time_constraints in src/main.rs:502 when TimeFilter::after(opts.changed_within) returns None. TimeFilter::from_str tries, in order: a jiff Span (duration like '1d2h'), a Timestamp, a civil DateTime, and an '@<unix-secs>' epoch form; if none parse, the --changed-within value is invalid.","triggerScenarios":"Passing 'fd --changed-within foo', 'fd --changed-within 5' (bare number, no unit — jiff Span requires units), or a date string jiff cannot parse.","commonSituations":"Assuming a bare integer means days; locale-specific date formats jiff rejects; copy-pasting ISO strings with stray whitespace.","solutions":["Use a jiff duration: 'fd --changed-within 1d' or 'fd --changed-within 2h30m'.","Use a date/datetime: 'fd --changed-within 2024-01-01' or 'fd --changed-within \"2024-01-01T12:00:00\"'.","Use an epoch: 'fd --changed-within @1700000000'. Consult 'fd --help' for accepted formats."],"exampleFix":"// before\nfd --changed-within 5\n\n// after\nfd --changed-within 5d","handlingStrategy":"validation","validationCode":"# accept a jiff duration (e.g. 1d2h), a date, or @<epoch>\nif ! printf '%s' \"$CW\" | grep -Eq '^@?[0-9]+[dhms]?[0-9]*[a-z]*$|^[0-9]{4}-[0-9]{2}-[0-9]{2}'; then\n  echo \"invalid --changed-within: $CW\" >&2; exit 1\nfi\nfd --changed-within \"$CW\"","typeGuard":"fn parses_as_jiff_time(s: &str) -> bool {\n    use jiff::{Span, Timestamp, civil::DateTime};\n    s.parse::<Span>().is_ok()\n        || s.parse::<Timestamp>().is_ok()\n        || s.parse::<DateTime>().is_ok()\n        || s.strip_prefix('@').map_or(false, |n| n.parse::<u64>().is_ok())\n}","tryCatchPattern":null,"preventionTips":["Always include a unit for durations (1d, 2h, 30m, 45s).","Use ISO dates or '@epoch' for absolute cutoffs.","Reject bare integers upstream — they never parse as a Span."],"tags":["time-filter","parsing","cli-flag","jiff"],"analyzedSha":"41532d114e2ba565fb5367d606c111b29b96450c","analyzedAt":"2026-08-06T01:39:28.509Z","schemaVersion":2}