Documentation ¶
Overview ¶
Package localtime provides time related funcs.
Index ¶
- Variables
- func Equal(a, b time.Time) bool
- func Normalize(t time.Time) time.Time
- func Now() time.Time
- func ParseRFC3339(s string) (time.Time, error)
- func RFC3339(t time.Time) string
- func SetTimeSyncer(syncer *TimeSyncer)
- func String(t time.Time) string
- func UTCNow() time.Time
- func Within(base, target time.Time, d time.Duration) bool
- func WithinNow(target time.Time, d time.Duration) bool
- type CallbackTimer
- func (ct *CallbackTimer) ID() TimerID
- func (ct *CallbackTimer) IsStarted() bool
- func (ct *CallbackTimer) Reset() error
- func (ct *CallbackTimer) Restart() error
- func (ct *CallbackTimer) SetInterval(f func(int) time.Duration) Timer
- func (ct *CallbackTimer) Start() error
- func (ct *CallbackTimer) Stop() error
- type ContextTimer
- type Time
- func (t Time) Bytes() []byte
- func (t Time) Equal(n Time) bool
- func (t Time) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (t Time) MarshalText() ([]byte, error)
- func (t Time) Normalize() Time
- func (t Time) RFC3339() string
- func (t *Time) UnmarshalBSONValue(ty bsontype.Type, b []byte) error
- func (t *Time) UnmarshalText(b []byte) error
- type TimeSyncer
- type Timer
- type TimerID
- type Timers
- func (ts *Timers) IsTimerStarted(id TimerID) bool
- func (ts *Timers) ResetTimer(id TimerID) error
- func (ts *Timers) SetLogging(l *logging.Logging) *logging.Logging
- func (ts *Timers) SetTimer(timer Timer) error
- func (*Timers) Start() error
- func (ts *Timers) StartTimers(ids []TimerID, stopOthers bool) error
- func (ts *Timers) Started() []TimerID
- func (ts *Timers) Stop() error
- func (ts *Timers) StopTimers(ids []TimerID) error
- func (ts *Timers) StopTimersAll() error
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 Normalize ¶
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 ParseRFC3339 ¶
ParseRFC3339 parses RFC3339 string.
func SetTimeSyncer ¶
func SetTimeSyncer(syncer *TimeSyncer)
SetTimeSyncer sets the global TimeSyncer.
Types ¶
type CallbackTimer ¶
type CallbackTimer struct { sync.RWMutex *logging.Logging // contains filtered or unexported fields }
func NewCallbackTimer ¶
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 (*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 ¶
func (Time) MarshalText ¶
func (*Time) UnmarshalBSONValue ¶
func (*Time) UnmarshalText ¶
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.
type Timers ¶
Timers handles the multiple timers and controls them selectively.
func (*Timers) IsTimerStarted ¶
func (*Timers) ResetTimer ¶
func (*Timers) StartTimers ¶
StartTimers starts timers with the given ids, before starting timers, stops the other timers if stopOthers is true.
func (*Timers) StopTimers ¶
func (*Timers) StopTimersAll ¶
Click to show internal directories.
Click to hide internal directories.