Help us shape the future of Go! Take the 2026 Go Developer Survey

compact_time

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2019 License: MIT Imports: 4 Imported by: 11

README

Compact Time

A go implementation of compact time.

Library Usage

func demonstrateEncode() {
	location, err := time.LoadLocation("Asia/Singapore")
	if err != nil {
		// TODO: Deal with this
	}
	date := time.Date(2020, time.Month(8), 30, 15, 33, 14, 19577323, location)
	buffer := make([]byte, TimestampEncodedSize(date))
	encodedCount, ok, err := EncodeTimestamp(date, buffer)
	if err != nil {
		// TODO: Handle error
	}
	if !ok {
		// TODO: Not enough room in buffer to encode
	}
	fmt.Printf("Encoded [%v] into %v bytes: %v\n", date, encodedCount, buffer)
	// Prints: Encoded [2020-08-30 15:33:14.019577323 +0800 +08] into 21 bytes: [59 225 243 184 158 171 18 0 80 22 83 47 83 105 110 103 97 112 111 114 101]
}
func demonstrateDecode() {
	buffer := []byte{0x14, 0x4d, 0x09, 0x1c, 0x07}
	date, decodedCount, ok, err := DecodeTimestamp(buffer)
	if err != nil {
		// TODO: Handle error
	}
	if !ok {
		// TODO: Not enough bytes in buffer to decode
	}
	fmt.Printf("Decoded %v bytes of %v into [%v]\n", decodedCount, buffer, date)
	// Prints: Decoded 5 bytes of [20 77 9 28 7] into [1966-12-01 05:13:05 +0000 UTC]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DateEncodedSize

func DateEncodedSize(time time.Time) int

Get the number of bytes that would be required to encode this date.

func DecodeDate

func DecodeDate(src []byte) (result time.Time, bytesDecoded int, ok bool)

Decode a date. Returns the number of bytes decoded, or the number of bytes it attempted to decode. Returns ok=true if there was enough data in src. If ok == false, the resulting date is invalid.

func DecodeTime

func DecodeTime(src []byte) (result time.Time, bytesDecoded int, ok bool, err error)

Decode a time value. Returns the number of bytes decoded, or the number of bytes it attempted to decode. Returns ok=true if there was enough data in src. Returns an error if something went wrong other than there not being enough data. If ok == false or err != nil, the resulting time value is invalid.

func DecodeTimestamp

func DecodeTimestamp(src []byte) (result time.Time, bytesDecoded int, ok bool, err error)

Decode a timestamp. Returns the number of bytes decoded, or the number of bytes it attempted to decode. Returns ok=true if there was enough data in src. Returns an error if something went wrong other than there not being enough data. If ok == false or err != nil, the resulting timestamp is invalid.

func EncodeDate

func EncodeDate(time time.Time, dst []byte) (bytesEncoded int, ok bool)

Encode a date. Returns the number of bytes encoded, or the number of bytes it attempted to encode. Returns ok=true if there was enough room in dst.

func EncodeTime

func EncodeTime(tValue time.Time, dst []byte) (bytesEncoded int, ok bool, err error)

Encode a time value. Returns the number of bytes encoded, or the number of bytes it attempted to encode. Returns ok=true if there was enough room in dst. Returns an error if something went wrong other than there not being enough room.

func EncodeTimestamp

func EncodeTimestamp(time time.Time, dst []byte) (bytesEncoded int, ok bool, err error)

Encode a timestamp. Returns the number of bytes encoded, or the number of bytes it attempted to encode. Returns ok=true if there was enough room in dst. Returns an error if something went wrong other than there not being enough room.

func TimeEncodedSize

func TimeEncodedSize(time time.Time) int

Get the number of bytes that would be required to encode this time value.

func TimestampEncodedSize

func TimestampEncodedSize(time time.Time) int

Get the number of bytes that would be required to encode this timestamp.

Types

This section is empty.

Jump to

Keyboard shortcuts

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