awstime

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package awstime provides helpers for emitting timestamps in the wire format expected by AWS JSON-protocol SDK deserializers.

The AWS "json" and "rest-json" protocols default to the unixTimestamp timestamp format, which serializes a point in time as a JSON number of seconds since the Unix epoch (with optional fractional milliseconds). The SDK deserializers reject RFC3339 strings for these shapes with an error of the form "expected Timestamp to be a JSON Number, got string instead".

Use Epoch to convert a time.Time into a value that json.Marshal renders as the correct numeric wire form.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Epoch

func Epoch(t time.Time) float64

Epoch converts t into seconds since the Unix epoch, preserving sub-second precision as a fractional component. The returned float64 is rendered by encoding/json as a JSON number, matching the unixTimestamp format used by the AWS json and rest-json protocols.

A zero time.Time returns 0, matching AWS behavior of omitting unset timestamps (callers that must omit the field entirely should guard on t.IsZero() before adding it to the response).

Types

type EpochTime

type EpochTime struct{ time.Time }

EpochTime is a time.Time that marshals to and from epoch-seconds JSON numbers, so a model struct can be persisted and sent on the wire in the unixTimestamp form without a separate DTO.

func NewEpochTime

func NewEpochTime(t time.Time) EpochTime

NewEpochTime wraps t.

func (EpochTime) MarshalJSON

func (t EpochTime) MarshalJSON() ([]byte, error)

MarshalJSON renders the time as epoch seconds.

func (*EpochTime) UnmarshalJSON

func (t *EpochTime) UnmarshalJSON(data []byte) error

UnmarshalJSON parses an epoch-seconds number; null leaves the zero time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL