Documentation
¶
Index ¶
- func Between(t, a, b time.Time) bool
- func ProgressWrapper(from, upto time.Time, progressFunction func(float64)) func()
- func ProgressWrapperInterval(from, upto time.Time, interval time.Duration, progressFunction func(float64)) func()
- func ToToday(d time.Time) time.Time
- func ToTomorrow(d time.Time) time.Time
- type Event
- type Loop
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Between ¶
Between returns true if the given time t is between the two timestamps a (inclusive) and b (exclusive)
Example ¶
before := time.Now() A := time.Now() t := time.Now() B := time.Now() after := time.Now() fmt.Println(Between(t, A, B)) // true fmt.Println(Between(t, before, A)) // false fmt.Println(Between(t, B, after)) // false fmt.Println(Between(t, before, after)) // true fmt.Println(Between(t, before, B)) // true fmt.Println(Between(t, A, after)) // true fmt.Println(Between(t, after, before)) // false fmt.Println(Between(t, t, B)) // true (from inclusive, to exclusive) fmt.Println(Between(t, A, t)) // false (from inclusive, to exclusive)
Output: true false false true true true false true false
func ProgressWrapper ¶
ProgressWrapper wraps a function that takes a float64 in such a way that a float between 0 and 1 is passed in when it is called. The float signifies how far time has progressed from the given `from` time up to the given `upto` time. The wrapped function that takes no arguments is returned. The final "100%" (1.0) value will never be sent to the wrapped function, because the `upto` time is exclusive, not inclusive.
func ProgressWrapperInterval ¶
func ProgressWrapperInterval(from, upto time.Time, interval time.Duration, progressFunction func(float64)) func()
ProgressWrapperInterval behaves like ProgressWrapper, except that an interval is given, that lets the function receive a "1.0" value at the final run, when progress is complete. The interval duration is subtracted from the `upto` time, at the time when the progress float is calculated.
Types ¶
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event stores a time window for when the event can be triggered (`from` up to `upTo`), how long it should take to cooldown before being able to be re-triggered, which action should be performed when triggered, when it was last triggered, a mutex and a boolean variable for keeping track of if the action is still ongoing or not.
func New ¶
New creates a new Event, that should happen at the given "when" time, within the given time window, with an associated cooldown period after the event has been triggered. The event can be retriggered after every cooldown, within the time window. Only hour/minute/second will be considered.
func NewDateEvent ¶
NewDateEvent is like New, but the date will also be considered when triggering events.
func (*Event) Cooldown ¶
Cooldown is how long to wait after the event has been triggered, before being possible to trigger again.
func (*Event) Has ¶
Has checks if the Event has time t in its interval: from p.From() and up to but not including p.UpTo()
func (*Event) ShouldTrigger ¶
ShouldTrigger returns true if the current time is in the interval of the event AND it is not ongoing AND it is not in the cooldown period.