Documentation
¶
Overview ¶
Package gxtime encapsulates some golang.time functions
Package gxtime encapsulates some golang.time functions ¶
Package gxtime encapsulates some golang.time functions refer to github.com/jehiah/go-strftime
Package gxtime encapsulates some golang.time functions ¶
Package gxtime encapsulates some golang.time functions ¶
Package gxtime encapsulates some golang.time functions ¶
Package gxtime encapsulates some golang.time functions ref: https://github.com/AlexStocks/go-practice/blob/master/time/siddontang_time_wheel.go
Index ¶
- Constants
- Variables
- func After(d time.Duration) <-chan time.Time
- func DAY_NUM(expire int64) int64
- func Format(format string, t time.Time) string
- func Future(sec int, f func())
- func HOUR_NUM(expire int64) int64
- func Init()
- func MINUTE_NUM(expire int64) int64
- func MS_NUM(expire int64) int64
- func SECOND_NUM(expire int64) int64
- func Sleep(d time.Duration)
- func Tick(d time.Duration) <-chan time.Time
- func Time2Unix(t time.Time) int64
- func Time2UnixNano(t time.Time) int64
- func TimeMicrosecondDuration(m int) time.Duration
- func TimeMillisecondDuration(m int) time.Duration
- func TimeNanosecondDuration(n int) time.Duration
- func TimeSecondDuration(sec int) time.Duration
- func Unix2Time(unix int64) time.Time
- func UnixNano2Time(nano int64) time.Time
- func UnixString2Time(unix string) time.Time
- func YMD(year int, month int, day int, hour int, minute int, sec int) int
- func YMDPrint(sec int, nsec int) string
- func YMDUTC(year int, month int, day int, hour int, minute int, sec int) int
- type CountWatch
- type Ticker
- type Timer
- type TimerFunc
- type TimerID
- type TimerType
- type TimerWheel
- func (w *TimerWheel) AddTimer(f TimerFunc, typ TimerType, period int64, arg interface{}) (*Timer, error)
- func (w *TimerWheel) After(d time.Duration) <-chan time.Time
- func (w *TimerWheel) AfterFunc(d time.Duration, f func()) *Timer
- func (w *TimerWheel) Close()
- func (w *TimerWheel) NewTicker(d time.Duration) *Ticker
- func (w *TimerWheel) NewTimer(d time.Duration) *Timer
- func (w *TimerWheel) Sleep(d time.Duration)
- func (w *TimerWheel) Stop()
- func (w *TimerWheel) Tick(d time.Duration) <-chan time.Time
- func (w *TimerWheel) TickFunc(d time.Duration, f func()) *Ticker
- func (w *TimerWheel) TimerNumber() int
- type Wheel
Examples ¶
Constants ¶
View Source
const ( MAX_MS = 1000 MAX_SECOND = 60 MAX_MINUTE = 60 MAX_HOUR = 24 MAX_DAY = 31 MS = 1e6 SECOND_MS = 1 * MAX_MS * MS MINUTE_MS = 1 * MAX_SECOND * SECOND_MS HOUR_MS = 1 * MAX_MINUTE * MINUTE_MS DAY_MS = 1 * MAX_HOUR * HOUR_MS // ticker interval不能设置到这种精度, // 实际运行时ticker的时间间隔会在1.001ms上下浮动, // 当ticker interval小于1ms的时候,会导致TimerWheel.hand // 和timeWheel.inc不增长,造成时间错乱:例如本来 // 1.5s运行的函数在持续2.1s之后才被执行 // MINIMUM_DIFF = 1.001 * MS MINIMUM_DIFF = 10 * MS )
View Source
const ( ADD_TIMER timerAction = 1 DEL_TIMER timerAction = 2 RESET_TIMER timerAction = 3 )
View Source
const (
MAX_TIMER_LEVEL = 5
)
Variables ¶
View Source
var ( ErrTimeChannelFull = fmt.Errorf("timer channel full") ErrTimeChannelClosed = fmt.Errorf("timer channel closed") )
Functions ¶
func Format ¶ added in v0.2.0
go implementation of strftime This is an alternative to time.Format because no one knows what date 040305 is supposed to create when used as a 'layout' string this takes standard strftime format options. For a complete list of format options see http://strftime.org/
Example ¶
t := time.Unix(1340244776, 0)
utc, _ := time.LoadLocation("UTC")
t = t.In(utc)
fmt.Println(Format("%Y-%m-%d %H:%M:%S", t))
Output: 2012-06-21 02:12:56
func MINUTE_NUM ¶ added in v0.2.0
func SECOND_NUM ¶ added in v0.2.0
func Time2UnixNano ¶ added in v0.2.0
func TimeMicrosecondDuration ¶
func TimeMillisecondDuration ¶
func TimeNanosecondDuration ¶
func TimeSecondDuration ¶
func UnixNano2Time ¶ added in v0.2.0
func UnixString2Time ¶
Types ¶
type CountWatch ¶
type CountWatch struct {
// contains filtered or unexported fields
}
func (*CountWatch) Count ¶
func (w *CountWatch) Count() int64
func (*CountWatch) Reset ¶
func (w *CountWatch) Reset()
func (*CountWatch) Start ¶
func (w *CountWatch) Start()
type TimerWheel ¶ added in v0.2.0
type TimerWheel struct {
// contains filtered or unexported fields
}
timer based on multiple wheels
func NewTimerWheel ¶ added in v0.2.0
func NewTimerWheel() *TimerWheel
func (*TimerWheel) AddTimer ¶ added in v0.2.0
func (w *TimerWheel) AddTimer(f TimerFunc, typ TimerType, period int64, arg interface{}) (*Timer, error)
异步通知timerWheel添加一个timer,有可能失败
func (*TimerWheel) After ¶ added in v0.2.0
func (w *TimerWheel) After(d time.Duration) <-chan time.Time
func (*TimerWheel) AfterFunc ¶ added in v0.2.0
func (w *TimerWheel) AfterFunc(d time.Duration, f func()) *Timer
func (*TimerWheel) Close ¶ added in v0.2.0
func (w *TimerWheel) Close()
func (*TimerWheel) NewTicker ¶ added in v0.2.0
func (w *TimerWheel) NewTicker(d time.Duration) *Ticker
func (*TimerWheel) Sleep ¶ added in v0.2.0
func (w *TimerWheel) Sleep(d time.Duration)
func (*TimerWheel) Stop ¶ added in v0.2.0
func (w *TimerWheel) Stop()
func (*TimerWheel) Tick ¶ added in v0.2.0
func (w *TimerWheel) Tick(d time.Duration) <-chan time.Time
func (*TimerWheel) TickFunc ¶ added in v0.2.0
func (w *TimerWheel) TickFunc(d time.Duration, f func()) *Ticker
func (*TimerWheel) TimerNumber ¶ added in v0.2.0
func (w *TimerWheel) TimerNumber() int
Click to show internal directories.
Click to hide internal directories.