time

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package time provides time-zone and local-machine independent time service

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitTimeSync

func InitTimeSync()

Types

type TimeService

type TimeService interface {
	// Now returns the current timestamp calibrated with ntp server
	Now() TimeStamp

	// SinceSeconds returns the time duration from the given timestamp to current moment
	SinceSeconds(t TimeStamp) int64

	// NowAfter checks if current timestamp greater than the given one
	NowAfter(t TimeStamp) bool
}

TimeService is a time service, it return a timestamp in seconds

var TSInstance TimeService

type TimeStamp

type TimeStamp int64

TimeStamp in milliseconds

func Int64MilliSecondsToTimeStamp

func Int64MilliSecondsToTimeStamp(milliSec int64) TimeStamp

func TimeToTimeStamp

func TimeToTimeStamp(t time.Time) TimeStamp

func (TimeStamp) AddMilliSeconds

func (ts TimeStamp) AddMilliSeconds(milliSec int64) TimeStamp

func (TimeStamp) AddSeconds

func (ts TimeStamp) AddSeconds(sec int64) TimeStamp

func (TimeStamp) After

func (ts TimeStamp) After(t TimeStamp) bool

func (TimeStamp) Bytes

func (ts TimeStamp) Bytes() []byte

func (TimeStamp) Local

func (ts TimeStamp) Local() time.Time

func (TimeStamp) SinceMilliSeconds

func (ts TimeStamp) SinceMilliSeconds(t TimeStamp) int64

func (TimeStamp) SinceSeconds

func (ts TimeStamp) SinceSeconds(t TimeStamp) int64

func (TimeStamp) String

func (ts TimeStamp) String() string

func (TimeStamp) UTC

func (ts TimeStamp) UTC() time.Time

func (TimeStamp) Unix

func (ts TimeStamp) Unix() int64

func (TimeStamp) UnixMilli

func (ts TimeStamp) UnixMilli() int64

type TimeSync

type TimeSync struct {
	// contains filtered or unexported fields
}

TimeSync implements time synchronization from ntp servers

func (*TimeSync) Now

func (ts *TimeSync) Now() TimeStamp

Now returns the current timestamp calibrated with ntp server

func (*TimeSync) NowAfter

func (ts *TimeSync) NowAfter(t TimeStamp) bool

NowAfter checks if current timestamp greater than the given one

func (*TimeSync) SinceSeconds

func (ts *TimeSync) SinceSeconds(t TimeStamp) int64

SinceSeconds returns the time duration seconds from the given timestamp to current moment

Jump to

Keyboard shortcuts

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