Documentation ¶
Overview ¶
The Tideland Go Library timex package helps when working with times and dates. Beside tests it contains a crontab for chronological jobs and a retry function to let code blocks be retried under well defined conditions regarding time and count.
Index ¶
- Constants
- func BeginOf(t time.Time, unit UnitOfTime) time.Time
- func DayInList(t time.Time, days []int) bool
- func DayInRange(t time.Time, minDay, maxDay int) bool
- func EndOf(t time.Time, unit UnitOfTime) time.Time
- func HourInList(t time.Time, hours []int) bool
- func HourInRange(t time.Time, minHour, maxHour int) bool
- func MinuteInList(t time.Time, minutes []int) bool
- func MinuteInRange(t time.Time, minMinute, maxMinute int) bool
- func MonthInList(t time.Time, months []time.Month) bool
- func MonthInRange(t time.Time, minMonth, maxMonth time.Month) bool
- func PackageVersion() version.Version
- func Retry(f func() (bool, error), rs RetryStrategy) error
- func SecondInList(t time.Time, seconds []int) bool
- func SecondInRange(t time.Time, minSecond, maxSecond int) bool
- func WeekdayInList(t time.Time, weekdays []time.Weekday) bool
- func WeekdayInRange(t time.Time, minWeekday, maxWeekday time.Weekday) bool
- func YearInList(t time.Time, years []int) bool
- func YearInRange(t time.Time, minYear, maxYear int) bool
- type Crontab
- type Job
- type RetryStrategy
- type UnitOfTime
Constants ¶
const ( ErrCrontabCannotBeRecovered = iota + 1 ErrRetriedTooLong ErrRetriedTooOften )
Variables ¶
This section is empty.
Functions ¶
func BeginOf ¶
func BeginOf(t time.Time, unit UnitOfTime) time.Time
BeginOf returns the begin of the passed unit for the given time.
func DayInRange ¶
DayInRange tests if a day of a time is in a given range.
func EndOf ¶
func EndOf(t time.Time, unit UnitOfTime) time.Time
EndOf returns the end of the passed unit for the given time.
func HourInList ¶
HourInList tests if the hour of a time is in a given list.
func HourInRange ¶
HourInRange tests if a hour of a time is in a given range.
func MinuteInList ¶
MinuteInList tests if the minute of a time is in a given list.
func MinuteInRange ¶
MinuteInRange tests if a minute of a time is in a given range.
func MonthInList ¶
MonthInList tests if the month of a time is in a given list.
func MonthInRange ¶
MonthInRange tests if a month of a time is in a given range.
func PackageVersion ¶
PackageVersion returns the version of the version package.
func Retry ¶
func Retry(f func() (bool, error), rs RetryStrategy) error
Retry executes the passed function until it returns true or an error. These retries are restricted by the retry strategy.
func SecondInList ¶
SecondInList tests if the second of a time is in a given list.
func SecondInRange ¶
SecondInRange tests if a second of a time is in a given range.
func WeekdayInList ¶
WeekdayInList tests if the weekday of a time is in a given list.
func WeekdayInRange ¶
WeekdayInRange tests if a weekday of a time is in a given range.
func YearInList ¶
YearInList test if the year of a time is in a given list.
Types ¶
type Crontab ¶
type Crontab struct {
// contains filtered or unexported fields
}
Crontab is one cron server. A system can run multiple in parallel.
type Job ¶
type Job interface { // ShallExecute decides when called if the job // shal be executed. ShallExecute(t time.Time) bool // Execute executes the job. If the method returns // false or an error it will be removed. Execute() (bool, error) }
Job is executed by the crontab.
type RetryStrategy ¶
type RetryStrategy struct { Count int Break time.Duration BreakIncrement time.Duration Timeout time.Duration }
RetryStrategy describes how often the function in Retry is executed, the initial break between those retries, how much this time is incremented for each retry, and the maximum timeout.
func LongAttempt ¶
func LongAttempt() RetryStrategy
LongAttempt returns a predefined long retry strategy.
func MediumAttempt ¶
func MediumAttempt() RetryStrategy
MediumAttempt returns a predefined medium retry strategy.
func ShortAttempt ¶
func ShortAttempt() RetryStrategy
ShortAttempt returns a predefined short retry strategy.
type UnitOfTime ¶
type UnitOfTime int
UnitOfTime describes whose begin/end is wanted.
const ( Second UnitOfTime = iota + 1 Minute Hour Day Month Year )