a1284075aa
Validate constructors, strict HH:MM:SS parse, UTC ClockTimeFromTime, ISODuration Value/Scan, Compare and TextMarshaler, codec.go split. Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
890 B
Markdown
37 lines
890 B
Markdown
# clocktime
|
|
|
|
Time-of-day and ISO 8601 duration types for APIs, GraphQL, and SQL.
|
|
|
|
## Install
|
|
|
|
```bash
|
|
go get gitea.auvem.com/go-toolkit/clocktime
|
|
```
|
|
|
|
## ClockTime
|
|
|
|
```go
|
|
ct, err := clocktime.ParseClockTime("09:30:00")
|
|
t := ct.Time() // 1970-01-01 UTC anchor
|
|
```
|
|
|
|
- Strict `HH:MM:SS` parsing via [ParseClockTime]
|
|
- SQL `TIME` columns: stored as `[]byte` / string; scanned from `time.Time`, `[]byte`, or `string`
|
|
- Optional fields: use `*ClockTime`; `IsZero()` is true only for nil pointers
|
|
- Midnight `00:00:00` is valid; use `IsMidnight()` to detect it
|
|
|
|
## ISODuration
|
|
|
|
```go
|
|
d, err := clocktime.ParseISODuration("PT1H30M")
|
|
ns := d.Duration()
|
|
```
|
|
|
|
- JSON/GQL: ISO 8601 strings
|
|
- SQL: `int64` nanoseconds (strings accepted on scan)
|
|
- Calendar durations (`P1M`, `P1Y`) convert to approximate nanoseconds and may not round-trip
|
|
|
|
## gqlgen
|
|
|
|
Both types implement `MarshalGQL` / `UnmarshalGQL`.
|