chrono

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: GPL-2.0 Imports: 11 Imported by: 0

README

chrono

A more transmittable time type for Go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DurPB is a shorthand for this long function
	DurPB = ptypes.DurationProto
	// TimePB is a shorthand for this long function
	TimePB = ptypes.TimestampProto
	// ToTime is a shorthand for this long function
	ToTime = ptypes.Timestamp
	// NowPB is shorthand for this long function
	NowPB = ptypes.TimestampNow
	// Dur is shorthand for this long function
	Dur = ptypes.Duration
)

Functions

func DurString

func DurString(d *Duration) string

DurString converted chrono.Duration into an Influx GROUP BY string

func Max

func Max(times ...time.Time) time.Time

Max returns the latest of all times given

func RFC3339

func RFC3339(t *Time) string

RFC3339 converted chrono.Time into an RFC3339 string

func Secs

func Secs(f float64) time.Duration

Secs converts a float representation of seconds to a time.Duration

func TimeDifference

func TimeDifference(start *Time, end *Time) time.Duration

TimeDifference returns the Duration between the given start and end times

func WithinRange

func WithinRange(t time.Time, rng Range) bool

WithinRange returns whether or not a given time is within a time range

Types

type Duration

type Duration struct {
	ProtoDuration        *duration.Duration `protobuf:"bytes,1,opt,name=proto_duration,json=protoDuration,proto3" json:"proto_duration,omitempty"`
	XXX_NoUnkeyedLiteral struct{}           `json:"-"`
	XXX_unrecognized     []byte             `json:"-"`
	XXX_sizecache        int32              `json:"-"`
}

func MustDuration

func MustDuration(d *Duration, err error) *Duration

func NewDuration

func NewDuration(d time.Duration) *Duration

NewDuration instantiates a *chrono.Duration from a time.Duration

func NewDurationFromProto

func NewDurationFromProto(pd *duration.Duration) *Duration

NewDurationFromProto instantiates a Duration from a protocol buffer *duration.Duration

func NewDurationFromString

func NewDurationFromString(str string) (*Duration, error)

NewDurationFromString instantiates a Duration from a string

func (*Duration) D

func (d *Duration) D() time.Duration

D returns the Duration as a time.Duration

func (*Duration) Descriptor

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

func (*Duration) GetProtoDuration

func (m *Duration) GetProtoDuration() *duration.Duration

func (*Duration) MarshalGQL

func (d *Duration) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface

func (*Duration) MarshalJSON

func (d *Duration) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Duration into JSON

func (*Duration) PB

func (d *Duration) PB() *duration.Duration

PB returns the Duration as protocol buffer *duration.Duration

func (*Duration) ProtoMessage

func (*Duration) ProtoMessage()

func (*Duration) Reset

func (m *Duration) Reset()

func (*Duration) String

func (m *Duration) String() string

func (*Duration) UnmarshalGQL

func (d *Duration) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Unmarshaler interface

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the duration encoded as JSON into a Duration

func (*Duration) XXX_DiscardUnknown

func (m *Duration) XXX_DiscardUnknown()

func (*Duration) XXX_Marshal

func (m *Duration) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Duration) XXX_Merge

func (m *Duration) XXX_Merge(src proto.Message)

func (*Duration) XXX_Size

func (m *Duration) XXX_Size() int

func (*Duration) XXX_Unmarshal

func (m *Duration) XXX_Unmarshal(b []byte) error

type Range

type Range struct {
	Lower, Upper time.Time
}

Range defines a time range using a lower and upper time bound

type RelativeRange

type RelativeRange struct {
	Lower, Upper time.Duration
}

RelativeRange is a relative time range defined by the upper and lower durations. These values are used to create an absolute range centered around a time (like the current time)

func (RelativeRange) Abs

func (r RelativeRange) Abs(t time.Time) Range

Abs returns an absolute time range from the relative range centered around the provided time

type Time

type Time struct {
	ProtoTime            *timestamp.Timestamp `protobuf:"bytes,1,opt,name=proto_time,json=protoTime,proto3" json:"proto_time,omitempty"`
	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
	XXX_unrecognized     []byte               `json:"-"`
	XXX_sizecache        int32                `json:"-"`
}

func Add

func Add(t *Time, dur time.Duration) *Time

Add adds a time.Duration to a chrono.Time

func Average

func Average(a *Time, b *Time) *Time

Average returns the average of two *Times

func Must

