Skip to content

Malformed YYYY-MM-DD produces confusing 'invalid date unit' error #42

Description

@DTTerastar

QA finding: when --since or --until looks like a date but doesn't parse (e.g. 2026-99-99, 2026-02-30, 2026-13-45), time.ParseInLocation fails silently and the value falls through to the relative-date parser (Nd/Nw/Nm/Ny). That parser then Sscanfs the leading digits, sees a non-{d,w,m,y} trailing char, and reports:

$ crono-export nutrition --since 2026-99-99
error: bad --since: invalid date unit "9": use d, w, m, or y

$ crono-export nutrition --since 2026-02-30
error: bad --since: invalid date unit "0": use d, w, m, or y

User typed a date, error talks about Nd/Nw/Nm/Ny "units" — confusing, especially 2026-02-30 (a valid-looking Feb 30 from a leap-year confusion).

Suggested fix in parseDateValue: if the value contains a - after position 0 (i.e., looks date-shaped), surface the time.ParseInLocation error rather than falling through. Something like:

if t, err := time.ParseInLocation(dateLayout, s, today.Location()); err == nil {
    return t, nil
} else if strings.Contains(s[1:], "-") {
    return time.Time{}, fmt.Errorf("invalid date %q: %w (expected YYYY-MM-DD)", s, err)
}

Severity: minor (UX / error message clarity)

Activity

  1. added
    kind:bugObserved behavior diverges from documented behavior.
    area:dates--since / --until parsing and windowing.
    priority:lowPolish, cosmetic, or open-ended discussion with no immediate action.
    on May 19, 2026
  2. Terastar-Paperclip commented on May 19, 2026

    @Terastar-Paperclip
    Contributor

    Triage:

    • kind:bug · area:dates · priority:low
    • Bucket: low under TRIAGE.md — error-message clarity, no incorrect output.
    • Repro is complete; suggested fix (date-shape detect + surface time.ParseInLocation error) is in the body.

    No CONTRACT.md change — date-flag syntax is unchanged. Engineering ownership.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:dates--since / --until parsing and windowing.kind:bugObserved behavior diverges from documented behavior.priority:lowPolish, cosmetic, or open-ended discussion with no immediate action.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions