main
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>
clocktime
Time-of-day and ISO 8601 duration types for APIs, GraphQL, and SQL.
Install
go get gitea.auvem.com/go-toolkit/clocktime
ClockTime
ct, err := clocktime.ParseClockTime("09:30:00")
t := ct.Time() // 1970-01-01 UTC anchor
- Strict
HH:MM:SSparsing via [ParseClockTime] - SQL
TIMEcolumns: stored as[]byte/ string; scanned fromtime.Time,[]byte, orstring - Optional fields: use
*ClockTime;IsZero()is true only for nil pointers - Midnight
00:00:00is valid; useIsMidnight()to detect it
ISODuration
d, err := clocktime.ParseISODuration("PT1H30M")
ns := d.Duration()
- JSON/GQL: ISO 8601 strings
- SQL:
int64nanoseconds (strings accepted on scan) - Calendar durations (
P1M,P1Y) convert to approximate nanoseconds and may not round-trip
gqlgen
Both types implement MarshalGQL / UnmarshalGQL.
Description
clocktime provides a calendar independent time of day object in 24-hour format.
Languages
Go
100%