tai64n

package module
v0.0.0-...-12133df Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2018 License: BSD-2-Clause Imports: 11 Imported by: 9

README

tai64n

Because time is a terrible thing to waste.

A golang library for calculating and holding time moments in TAI64N format.

Useful timestamping any data that requires high precision (nanosecond) and always flows forward (is not confused by leap seconds).

Documentation

Overview

Package tai64n is a generated protocol buffer package.

It is generated from these files:

tai64n.proto

It has these top-level messages:

TAI64N

Index

Constants

View Source
const TAI64OriginalBase = uint64(4611686018427387904)

The number of seconds to offset the UNIX epoch to find the current TAI time.

Variables

View Source
var (
	ErrInvalidLengthTai64N = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowTai64N   = fmt.Errorf("proto: integer overflow")
)
View Source
var AllLeapMoments []*LeapMoment
View Source
var AllLeapSeconds = []*LeapSecond{
	&LeapSecond{time.Date(1972, time.January, 1, 0, 0, 0, 0, time.UTC), 10},
	&LeapSecond{time.Date(1972, time.July, 1, 0, 0, 0, 0, time.UTC), 11},
	&LeapSecond{time.Date(1973, time.January, 1, 0, 0, 0, 0, time.UTC), 12},
	&LeapSecond{time.Date(1974, time.January, 1, 0, 0, 0, 0, time.UTC), 13},
	&LeapSecond{time.Date(1975, time.January, 1, 0, 0, 0, 0, time.UTC), 14},
	&LeapSecond{time.Date(1976, time.January, 1, 0, 0, 0, 0, time.UTC), 15},
	&LeapSecond{time.Date(1977, time.January, 1, 0, 0, 0, 0, time.UTC), 16},
	&LeapSecond{time.Date(1978, time.January, 1, 0, 0, 0, 0, time.UTC), 17},
	&LeapSecond{time.Date(1979, time.January, 1, 0, 0, 0, 0, time.UTC), 18},
	&LeapSecond{time.Date(1980, time.January, 1, 0, 0, 0, 0, time.UTC), 19},
	&LeapSecond{time.Date(1981, time.July, 1, 0, 0, 0, 0, time.UTC), 20},
	&LeapSecond{time.Date(1982, time.July, 1, 0, 0, 0, 0, time.UTC), 21},
	&LeapSecond{time.Date(1983, time.July, 1, 0, 0, 0, 0, time.UTC), 22},
	&LeapSecond{time.Date(1985, time.July, 1, 0, 0, 0, 0, time.UTC), 23},
	&LeapSecond{time.Date(1988, time.January, 1, 0, 0, 0, 0, time.UTC), 24},
	&LeapSecond{time.Date(1990, time.January, 1, 0, 0, 0, 0, time.UTC), 25},
	&LeapSecond{time.Date(1991, time.January, 1, 0, 0, 0, 0, time.UTC), 26},
	&LeapSecond{time.Date(1992, time.July, 1, 0, 0, 0, 0, time.UTC), 27},
	&LeapSecond{time.Date(1993, time.July, 1, 0, 0, 0, 0, time.UTC), 28},
	&LeapSecond{time.Date(1994, time.July, 1, 0, 0, 0, 0, time.UTC), 29},
	&LeapSecond{time.Date(1996, time.January, 1, 0, 0, 0, 0, time.UTC), 30},
	&LeapSecond{time.Date(1997, time.July, 1, 0, 0, 0, 0, time.UTC), 31},
	&LeapSecond{time.Date(1999, time.January, 1, 0, 0, 0, 0, time.UTC), 32},
	&LeapSecond{time.Date(2006, time.January, 1, 0, 0, 0, 0, time.UTC), 33},
	&LeapSecond{time.Date(2009, time.January, 1, 0, 0, 0, 0, time.UTC), 34},
	&LeapSecond{time.Date(2012, time.July, 1, 0, 0, 0, 0, time.UTC), 35},
	&LeapSecond{time.Date(2015, time.July, 1, 0, 0, 0, 0, time.UTC), 36},
	&LeapSecond{time.Date(2017, time.January, 1, 0, 0, 0, 0, time.UTC), 37},
}

