Documentation
¶
Overview ¶
* @Author: cnzf1 * @Date: 2023-01-04 09:58:25 * @LastEditors: cnzf1 * @LastEditTime: 2023-01-04 09:58:29 * @Description:
* @Author: cnzf1 * @Date: 2022-07-20 13:56:45 * @LastEditors: cnzf1 * @LastEditTime: 2023-01-09 17:26:51 * @Description:
* @Author: cnzf1 * @Date: 2022-08-26 11:42:04 * @LastEditors: cnzf1 * @LastEditTime: 2022-12-15 16:31:34 * @Description:
Index ¶
- Constants
- func BackoffUntil(f func(), backoff BackoffManager, sliding bool, stopCh <-chan struct{})
- func JitterAround(duration time.Duration, jitter float64) time.Duration
- func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, ...)
- func JitterUp(duration time.Duration, factor float64) time.Duration
- func MsToUTCTime(t int64) time.Time
- func NowMs() int64
- func NowS() int64
- func NowUs() int64
- func StrToTime(s string) time.Time
- func SubDaySets(before, last time.Time, seps ...string) []string
- func SubDaySetsEx(before, last time.Time, useFirst bool, useLast bool, seps ...string) []string
- func SubDays(before, last time.Time) int
- func SubMonSets(before, last time.Time, seps ...string) []string
- func SubMonSetsEx(before, last time.Time, useFirst bool, useLast bool, seps ...string) []string
- func SubYearSets(before, last time.Time) []string
- func SubYearSetsEx(before, last time.Time, useFirst bool, useLast bool) []string
- func TSToStr(sec int64, nsec int64) string
- func TSToTime(sec int64, nsec int64) time.Time
- func TimeToMs(t time.Time) int64
- func TimeToStr(s time.Time) string
- func Until(f func(), period time.Duration, stopCh <-chan struct{})
- type BackoffManager
- type Clock
- type ElapsedTimer
- type PassiveClock
- type RealClock
- func (RealClock) After(d time.Duration) <-chan time.Time
- func (RealClock) AfterFunc(d time.Duration, f func()) Timer
- func (RealClock) NewTicker(d time.Duration) Ticker
- func (RealClock) NewTimer(d time.Duration) Timer
- func (RealClock) Now() time.Time
- func (RealClock) Since(ts time.Time) time.Duration
- func (RealClock) Sleep(d time.Duration)
- func (RealClock) Tick(d time.Duration) <-chan time.Time
- type Ticker
- type Timer
- type WithTicker
Constants ¶
const ( TIME_LAYOUT_YEAR = "2006" // YYYY TIME_LAYOUT_MONTH = "2006-01" // YYYY-MM TIME_LAYOUT_DAY = "2006-01-02" // YYYY-MM-DD TIME_LAYOUT_MINUTE = "2006-01-02 15:04" // YYYY-MM-DD HH:mm TIME_LAYOUT_SECOND = "2006-01-02 15:04:05" // YYYY-MM-DD HH-mm:SS TIME_LAYOUT_MILLSECOND = "2006-01-02 15:04:05.000" // YYYY-MM-DD HH-mm:SS.NNN TIME_LAYOUT_MICROSECOND = "2006-01-02 15:04:05.000000" // YYYY-MM-DD HH-mm:SS.NNNNNN TIME_LAYOUT_NANOSECOND = "2006-01-02 15:04:05.000000000" // YYYY-MM-DD HH-mm:SS.NNNNNNNNN TIME_LAYOUT_COMPACT_DAY = "20060102" // YYYYMMDD TIME_LAYOUT_COMPACT_SIMPLE_SECOND = "150405" // hhmmss TIME_LAYOUT_COMPACT_EXT_SECOND = "0102150405" // MMDDhhmmss TIME_LAYOUT_COMPACT_SECOND = "20060102150405" // YYYYMMDDhhmmss )
Variables ¶
This section is empty.
Functions ¶
func BackoffUntil ¶
func BackoffUntil(f func(), backoff BackoffManager, sliding bool, stopCh <-chan struct{})
func JitterAround ¶
JitterAround return duration which added a random jitter
This adds or subtracts time from the duration within a given jitter fraction. For example for 10s and jitter 0.1, it will return a time within [9s, 11s])
func JitterUntil ¶
func JitterUp ¶
JitterUp return duration which added factor times the cardinality For example for 10s and jitter 1, it will return a time within [10s, 20s])
func MsToUTCTime ¶
MillisToTime returns the UTC time corresponding to the given Unix time, t milliseconds since January 1, 1970 UTC.
func SubDaySets ¶
SubDaySets return the date set during before and last.
For example:
before := time.Date(2020, 12, 28, 1, 5, 10, 0, time.Local) after := time.Date(2021, 1, 2, 13, 10, 30, 0, time.Local) Call SubDaySets(before, after) -> []string{"2020-12-28","2020-12-29","2020-12-30", "2020-12-31","2021-01-01","2021-01-02"}
func SubDaySetsEx ¶
SubDaySetsEx return the date set during before and last. useFirst represent include the date of before. useLast represent include the date of last.
For example:
before := time.Date(2020, 12, 28, 1, 5, 10, 0, time.Local) after := time.Date(2021, 1, 2, 13, 10, 30, 0, time.Local) Call SubDaySetsEx(before, after, true, true) -> []string{"2020-12-28","2020-12-29","2020-12-30", "2020-12-31","2021-01-01","2021-01-02"}
func SubMonSets ¶
SubMonSets return the month set during before and last.
For example:
before := time.Date(2020, 12, 28, 1, 5, 10, 0, time.Local) after := time.Date(2021, 1, 2, 13, 10, 30, 0, time.Local) Call SubMonSets(before, after) -> []string{"2020-12", "2021-01"}
func SubMonSetsEx ¶
SubMonSetsEx return the month set during before and last. useFirst represent include the month of before. useLast represent include the month of last.
For example:
before := time.Date(2020, 12, 28, 1, 5, 10, 0, time.Local) after := time.Date(2021, 1, 2, 13, 10, 30, 0, time.Local) Call SubMonSetsEx(before, after, true, true) -> []string{"2020-12", "2021-01"}
func SubYearSets ¶
SubYearSets return the year set during before and last.
For example:
before := time.Date(2020, 12, 28, 1, 5, 10, 0, time.Local) after := time.Date(2021, 1, 2, 13, 10, 30, 0, time.Local) Call SubYearSets(before, after) -> []string{"2020", "2021"}
func SubYearSetsEx ¶
SubYearSetsEx return the year set during before and last. useFirst represent include the year of before. useLast represent include the year of last.
For example:
before := time.Date(2020, 12, 28, 1, 5, 10, 0, time.Local) after := time.Date(2021, 1, 2, 13, 10, 30, 0, time.Local) Call SubYearSetsEx(before, after, true, true) -> []string{"2020", "2021"}
Types ¶
type BackoffManager ¶
type BackoffManager interface {
Backoff() Timer
}
func NewJitteredBackoffManager ¶
func NewJitteredBackoffManager(duration time.Duration, jitter float64, c Clock) BackoffManager
NewJitteredBackoffManager returns a BackoffManager that backoffs with given duration plus given jitter. If the jitter is negative, backoff will not be jittered.
type Clock ¶
type Clock interface { PassiveClock // After returns the channel of a new Timer. // This method does not allow to free/GC the backing timer before it fires. Use // NewTimer instead. After(d time.Duration) <-chan time.Time // NewTimer returns a new Timer. NewTimer(d time.Duration) Timer // Sleep sleeps for the provided duration d. // Consider making the sleep interruptible by using 'select' on a context channel and a timer channel. Sleep(d time.Duration) // Tick returns the channel of a new Ticker. // This method does not allow to free/GC the backing ticker. Use // NewTicker from WithTicker instead. Tick(d time.Duration) <-chan time.Time }
Clock allows for injecting fake or real clocks into code that needs to do arbitrary things based on time.
type ElapsedTimer ¶
type ElapsedTimer struct {
// contains filtered or unexported fields
}
func NewElapsedTimer ¶
func NewElapsedTimer() *ElapsedTimer
NewElapsedTimer returns an ElapsedTimer.
func (*ElapsedTimer) Duration ¶
func (et *ElapsedTimer) Duration() time.Duration
Duration returns the elapsed time.
func (*ElapsedTimer) Elapsed ¶
func (et *ElapsedTimer) Elapsed() time.Duration
Elapsed returns the string representation of elapsed time.
func (*ElapsedTimer) ElapsedMs ¶
func (et *ElapsedTimer) ElapsedMs() float32
ElapsedMs returns the elapsed time of string on milliseconds.
type PassiveClock ¶
PassiveClock allows for injecting fake or real clocks into code that needs to read the current time but does not support scheduling activity in the future.
type RealClock ¶
type RealClock struct{}
RealClock really calls time.Now()
func (RealClock) After ¶
After is the same as time.After(d). This method does not allow to free/GC the backing timer before it fires. Use NewTimer instead.