Documentation ¶
Index ¶
- Constants
- func FormatDate(tsMillis uint64) string
- func FormatTimeMillis(tsMillis uint64) string
- func GetTimeMillis() uint64
- func GetTimeNano() uint64
- func GetTimestamp() uint64
- func Now() time.Time
- func SetClock(c Clock)
- func SetTickerCreator(tc TickerCreator)
- func Sleep(d time.Duration)
- func StartTicker()
- type Clock
- type MockClock
- type MockTicker
- type MockTickerCreator
- type RealClock
- type RealTicker
- type RealTickerCreator
- type Ticker
- type TickerCreator
Constants ¶
View Source
const ( TimeFormat = "2006-01-02 15:04:05" DateFormat = "2006-01-02" UnixTimeUnitOffset = uint64(time.Millisecond / time.Nanosecond) )
Variables ¶
This section is empty.
Functions ¶
func FormatTimeMillis ¶
FormatTimeMillis 将Unix时间戳(ms)格式化为时间字符串
Types ¶
type Clock ¶
type Clock interface { Now() time.Time Sleep(d time.Duration) GetTimeMillis() uint64 GetTimeNano() uint64 }
Clock 时钟接口
type MockClock ¶
type MockClock struct {
// contains filtered or unexported fields
}
MockClock 测试使用的Clock对象
func NewMockClock ¶
func NewMockClock() *MockClock
func (*MockClock) GetTimeMillis ¶
func (*MockClock) GetTimeNano ¶
type MockTicker ¶
type MockTicker struct {
// contains filtered or unexported fields
}
MockTicker 测试使用的 Ticker 对象 MockTicker 和 MockClock 一般搭配使用
func NewMockTicker ¶
func NewMockTicker(d time.Duration) *MockTicker
func (*MockTicker) C ¶
func (t *MockTicker) C() <-chan time.Time
func (*MockTicker) Stop ¶
func (t *MockTicker) Stop()
type MockTickerCreator ¶
type MockTickerCreator struct{}
MockTickerCreator 创建 MockTicker 用于测试 MockTickerCreator 和 MockClock 通常一起使用
func NewMockTickerCreator ¶
func NewMockTickerCreator() *MockTickerCreator
type RealClock ¶
type RealClock struct{}
RealClock 真实使用的Clock对象
func NewRealClock ¶
func NewRealClock() *RealClock
func (*RealClock) GetTimeMillis ¶
func (*RealClock) GetTimeNano ¶
type RealTicker ¶
type RealTicker struct {
// contains filtered or unexported fields
}
RealTicker 真实使用的 Ticker 对象
func NewRealTicker ¶
func NewRealTicker(d time.Duration) *RealTicker
func (*RealTicker) C ¶
func (t *RealTicker) C() <-chan time.Time
func (*RealTicker) Stop ¶
func (t *RealTicker) Stop()
type RealTickerCreator ¶
type RealTickerCreator struct{}
RealTickerCreator 创建真实的 RealTicker 和 time.Ticker 对象.
func NewRealTickerCreator ¶
func NewRealTickerCreator() *RealTickerCreator
type TickerCreator ¶
TickerCreator 实例化Ticker.
func CurrentTickerCreator ¶
func CurrentTickerCreator() TickerCreator
CurrentTickerCreator 获取 Ticker 对象
Click to show internal directories.
Click to hide internal directories.