Functions

func LeapSecondsInvolved

func LeapSecondsInvolved(t time.Time) uint64

Return the number of leap seconds that occur previous to the given time.

Types

type LeapMoment

type LeapMoment struct {
	LeapSecond *LeapSecond
	Moment     *TAI64N
}

type LeapSecond

type LeapSecond struct {
	Threshold time.Time
	Offset    int
}

Represents the first moment after a leap second occurs.

type TAI64N

type TAI64N struct {
	Seconds     uint64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"`
	Nanoseconds uint32 `protobuf:"varint,2,opt,name=nanoseconds,proto3" json:"nanoseconds,omitempty"`
}

func FromTime

func FromTime(t time.Time) *TAI64N

Convert from a time.Time

func Now

func Now() *TAI64N

Return the current moment

func ParseTAI64NLabel

func ParseTAI64NLabel(label string) *TAI64N

Parse the canonical ascii format

func (*TAI64N) Add

func (tai *TAI64N) Add(dur time.Duration) *TAI64N

Generate a new moment by adding a duration

func (*TAI64N) After

func (tai *TAI64N) After(other *TAI64N) bool

Indicated if the called moment is after the argument

func (*TAI64N) Before

func (tai *TAI64N) Before(other *TAI64N) bool

Indicated if the called moment is before the argument

func (*TAI64N) Clock

func (t *TAI64N) Clock() (hour, min, sec int)

Calculate the hour, minute, and second of this moment. If the moment falls on a leap second, the displayed value will be that of the leap second as the 60th second of the day.

func (*TAI64N) Compare

func (tai *TAI64N) Compare(other *TAI64N) TimeComparison

Indicate how the 2 moments compare to eachother

func (*TAI64N) Date

func (t *TAI64N) Date() (year int, month time.Month, day int)

Calculate the year, month, and day of this moment. If the moment falls on a leap second, the displayed value will be that of the leap second as the 60th second of the day.

func (*TAI64N) Descriptor

func (*TAI64N) Descriptor() ([]byte, []int)

func (*TAI64N) Equal

func (this *TAI64N) Equal(that interface{}) bool

func (*TAI64N) GoString

func (this *TAI64N) GoString() string

func (*TAI64N) Label

func (tai *TAI64N) Label() string

Render the moment in the canonical ascii format

func (*TAI64N) Marshal

func (m *TAI64N) Marshal() (data []byte, err error)

func (TAI64N) MarshalJSON

func (tai TAI64N) MarshalJSON() ([]byte, error)

func (*TAI64N) MarshalTo

func (m *TAI64N) MarshalTo(data []byte) (int, error)

func (*TAI64N) ProtoMessage

func (*TAI64N) ProtoMessage()

func (*TAI64N) ReadStorage

func (tai *TAI64N) ReadStorage(buf []byte)

Update the value from it's canonical binary format

func (*TAI64N) Reset

func (m *TAI64N) Reset()

func (*TAI64N) Size

func (m *TAI64N) Size() (n int)

func (*TAI64N) String

func (t *TAI64N) String() string

Render the moment as a RFC3339Nano format

func (*TAI64N) Sub

func (tai *TAI64N) Sub(other *TAI64N) time.Duration

Return a duration as the difference between the 2 times

func (*TAI64N) Time

func (tai *TAI64N) Time() time.Time

Convert back to a time.Time

func (*TAI64N) Unmarshal

func (m *TAI64N) Unmarshal(data []byte) error

func (*TAI64N) UnmarshalJSON

func (tai *TAI64N) UnmarshalJSON(data []byte) (err error)

func (*TAI64N) WriteStorage

func (tai *TAI64N) WriteStorage(buf []byte)

Return the value in it's canonical binary format

type TimeComparison

type TimeComparison int

Indicates via Before, After, or Equal how to moments compare to eachother.

const (
	Before TimeComparison = -1
	Equal  TimeComparison = 0
	After  TimeComparison = 1
)

Jump to

Keyboard shortcuts

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