timer

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2021 License: MIT Imports: 4 Imported by: 0

README

timer

Documentation

Index

Constants

View Source
const (
	// AnyTimeCronSpec 是任何时候都符合的 cronspec
	AnyTimeCronSpec = "* * * * *"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type TimeRange

type TimeRange struct {
	// contains filtered or unexported fields
}

TimeRange 描述一个时间范围, 并判断 time 是否符合 range. TimeRange 的判断条件来自于 Cron format, 见 https://en.wikipedia.org/wiki/Cron

Ex:

NewHourTimeRange(1,18), 表明 1-18 点都是符合(包括 18:59 也是)

Note:

TimeRange 中都是 [left,right] 的

func NewDomTimeRange

func NewDomTimeRange(left, right uint) (*TimeRange, error)

NewDomTimeRange is same as 'NewTimeRange("* * * left-right *")'

func NewDowTimeRange

func NewDowTimeRange(left, right uint) (*TimeRange, error)

NewDowTimeRange is same as 'NewTimeRange("* * * * left-right")'

func NewHourTimeRange

func NewHourTimeRange(left, right uint) (*TimeRange, error)

NewHourTimeRange is same as 'NewTimeRange("* left-right * * *")'

func NewMinTimeRange

func NewMinTimeRange(left, right uint) (*TimeRange, error)

NewMinTimeRange is same as 'NewTimeRange("left-right * * * *")'

func NewMonthTimeRange

func NewMonthTimeRange(left, right uint) (*TimeRange, error)

NewMonthTimeRange is same as 'NewTimeRange("* * * left-right *")'

func NewTimeRange

func NewTimeRange(spec string) (*TimeRange, error)

NewTimeRange 从 cron spec 创建 TimeRange, 每一必须为 left-right 或 *

┌───────────── minute (0 - 59) │ ┌───────────── hour (0 - 23) │ │ ┌───────────── day of the month (1 - 31) │ │ │ ┌───────────── month (1 - 12) │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday; │ │ │ │ │ 7 is also Sunday on some systems) │ │ │ │ │ │ │ │ │ │ * * * * *

func (*TimeRange) Clock

func (t *TimeRange) Clock() (bool, time.Time)

func (*TimeRange) ClockIn

func (t *TimeRange) ClockIn(tm time.Time) (bool, time.Time)

func (*TimeRange) IsTimeUp

func (r *TimeRange) IsTimeUp(tm time.Time) (bool, time.Time)

func (*TimeRange) IsTimeUpNow

func (r *TimeRange) IsTimeUpNow() (bool, time.Time)

func (*TimeRange) Spec

func (r *TimeRange) Spec() string

type TimeSpan

type TimeSpan struct {
	// contains filtered or unexported fields
}

func NewTimeSpan

func NewTimeSpan(interval time.Duration, lastAt time.Time) *TimeSpan

func (*TimeSpan) Clock

func (t *TimeSpan) Clock() (bool, time.Time)

Clock 与 now 比较, 当timeup时置 last 为 now

func (*TimeSpan) ClockIn

func (t *TimeSpan) ClockIn(tm time.Time) (bool, time.Time)

ClockIn 与 ts 比较, 当 timeup 时置 last 为 tm

func (*TimeSpan) Interval

func (t *TimeSpan) Interval() time.Duration

func (*TimeSpan) IsTimeUp

func (t *TimeSpan) IsTimeUp(tm time.Time) (bool, time.Time)

IsTimeUp 与 ts 比较

func (*TimeSpan) IsTimeUpNow

func (t *TimeSpan) IsTimeUpNow() (bool, time.Time)

IsTimeUpNow 与 now_ts 比较

func (*TimeSpan) LastAt

func (t *TimeSpan) LastAt() time.Time

func (*TimeSpan) ResetAs

func (t *TimeSpan) ResetAs(tm time.Time)

ResetNow 置 last 为 ts

func (*TimeSpan) ResetNow

func (t *TimeSpan) ResetNow()

ResetNow 置 last 为 now_ts

type Timer

type Timer interface {
	// Clock 检查当前时间是否允许, 允许情况下会执行需要的置位(TimeSpan)
	Clock() (bool, time.Time)

	// Clock 检查指定时间是否允许, 允许情况下会执行需要的置位(TimeSpan)
	ClockIn(tm time.Time) (bool, time.Time)

	// IsTimeUpNow 检查指定时间是否允许
	IsTimeUpNow() (bool, time.Time)

	// IsTimeUp 检查指定时间是否允许
	IsTimeUp(tm time.Time) (bool, time.Time)
}

type TimerList

type TimerList struct {
	// contains filtered or unexported fields
}

TimerList 用于检测多个 Timer 是否同时 time up

Note: next 会有误差, 因为只是取的 timer 中 next 最大值

func NewTimerList

func NewTimerList(timers ...Timer) (*TimerList, error)

func (*TimerList) Clock

func (t *TimerList) Clock() (bool, time.Time)

func (*TimerList) ClockIn

func (t *TimerList) ClockIn(tm time.Time) (bool, time.Time)

func (*TimerList) IsTimeUp

func (t *TimerList) IsTimeUp(tm time.Time) (bool, time.Time)

func (*TimerList) IsTimeUpNow

func (t *TimerList) IsTimeUpNow() (bool, time.Time)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL