recurring

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: BSD-3-Clause Imports: 3 Imported by: 4

Documentation

Overview

Package recurring handles recurring times.

Index

Examples

Constants

View Source
const (
	Weekdays = Monday | Tuesday | Wednesday | Thursday | Friday
	Weekend  = Saturday | Sunday
)

Variables

This section is empty.

Functions

func OnDays

func OnDays(dayMask DaysOfWeek) functional.Filterer

OnDays filters times by day of week. dayMask is the desired days of the week ored together e.g functional.Monday | functional.Tuesday

Types

type DaysOfWeek

type DaysOfWeek int
const (
	Sunday DaysOfWeek = 1 << iota
	Saturday
	Friday
	Thursday
	Wednesday
	Tuesday
	Monday
)

type R

type R interface {

	// ForTime returns a Stream of time.Time starting at t. The times that
	// returned Stream emits shall be after t and be in ascending order.
	ForTime(t time.Time) functional.Stream
}

R represents a recurring time such as each Monday at 7:00.

func After

func After(r R, d time.Duration) R

After returns a new R instance that represents duration d after every time in r

func AtInterval

func AtInterval(start time.Time, d time.Duration) R

AtInterval returns a new R instance that represents starting at time start and repeating at d intervals.

func AtTime

func AtTime(hour24, minute int) R

AtTime returns a new R instance that represents repeating at a certain time of day.

func Combine

func Combine(rs ...R) R

Combine combines multiple R instances together and returns them as a single one.

Example
package main

import (
	"fmt"
	"github.com/keep94/tasks/recurring"
	"time"
)

func main() {
	// Daily at 10:09, 13:05, and 17:13
	r := recurring.Combine(
		recurring.AtTime(10, 9),
		recurring.AtTime(13, 5),
		recurring.AtTime(17, 13))
	stream := r.ForTime(time.Date(2013, 10, 2, 12, 0, 0, 0, time.Local))
	layout := "Jan 2 15:04:05"
	var current time.Time
	for i := 0; i < 8; i++ {
		stream.Next(&current)
		fmt.Println(current.Format(layout))
	}
}
Output:

Oct 2 13:05:00
Oct 2 17:13:00
Oct 3 10:09:00
Oct 3 13:05:00
Oct 3 17:13:00
Oct 4 10:09:00
Oct 4 13:05:00
Oct 4 17:13:00

func Filter

func Filter(r R, f functional.Filterer) R

Filter returns a new R instance that filters the time.Time Streams that r creates

Example
package main

import (
	"fmt"
	"github.com/keep94/tasks/recurring"
	"time"
)

func main() {
	// Weekdays at 7:00
	r := recurring.Filter(
		recurring.AtTime(7, 0),
		recurring.OnDays(recurring.Weekdays))
	stream := r.ForTime(time.Date(2013, 10, 1, 7, 0, 0, 0, time.Local))
	layout := "Mon Jan 2 15:04:05"
	var current time.Time
	for i := 0; i < 5; i++ {
		stream.Next(&current)
		fmt.Println(current.Format(layout))
	}
}
Output:

Wed Oct 2 07:00:00
Thu Oct 3 07:00:00
Fri Oct 4 07:00:00
Mon Oct 7 07:00:00
Tue Oct 8 07:00:00

func Nil

func Nil() R

Nil returns a new R instance that represents never happening.

func OnDate

func OnDate(targetTime time.Time) R

OnDate returns a new R instance that represents happening once on a particular date and time.

func OnTheHour

func OnTheHour() R

OnTheHour returns an R instance that represents repeating at the start of each hour.

func StartAt

func StartAt(r R, startTime time.Time) R

StartAt returns a new R that is the same as r but contains only the times on or after startTime.

func Until

func Until(r R, t time.Time) R

Until returns a new R that is the same as r but contains only times before t.

type RFunc

type RFunc func(t time.Time) functional.Stream

RFunc converts an ordinary function to an R instance

func (RFunc) ForTime

func (f RFunc) ForTime(t time.Time) functional.Stream

Jump to

Keyboard shortcuts

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