timex

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package timex adds some useful functions for the work with them time type.

Index

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 DayInList

func DayInList(t time.Time, days []int) bool

DayInList tests if the day of a time is in a given list.

func DayInRange

func DayInRange(t time.Time, minDay, maxDay int) bool

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

func HourInList(t time.Time, hours []int) bool

HourInList tests if the hour of a time is in a given list.

func HourInRange

func HourInRange(t time.Time, minHour, maxHour int) bool

HourInRange tests if a hour of a time is in a given range.

func MinuteInList

func MinuteInList(t time.Time, minutes []int) bool

MinuteInList tests if the minute of a time is in a given list.

func MinuteInRange

func MinuteInRange(t time.Time, minMinute, maxMinute int) bool

MinuteInRange tests if a minute of a time is in a given range.

func MonthInList

func MonthInList(t time.Time, months []time.Month) bool

MonthInList tests if the month of a time is in a given list.

func MonthInRange

func MonthInRange(t time.Time, minMonth, maxMonth time.Month) bool

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

func SecondInList(t time.Time, seconds []int) bool

SecondInList tests if the second of a time is in a given list.

func SecondInRange

func SecondInRange(t time.Time, minSecond, maxSecond int) bool

SecondInRange tests if a second of a time is in a given range.

func WeekdayInList

func WeekdayInList(t time.Time, weekdays []time.Weekday) bool

WeekdayInList tests if the weekday of a time is in a given list.

func WeekdayInRange

func WeekdayInRange(t time.Time, minWeekday, maxWeekday time.Weekday) bool

WeekdayInRange tests if a weekday of a time is in a given range.

func YearInList

func YearInList(t time.Time, years []int) bool

YearInList test if the year of a time is in a given list.

func YearInRange

func YearInRange(t time.Time, minYear, maxYear int) bool

YearInRange tests if a year of a time is in a given range.

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.

Jump to

Keyboard shortcuts

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