Debian Codegraph @

debian/rust-vendor/parse_datetime/CLAUDE.md

raw
1 # CLAUDE.md
2
3 This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
5 ## Project Overview
6
7 `parse_datetime` is a Rust crate (part of the [uutils](https://github.com/uutils) project) that parses human-readable date/time strings into jiff `Zoned` objects. It aims for GNU `date` compatibility. Formerly called `humantime_to_duration`.
8
9 ## Build & Test Commands
10
11 Use `-q` on `cargo` to suppress compilation output and keep logs cheap.
12
13 ```bash
14 cargo build -q # Build
15 cargo test -q # Run all tests
16 cargo test -q <test_name> # Run a single test
17 cargo test -q --lib # Run unit tests only (in src/)
18 cargo test -q --test time # Run a specific integration test file
19 ```
20
21 ### Fuzzer
22
23 ```bash
24 cd fuzz && cargo +nightly fuzz run -q fuzz_parse_datetime -- -verbosity=0
25 ```
26
27 ## Architecture
28
29 The crate exposes two public functions (`parse_datetime` and `parse_datetime_at_date` in `src/lib.rs`) that delegate to the internal parsing engine in `src/items/`.
30
31 ### Parsing Pipeline
32
33 1. **`src/items/mod.rs`** — Top-level parser. Uses [winnow](https://docs.rs/winnow) combinators to parse input into a sequence of `Item` variants (Date, Time, Relative, Weekday, Offset, Timestamp, etc.). The grammar is documented in the `parse()` function's doc comment.
34
35 2. **`src/items/*.rs`** — Each module parses one item type matching the GNU date spec:
36 - `combined` — combined date+time (e.g. ISO 8601)
37 - `date` — calendar dates (ISO, US, literal month formats)
38 - `time` — time of day (24h, 12h/meridiem)
39 - `relative` — relative durations ("3 days", "yesterday", "ago")
40 - `weekday` — day-of-week items with optional ordinals ("next thursday")
41 - `offset` — named timezone offsets ("UTC+07:00")
42 - `timezone` — TZ rule parsing (`TZ="Europe/Paris"`)
43 - `epoch` — unix timestamps ("@1234567890")
44 - `pure` — bare digit strings (interpreted as year or HHMM)
45 - `year` — standalone year parsing
46 - `primitive` — shared low-level parsers (digits, whitespace)
47 - `ordinal` — text/numeric ordinals ("first", "next", "+3")
48
49 3. **`src/items/builder.rs`** — `DateTimeBuilder` collects parsed items and resolves them against a base date/time to produce a final `Zoned`. The `TryFrom<Vec<Item>>` impl enforces constraints (e.g. no duplicate dates/times).
50
51 ### Testing
52
53 - **Unit tests** live alongside source in `src/lib.rs` and `src/items/mod.rs`
54 - **Integration tests** in `tests/time.rs` and `tests/date.rs` use `rstest` for parameterized tests; expected values come from GNU `date` output
55 - Test helper in `tests/common/mod.rs`
56
57 ### Key Dependencies
58
59 - **jiff** — timezone-aware datetime library (replaces chrono)
60 - **winnow** — parser combinator framework (fork/successor of nom)
61 - **rstest** — parameterized test framework (dev only)
62
63 ## Shared conventions
64
65 @../coreutils-claude/common/coding-style.md
66 @../coreutils-claude/common/ci.md
67 @../coreutils-claude/common/testing.md
68 @../coreutils-claude/common/code.md
69 @../coreutils-claude/common/commit.md