timestamp

package
v0.0.0-...-abd3a35 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package timestamp handles converting time.Time values to unambiguous string and byte representations.

Package timestamp handles values roughly between 1678 and 2262, the time range that can be represented as nanoseconds from the Unix epoch (1970) within an int64. Timestamps for times/dates outside this range are undefined.

Index

Constants

MaxLen is the maximum number of bytes a Timestamp will occupy when converted to a binary representation.

Variables

View Source
var (
	// Earliest is the earliest time that can be converted into a timestamp.
	// Converting times before Earliest into a Timestamp yields undefined
	// behavior. This applies to the zero time.Time{}.
	Earliest = time.Unix(0, math.MinInt64)

	// Latest is the latest time that can be converted into a timestamp.
	// Converting times before Earliest into a Timestamp yields undefined
	// behavior.
	Latest = time.Unix(0, math.MaxInt64)
)

Functions

func FromBytes

func FromBytes(buf []byte) (time.Time, int)

FromBytes decodes a time.Time object from buf and returns the object and the number of bytes read (> 0). If an error occurred, the value is time.Time(0) and the number of bytes n is <= 0 with the following meaning:

 n == 0: buf too small
	n  < 0: value larger than 64 bits (overflow)
	        and -n is the number of bytes read

A variable-length encoding is expected; smaller values require fewer bytes. For a specification, see https://developers.google.com/protocol-buffers/docs/encoding.

func FromString

func FromString(t string) (time.Time, error)

FromString decodes a time.Time object from a string containing an integer number of UTC nanoseconds from the Unix epoch.

func ToBytes

func ToBytes(buf []byte, t time.Time) int

ToBytes encodes a time.Time object to a little-endian binary integer number of UTC nanoseconds from the Unix epoch, writes the result to a buffer and returns the number of bytes written. toBytes panics if the buffer is too small.

A variable-length encoding is used; smaller values require fewer bytes. For a specification, see https://developers.google.com/protocol-buffers/docs/encoding.

func ToString

func ToString(t time.Time) string

ToString encodes a time.Time object to a string containing an integer number of UTC nanoseconds from the Unix epoch.

Types

This section is empty.

Jump to

Keyboard shortcuts

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