Documentation ¶
Index ¶
- Constants
- func CheckNeedUpdate(updateType int64, extra string, tm int64) (bool, error)
- func CheckNeedUpdate2(updateType int64, extra string, start, end int64) (bool, error)
- func DayBeginStamp(now int64) int64
- func EndOfDay(now time.Time) time.Time
- func EndOfMonth(now time.Time) time.Time
- func EndOfWeek(now time.Time) time.Time
- func EndOfYear(now time.Time) time.Time
- func GetLocalTimeFromString(ctx context.Context, format string, timestring string) (localtime time.Time)
- func GetTimeFormStamp(strTime int64, format string) string
- func GetTimeSE(timeType int64, timeValue int64, now time.Time) (ST *time.Time, ET *time.Time, err error)
- func GetTimeSE2(timeType int64, timeValue int64, now time.Time) (ST int64, ET int64, err error)
- func HourBeginStamp(now int64) int64
- func MonthScope(stamp int64) (int64, int64)
- func StartOfDay(now time.Time) time.Time
- func StartOfDayStampFromStr(day string) (int64, error)
- func StartOfMonth(now time.Time) time.Time
- func StartOfWeek(now time.Time) time.Time
- func StartOfYear(now time.Time) time.Time
- func TimeCheckerValid(updateType int64, extra string) error
- func WeekScope(stamp int64) (int64, int64)
- type AbsTimeChecker
- type BackOffCtrl
- type Duration
- type HandTimeChecker
- type NatureDayTimeChecker
- type RandTicker
- type RunTimeStat
- type TimeChecker
- type Timer
Constants ¶
const ( TimeForever = 0 // 永久 TimeAbs = 1 // 绝对时间,单位为s TimeDay = 2 // 自然日 TimeWeek = 3 // 自然周 TimeMonth = 4 // 自然月 TimeYear = 5 // 自然年 TimeBackAbs = 6 // 绝对时间,单位为s, 从当前时间往后 )
const ( TimeTypeHand = 0 TimeTypeAbs = 1 TimeTypeNatureDay = 2 )
const ( TimeFormatYear = "2006-01-02" TimeFormatDate = "01-02" TimeFormatTime24 = "15:04:05" TimeFormatTime12 = "03:04:05" TimeFormatAll = "2006-01-02 15:04:05" )
build format with string type and build a struct for this format func
Variables ¶
This section is empty.
Functions ¶
func CheckNeedUpdate2 ¶
func GetLocalTimeFromString ¶
func GetTimeFormStamp ¶
func GetTimeSE ¶
func GetTimeSE(timeType int64, timeValue int64, now time.Time) (ST *time.Time, ET *time.Time, err error)
时间转换 返回请求对应的起止时间,如果是永久, 则返回 timeType 时间类型 timeValue
func GetTimeSE2 ¶
func StartOfDayStampFromStr ¶
StartOfDayStampFromStr 获取指定天的时间范围 天格式 2006-01-02 为空时候返回当天的
func TimeCheckerValid ¶
Types ¶
type AbsTimeChecker ¶
type AbsTimeChecker struct {
Value int64 `json:"value"`
}
==== 绝对时间
func (*AbsTimeChecker) Check ¶
func (a *AbsTimeChecker) Check(start, end int64) bool
func (*AbsTimeChecker) Valid ¶
func (a *AbsTimeChecker) Valid() error
type BackOffCtrl ¶
type BackOffCtrl struct {
// contains filtered or unexported fields
}
BackOffCtrl ...
func NewBackOffCtrl ¶
func NewBackOffCtrl(step time.Duration, ceil time.Duration) *BackOffCtrl
NewBackOffCtrl ...
type Duration ¶
func (Duration) Shrink ¶
Shrink will decrease the duration by comparing with context's timeout duration and return new timeout\context\CancelFunc.
func (*Duration) UnmarshalText ¶
UnmarshalText unmarshal text to duration.
type HandTimeChecker ¶
type HandTimeChecker struct{}
==== 手动更新
func (HandTimeChecker) Check ¶
func (HandTimeChecker) Check(start, end int64) bool
func (HandTimeChecker) Valid ¶
func (HandTimeChecker) Valid() error
type NatureDayTimeChecker ¶
type NatureDayTimeChecker struct {
Value int `json:"value"`
}
==== 自然日
func (*NatureDayTimeChecker) Check ¶
func (n *NatureDayTimeChecker) Check(start, end int64) bool
func (*NatureDayTimeChecker) Valid ¶
func (n *NatureDayTimeChecker) Valid() error
type RandTicker ¶
RandTicker is just like time.Ticker, except that it adds randomness to the events.
func NewRandTicker ¶
func NewRandTicker(d, variance time.Duration) *RandTicker
NewRandTicker creates a new RandTicker. d is the duration, and variance specifies the variance. The ticker will tick every d +/- variance.
func (*RandTicker) Stop ¶
func (tkr *RandTicker) Stop()
Stop stops the ticker and closes the underlying channel.
type RunTimeStat ¶
type RunTimeStat struct {
// contains filtered or unexported fields
}
RunTimeStat ...
type TimeChecker ¶
func TimeCheckerFactory ¶
func TimeCheckerFactory(updateType int64, extra string) (TimeChecker, error)
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer provides timer functionality that can be controlled by the user. You start the timer by providing it a callback function, which it will call at the specified interval.
var t = timer.NewTimer(1e9) t.Start(KeepHouse) func KeepHouse() { // do house keeping work }
You can stop the timer by calling t.Stop, which is guaranteed to wait if KeepHouse is being executed.
You can create an untimely trigger by calling t.Trigger. You can also schedule an untimely trigger by calling t.TriggerAfter.
The timer interval can be changed on the fly by calling t.SetInterval. A zero value interval will cause the timer to wait indefinitely, and it will react only to an explicit Trigger or Stop.
func (*Timer) SetInterval ¶
SetInterval changes the wait interval. It will cause the timer to restart the wait.
func (*Timer) Stop ¶
func (tm *Timer) Stop()
Stop will stop the timer. It guarantees that the timer will not execute any more calls to keephouse once it has returned.
func (*Timer) Trigger ¶
func (tm *Timer) Trigger()
Trigger will cause the timer to immediately execute the keephouse function. It will then cause the timer to restart the wait.
func (*Timer) TriggerAfter ¶
TriggerAfter waits for the specified duration and triggers the next event.