dot

package
v0.0.0-...-2c63f42 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cm (common) provides most used elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsZeroTime

func IsZeroTime(t time.Time) bool

IsZeroTime checks whether given time is zero. When transport time using grpc, empty time is marshalled to time.Unix(0, 0).

func Millis

func Millis(t time.Time) int64

Millis converts from Go time to timestamp (in millisecond).

Types

type IntID

type IntID int64

func NewIntID

func NewIntID() IntID

NewIntID mocks generating new id. In production, we need to use a more robust function.

func (IntID) MarshalJSON

func (id IntID) MarshalJSON() ([]byte, error)

func (*IntID) UnmarshalJSON

func (id *IntID) UnmarshalJSON(data []byte) error

type Timestamp

type Timestamp int64

Timestamp represents time as number of milliseconds from 1970.

func Now

func Now() Timestamp

Now returns current time.

func ToTimestamp

func ToTimestamp(t time.Time) Timestamp

ToTimestamp converts from Go time to timestamp (in nanosecond).

func (Timestamp) Add

func (t Timestamp) Add(d time.Duration) Timestamp

Add adds duration to timestamp

func (Timestamp) AddDays

func (t Timestamp) AddDays(days int) Timestamp

AddDays add a number of days to timestamp

func (Timestamp) After

func (t Timestamp) After(u Timestamp) bool

After reports whether the time instant t is after u

func (Timestamp) Before

func (t Timestamp) Before(u Timestamp) bool

Before reports whether the time instant t is before u

func (Timestamp) IsZero

func (t Timestamp) IsZero() bool

IsZero reports whether timestamp is zero

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements JSONMarshaler

func (Timestamp) Millis

func (t Timestamp) Millis() int64

Millis returns the timestamp as number of milliseconds from 1970

func (Timestamp) String

func (t Timestamp) String() string

func (Timestamp) Sub

func (t Timestamp) Sub(u Timestamp) time.Duration

Sub subs timestamp

func (Timestamp) ToTime

func (t Timestamp) ToTime() time.Time

ToTime converts from timestamp to Go time.

func (Timestamp) Unix

func (t Timestamp) Unix() int64

Unix converts Timestamp to seconds

func (Timestamp) UnixNano

func (t Timestamp) UnixNano() int64

UnixNano extracts nanoseconds from Timestamp

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON implements JSONUnmarshaler

Jump to

Keyboard shortcuts

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