Documentation ¶
Overview ¶
Package timex adds some useful functions for the work with them time type.
Index ¶
- 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 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 RetryStrategy
- type UnitOfTime
Constants ¶
This section is empty.
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 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. It's a simple approach, more flexible ways can be found at together/wait.
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 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 )
Different units of time.