CustomDateTime

The CustomDateTime struct wraps Go's time.Time and handles CBOR encoding with tag 12 as specified by SurrealDB. It preserves nanosecond precision and stores datetimes as a [seconds, nanoseconds] pair.

Package: github.com/surrealdb/surrealdb.go/pkg/models

Source: pkg/models/datetime.go

Definition

type CustomDateTime struct {
time.Time
}

CustomDateTime embeds time.Time, so all standard time.Time methods are available directly.

Methods

.String()

Returns the datetime formatted as "2006-01-02T15:04:05Z" in UTC.

Syntax

s := dt.String()

Returns: string

.SurrealString()

Returns the SurrealQL representation: <datetime> '2006-01-02T15:04:05Z'.

Syntax

s := dt.SurrealString()

Returns: string

.IsZero()

Returns true if the datetime is nil or the zero time.

Syntax

zero := dt.IsZero()

Returns: bool

Usage

import "github.com/surrealdb/surrealdb.go/pkg/models"

now := models.CustomDateTime{Time: time.Now()}

type Event struct {
ID *models.RecordID `json:"id,omitempty"`
CreatedAt models.CustomDateTime `json:"created_at"`
}

Zero-valued CustomDateTime is encoded as CBOR tag 6 (NONE).

See Also