epoch

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrParseFormatted = errors.New("failed to convert string to time")

ErrParseFormatted is used when parsing the formatted string failed.

Functions

func ParseFormatted

func ParseFormatted(input string) (time.Time, error)

ParseFormatted takes a human readable time string and returns Go's default time type. Example input: "Mon, 02 Jan 2006 15:04:05 MST".

func ParseTimestamp

func ParseTimestamp(timestamp int64, unit TimeUnit) (time.Time, error)

ParseTimestamp takes a timestamp of the given unit and returns Go's default time type.

func ToTimestamp

func ToTimestamp(t time.Time, unit TimeUnit) (int64, error)

ToTimestamp takes Go's default time type returns a timestamp of the given unit.

Types

type TimeUnit

type TimeUnit byte

TimeUnit represents a time unit.

const (
	// UnitSeconds represents seconds.
	UnitSeconds TimeUnit = iota
	// UnitMilliseconds represents milliseconds.
	UnitMilliseconds
	// UnitMicroseconds represents microseconds.
	UnitMicroseconds
	// UnitNanoseconds represents nanoseconds.
	UnitNanoseconds
)

func GuessUnit

func GuessUnit(timestamp int64, ref time.Time) TimeUnit

GuessUnit guesses if the input is sec, ms, us or ns based on the difference of the length (number of digits) of the 'ref' epoch times.

func ParseUnit

func ParseUnit(input string) (TimeUnit, error)

ParseUnit takes a string and returns the corresponding unit.

Jump to

Keyboard shortcuts

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