• Start

Languages

/

Go

/

API Reference

/

Values

CustomDateTime

The CustomDateTime type wraps time.Time with SurrealDB-compatible CBOR encoding at nanosecond precision.

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

type CustomDateTime struct {
time.Time
}

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

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

Syntax

s := dt.String()

Returns: string

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

Syntax

s := dt.SurrealString()

Returns: string

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

Syntax

zero := dt.IsZero()

Returns: bool

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).

Was this page helpful?