timeplus

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 3 Imported by: 1

README

timeplus

.github/workflows/timeplus.yaml

Types and utilities to deal with pragmatic use cases of time.

go get -u github.com/absurdlab/pkg/timeplus

Usage

// Current timestamp
timeplus.Now()

// Arbitrary timestamp
timeplus.On(time.Now().Add(time.Minute))

// Compare timestamp
t1 := timeplus.Now()
t2 := timeplus.Now().AddSecond(timeplus.Second(5))
t1.Before(t2)

// Interop with time.Time
var t = timeplus.Now()
var s = timeplus.Second(5)
t.Time()
s.Duration()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Second

type Second uint64

Second represent a clock second

func (Second) Duration

func (s Second) Duration() time.Duration

Duration converts the second to time.Duration type.

func (Second) Int64

func (s Second) Int64() int64

Int64 converts the second to an int64 type.

func (Second) Ref

func (s Second) Ref() *Second

Ref returns a reference to the Second value.

func (*Second) Scan

func (s *Second) Scan(src interface{}) error

func (Second) UInt64

func (s Second) UInt64() uint64

UInt64 converts the second to an uint64 type.

func (*Second) Value

func (s *Second) Value() (driver.Value, error)

type Timestamp

type Timestamp uint64

Timestamp is the number of seconds since unix epoch.

func Now

func Now() Timestamp

Now returns the current Timestamp.

func On

func On(t time.Time) Timestamp

On returns the Timestamp at given time.

func (Timestamp) AddDuration

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

AddDuration adds the given time.Duration to this Timestamp and returns a new Timestamp.

func (Timestamp) AddSecond

func (t Timestamp) AddSecond(second Second) Timestamp

AddSecond adds the given Second to this Timestamp and returns a new Timestamp.

func (Timestamp) After

func (t Timestamp) After(s Timestamp) bool

After returns true if this Timestamp happened after the given Timestamp. The method always returns false if at least one Timestamp is zero.

func (Timestamp) Before

func (t Timestamp) Before(s Timestamp) bool

Before returns true if this Timestamp happened before the given Timestamp. The method always returns false if at least one Timestamp is zero.

func (Timestamp) Equals

func (t Timestamp) Equals(s Timestamp) bool

Equals returns true if this Timestamp happened at the same time as the given Timestamp. The method always returns false if at least one Timestamp is zero.

func (Timestamp) Int64

func (t Timestamp) Int64() int64

Int64 converts Timestamp to int64 type.

func (*Timestamp) IsZero

func (t *Timestamp) IsZero() bool

IsZero returns true if this Timestamp is nil or equals to 0.

func (Timestamp) Ref

func (t Timestamp) Ref() *Timestamp

Ref returns a reference to the Timestamp value.

func (*Timestamp) Scan

func (t *Timestamp) Scan(src interface{}) error

func (Timestamp) Time

func (t Timestamp) Time() time.Time

Time converts Timestamp to time.Time.

func (Timestamp) UInt64

func (t Timestamp) UInt64() uint64

UInt64 converts Timestamp to uint64 type.

func (*Timestamp) Value

func (t *Timestamp) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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