CustomDuration
The CustomDuration struct wraps Go's time.Duration and handles CBOR encoding with tag 14 as specified by SurrealDB. It stores durations as a [seconds, nanoseconds] pair and formats them using SurrealDB's human-readable syntax (e.g., 1d2h30m).
Package: github.com/surrealdb/surrealdb.go/pkg/models
Source: pkg/models/duration.go
Definition
CustomDuration embeds time.Duration, so all standard time.Duration methods are available directly.
Methods
.String()
Returns the duration formatted in SurrealDB syntax (e.g., 2h30m, 1d12h, 500ms).
Returns: string
.ToCustomDurationString()
Converts to a CustomDurationString value.
Returns: CustomDurationString
Related Types
CustomDurationString
A string type for durations in SurrealDB format (e.g., "1d2h30m"). Encoded with CBOR tag 13.
Methods
.String()— returns the string value.ToDuration()— parses intotime.Duration.ToCustomDuration()— converts toCustomDuration
Helper Functions
FormatDuration
Formats nanoseconds into SurrealDB duration syntax.
Returns: string
ParseDuration
Parses a SurrealDB duration string into nanoseconds.
Returns: (int64, error)
Supported units: y, w, d, h, m, s, ms, us/µs, ns.
Usage
See Also
RecordID for the record identifier type
CustomDateTime for the datetime type
Value types for the full type mapping
Data manipulation for using duration values in CRUD operations
SurrealQL duration type for the underlying data model