github.com/sandwich-go/boost@v1.3.29/xtime/cop_global.go (about)

     1  package xtime
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  var globalCop *Cop = NewCop(func() time.Time { return time.Now() })
     8  
     9  // Stop 停止globalCop的时间,使用系统时间
    10  func Stop() { globalCop.Stop() }
    11  
    12  // SetNowProvider 设定now提供方法
    13  func SetNowProvider(nowProvider func() time.Time) { globalCop.nowProvider = nowProvider }
    14  
    15  // Now 获取当前时间,精度秒
    16  var Now = func() time.Time { return globalCop.Now() }
    17  
    18  // Unix 获取当前时间戳,精度秒
    19  // time consume: time.Now().Unix() > atomic.LoadInt64(&_atomic_timestamp) > globalCop.Unix() > globalCop.ts
    20  var Unix = func() int64 { return globalCop.Unix() }
    21  
    22  // UnixMilli 当前时间,单位毫秒
    23  var UnixMilli = func() int64 { return globalCop.UnixMilli() }
    24  
    25  const mockDeprecated = "Time Mock Deprecated: use https://github.com/sandwich-go/xtime instead"
    26  
    27  // mock属于测试类需求,stime对时间mock的支持仅限于Freeze,Scale,Travel,对于mock下的tick,after没有做完备支持,迁移到https://github.com/sandwich-go/xtime独立扩展支持
    28  // Mocked Deprecated: https://github.com/sandwich-go/xtime instead
    29  var Mocked = func() bool { panic(mockDeprecated) }
    30  
    31  // Freeze Deprecated: https://github.com/sandwich-go/xtime instead
    32  var Freeze = func(t time.Time) { panic(mockDeprecated) }
    33  
    34  // Scale Deprecated: https://github.com/sandwich-go/xtime instead
    35  var Scale = func(scale float64) { panic(mockDeprecated) }
    36  
    37  // Travel Deprecated: https://github.com/sandwich-go/xtime instead
    38  var Travel = func(t time.Time) { panic(mockDeprecated) }
    39  
    40  // Since Deprecated: https://github.com/sandwich-go/xtime instead
    41  var Since = func(t time.Time) time.Duration { panic(mockDeprecated) }
    42  
    43  // Sleep Deprecated: https://github.com/sandwich-go/xtime instead
    44  var Sleep = func(d time.Duration) { panic(mockDeprecated) }
    45  
    46  // After Deprecated: https://github.com/sandwich-go/xtime instead
    47  var After = func(d time.Duration) <-chan time.Time { panic(mockDeprecated) }
    48  
    49  // Tick Deprecated: https://github.com/sandwich-go/xtime instead
    50  var Tick = func(d time.Duration) <-chan time.Time { panic(mockDeprecated) }
    51  
    52  // Return Deprecated: https://github.com/sandwich-go/xtime instead
    53  var Return = func() { panic(mockDeprecated) }