localtime

package
v0.0.0-...-5a6e01e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package localtime provides time related funcs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ContextTimerPoolGet = func() *ContextTimer {
		return contextTimerPool.Get().(*ContextTimer)
	}
	ContextTimerPoolPut = func(ct *ContextTimer) {
		ct.Lock()
		ct.Logging = nil
		ct.ContextDaemon = nil
		ct.id = TimerID("")
		ct.interval = nil
		ct.callback = nil
		ct.c = 0
		ct.Unlock()

		contextTimerPool.Put(ct)
	}
)
View Source
var (
	StopTimerError = util.NewError("stop timer")
)

Functions

func Equal

func Equal(a, b time.Time) bool

func Normalize

func Normalize(t time.Time) time.Time

Normalize clear the nanoseconds part from Time and make time to UTC. "2009-11-10T23:00:00.00101010Z" -> "2009-11-10T23:00:00.001Z",

func Now

func Now() time.Time

Now returns the tuned Time with TimeSyncer.Offset().

func ParseRFC3339

func ParseRFC3339(s string) (time.Time, error)

ParseRFC3339 parses RFC3339 string.

func RFC3339

func RFC3339(t time.Time) string

RFC3339 formats time.Time to RFC3339Nano string.

func SetTimeSyncer

func SetTimeSyncer(syncer *TimeSyncer)

SetTimeSyncer sets the global TimeSyncer.

func String

func String(t time.Time) string

func UTCNow

func UTCNow() time.Time

func Within

func Within(base, target time.Time, d time.Duration) bool

func WithinNow

func WithinNow(target time.Time, d time.Duration) bool

Types

type CallbackTimer

type CallbackTimer struct {
	sync.RWMutex
	*logging.Logging
	// contains filtered or unexported fields
}

func NewCallbackTimer

func NewCallbackTimer(
	id TimerID,
	callback func(int) (bool, error),
	interval time.Duration,
) (*CallbackTimer, error)

func (*CallbackTimer) ID

func (ct *CallbackTimer) ID() TimerID

func (*CallbackTimer) IsStarted

func (ct *CallbackTimer) IsStarted() bool

func (*CallbackTimer) Reset

func (ct *CallbackTimer) Reset() error

func (*CallbackTimer) Restart

func (ct *CallbackTimer) Restart() error

func (*CallbackTimer) SetInterval

func (ct *CallbackTimer) SetInterval(f func(int) time.Duration) Timer

SetInterval sets the interval function. If the returned duration is 0, the timer will be stopped.

func (*CallbackTimer) Start

func (ct *CallbackTimer) Start() error

func (*CallbackTimer) Stop

func (ct *CallbackTimer) Stop() error

type ContextTimer

type ContextTimer struct {
	sync.RWMutex
	*logging.Logging
	*util.ContextDaemon
	// contains filtered or unexported fields
}

func NewContextTimer

func NewContextTimer(id TimerID, interval time.Duration, callback func(int) (bool, error)) *ContextTimer

func (*ContextTimer) ID

func (ct *ContextTimer) ID() TimerID

func (*ContextTimer) Reset

func (ct *ContextTimer) Reset() error

func (*ContextTimer) SetInterval

func (ct *ContextTimer) SetInterval(f func(int) time.Duration) Timer

func (*ContextTimer) SetLogging

func (ct *ContextTimer) SetLogging(l *logging.Logging) *logging.Logging

func (*ContextTimer) Stop

func (ct *ContextTimer) Stop() error

type Time

type Time struct {
	time.Time
}

func NewTime

func NewTime(t time.Time) Time

func (Time) Bytes

func (t Time) Bytes() []byte

func (Time) Equal

func (t Time) Equal(n Time) bool

func (Time) MarshalBSONValue

func (t Time) MarshalBSONValue() (bsontype.Type, []byte, error)

func (Time) MarshalText

func (t Time) MarshalText() ([]byte, error)

func (Time) Normalize

func (t Time) Normalize() Time

func (Time) RFC3339

func (t Time) RFC3339() string

func (*Time) UnmarshalBSONValue

func (t *Time) UnmarshalBSONValue(ty bsontype.Type, b []byte) error

func (*Time) UnmarshalText

func (t *Time) UnmarshalText(b []byte) error

type TimeSyncer

type TimeSyncer struct {
	sync.RWMutex
	*logging.Logging
	*util.ContextDaemon
	// contains filtered or unexported fields
}

TimeSyncer tries to sync time to time server.

func NewTimeSyncer

func NewTimeSyncer(server string, checkInterval time.Duration) (*TimeSyncer, error)

NewTimeSyncer creates new TimeSyncer

func (*TimeSyncer) Offset

func (ts *TimeSyncer) Offset() time.Duration

Offset returns the latest time offset.

func (*TimeSyncer) Start

func (ts *TimeSyncer) Start() error

Start starts TimeSyncer

type Timer

type Timer interface {
	util.Daemon
	IsStarted() bool
	ID() TimerID
	SetInterval(func(int) time.Duration) Timer
	Reset() error
}

type TimerID

type TimerID string

func (TimerID) String

func (ti TimerID) String() string

type Timers

type Timers struct {
	*logging.Logging
	sync.RWMutex
	// contains filtered or unexported fields
}

Timers handles the multiple timers and controls them selectively.

func NewTimers

func NewTimers(ids []TimerID, allowNew bool) *Timers

func (*Timers) IsTimerStarted

func (ts *Timers) IsTimerStarted(id TimerID) bool

func (*Timers) ResetTimer

func (ts *Timers) ResetTimer(id TimerID) error

func (*Timers) SetLogging

func (ts *Timers) SetLogging(l *logging.Logging) *logging.Logging

func (*Timers) SetTimer

func (ts *Timers) SetTimer(timer Timer) error

SetTimer sets the timer with id

func (*Timers) Start

func (*Timers) Start() error

Start of Timers does nothing

func (*Timers) StartTimers

func (ts *Timers) StartTimers(ids []TimerID, stopOthers bool) error

StartTimers starts timers with the given ids, before starting timers, stops the other timers if stopOthers is true.

func (*Timers) Started

func (ts *Timers) Started() []TimerID

func (*Timers) Stop

func (ts *Timers) Stop() error

Stop of Timers will stop all the timers

func (*Timers) StopTimers

func (ts *Timers) StopTimers(ids []TimerID) error

func (*Timers) StopTimersAll

func (ts *Timers) StopTimersAll() error

Jump to

Keyboard shortcuts

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