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-03-25 23:07:36 * @Description:
* @Author: cnzf1 * @Date: 2022-08-26 11:42:04 * @LastEditors: cnzf1 * @LastEditTime: 2023-03-28 20:53:28 * @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 NowStr(layout string) string
- 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 ElapsedTimer
- type FakeTicker
- type Ticker
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 TIME_LAYOUT_COMPACT_MILLSECOND = "20060102150405.000" // YYYYMMDDHHmmSS.NNN )
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. seps represent separator, default is '-'
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. seps represent separator, default is '-'
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. seps represent separator, default is '-'
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. seps represent separator, default is '-'
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() Ticker
}
func NewJitteredBackoffManager ¶
func NewJitteredBackoffManager(duration time.Duration, jitter float64) BackoffManager
NewJitteredBackoffManager returns a BackoffManager that backoffs with given duration plus given jitter. If the jitter is negative, backoff will not be jittered.
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 FakeTicker ¶ added in v1.2.2
FakeTicker interface is used for unit testing.
func NewFakeTicker ¶ added in v1.2.2
func NewFakeTicker() FakeTicker
NewFakeTicker returns a FakeTicker.