func Must(t *Time, err error) *Time

func New

func New(t time.Time) *Time

New instantiates a chrono Time from a Go Time. It panics if the time cannot be converted

func NewFromPB

func NewFromPB(pt *timestamp.Timestamp) *Time

NewFromPB instantiates a Time from a protocol buffer *timestamp.Timestamp

func NewFromString

func NewFromString(str string) (*Time, error)

FromString instantiates a Time from a RFC3339 string

func Now

func Now() *Time

Now instantiates a Time from the current time

func (*Time) Add

func (t *Time) Add(p1 time.Duration) time.Time

func (*Time) AddDate

func (t *Time) AddDate(p1 int, p2 int, p3 int) time.Time

func (*Time) After

func (t *Time) After(p1 time.Time) bool

func (*Time) AppendFormat

func (t *Time) AppendFormat(p1 []uint8, p2 string) []uint8

func (*Time) Before

func (t *Time) Before(p1 time.Time) bool

func (*Time) Clock

func (t *Time) Clock() (int, int, int)

func (*Time) Date

func (t *Time) Date() (int, time.Month, int)

func (*Time) Day

func (t *Time) Day() int

func (*Time) Descriptor

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

func (*Time) Equal

func (t *Time) Equal(p1 time.Time) bool

func (*Time) Format

func (t *Time) Format(p1 string) string

func (*Time) GetProtoTime

func (m *Time) GetProtoTime() *timestamp.Timestamp

func (*Time) GobEncode

func (t *Time) GobEncode() ([]uint8, error)

func (*Time) Hour

func (t *Time) Hour() int

func (*Time) ISOWeek

func (t *Time) ISOWeek() (int, int)

func (*Time) In

func (t *Time) In(p1 *time.Location) time.Time

func (*Time) IsZero

func (t *Time) IsZero() bool

func (*Time) Local

func (t *Time) Local() time.Time

func (*Time) Location

func (t *Time) Location() *time.Location

func (*Time) MarshalBinary

func (t *Time) MarshalBinary() ([]uint8, error)

func (Time) MarshalGQL

func (t Time) MarshalGQL(w io.Writer)

MarshalGQL implements the graphql.Marshaler interface

func (*Time) MarshalJSON

func (t *Time) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Time into JSON

func (*Time) MarshalText

func (t *Time) MarshalText() ([]uint8, error)

func (*Time) Minute

func (t *Time) Minute() int

func (*Time) Month

func (t *Time) Month() time.Month

func (*Time) Nanosecond

func (t *Time) Nanosecond() int

func (Time) PB

func (t Time) PB() *timestamp.Timestamp

PB returns the Time as a protocol buffer *timestamp.Timestamp

func (*Time) ProtoMessage

func (*Time) ProtoMessage()

func (*Time) Reset

func (m *Time) Reset()

func (*Time) Round

func (t *Time) Round(p1 time.Duration) time.Time

func (*Time) Second

func (t *Time) Second() int

func (*Time) String

func (m *Time) String() string

func (*Time) Sub

func (t *Time) Sub(p1 time.Time) time.Duration

func (Time) T

func (t Time) T() time.Time

T returns the Time as a time.Time

func (*Time) Truncate

func (t *Time) Truncate(p1 time.Duration) time.Time

func (*Time) UTC

func (t *Time) UTC() time.Time

func (*Time) Unix

func (t *Time) Unix() int64

func (*Time) UnixNano

func (t *Time) UnixNano() int64

func (*Time) UnmarshalGQL

func (t *Time) UnmarshalGQL(v interface{}) error

UnmarshalGQL implements the graphql.Unmarshaler interface

func (*Time) UnmarshalJSON

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

UnmarshalJSON unmarshals the time encoded as a RFC3339 JSON string into a Time

func (*Time) Weekday

func (t *Time) Weekday() time.Weekday

func (*Time) XXX_DiscardUnknown

func (m *Time) XXX_DiscardUnknown()

func (*Time) XXX_Marshal

func (m *Time) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Time) XXX_Merge

func (m *Time) XXX_Merge(src proto.Message)

func (*Time) XXX_Size

func (m *Time) XXX_Size() int

func (*Time) XXX_Unmarshal

func (m *Time) XXX_Unmarshal(b []byte) error

func (*Time) Year

func (t *Time) Year() int

func (*Time) YearDay

func (t *Time) YearDay() int

func (*Time) Zone

func (t *Time) Zone() (string, int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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