recur

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: AGPL-3.0 Imports: 7 Imported by: 1

README

Recur

Provides advanced functionality for calculating the timing of recurring events. You can easily use it to create simple or complex patterns for events that repeat at regular intervals, including events that occur on custom days or months. You can also customize the weekly off days to be used in the pattern, and generate a human-readable text representation of the pattern.
It gives easy way to check if a given time matches a specific pattern, and calculate the next time that a pattern will occur.
Recur is ideal for use in scheduling systems, task automation, and any other application that requires the precise timing of recurring events.

Features

  • Define recurrence patterns for daily, weekly, monthly, and yearly occurrences.
  • Specify specific days of the week or month for recurring events.
  • Handle complex recurrence scenarios with customizable options.
  • Calculate the next occurrence based on the current time.
  • Lightweight and easy to integrate into existing go projects.
  • Serializable recurring patterns for utilization in distributed systems.

Installation

You can install the Recur Go package by running the following command:

go get github.com/cybercloudsys/recur-go

Usage

To get started with Recur, you need to create a recurrence pattern. Recur supports various recurrence patterns such as daily, weekly, monthly, and yearly. Once you have defined the pattern, you can use the NextTime method to calculate the next occurrence.

Here's an example of creating a daily recurrence pattern:

import "github.com/cybercloudsys/recur-go"

func main() {
    recurPattern := recur.Daily().Build()
    nextOccurrence := recurPattern.NextTime()
    // nextOccurrence will be the date and time of the next occurrence
}

In this example, we created a daily recurrence pattern that calculates the next occurrence.

You can also create more complex recurrence patterns. Here's an example of creating a recurrence pattern that occurs on the closest working day 2 days before the end of a quarter at 10:30 AM:

import "github.com/cybercloudsys/recur-go"

func main() {
    recurPattern := recur.OnMonths(3, 6, 9, 12).OnDay(2).FromLastDay().OnWorkday().AtHour(10).AtMinute(30).Build()
    // Use the recurrence pattern as needed
}

Similarly, you can create monthly and yearly recurrence patterns with specific day or month constraints, such as the last Friday or the second Monday of every month.

These are just a few examples of the basic usage of Recur. You can explore the various options and methods provided by Recur to create more complex and customized recurrence patterns.

License

Recur
Copyright © 2023 Cyber Cloud Systems LLC

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Settings = RecurSettings{DateTimeKind: time.UTC, /* contains filtered or unexported fields */}

Functions

func Now

func Now() time.Time

Types

type LastMonthdayPattern

type LastMonthdayPattern struct {
	// contains filtered or unexported fields
}

func (*LastMonthdayPattern) AtHour

func (pattern *LastMonthdayPattern) AtHour(hour int) *MinutesPattern

func (*LastMonthdayPattern) AtMinute

func (pattern *LastMonthdayPattern) AtMinute(minute int) *SecondsPattern

func (*LastMonthdayPattern) AtSecond

func (pattern *LastMonthdayPattern) AtSecond(second int) *RecurringPattern

func (*LastMonthdayPattern) Build

func (pattern *LastMonthdayPattern) Build() *RecurringPattern

func (*LastMonthdayPattern) OnWorkday

func (pattern *LastMonthdayPattern) OnWorkday() *TimePattern

type MinutesPattern

type MinutesPattern struct {
	// contains filtered or unexported fields
}

func EveryHours

func EveryHours(hours int) *MinutesPattern

func (*MinutesPattern) AtMinute

func (pattern *MinutesPattern) AtMinute(minute int) *SecondsPattern

func (*MinutesPattern) AtSecond

func (pattern *MinutesPattern) AtSecond(second int) *RecurringPattern

func (*MinutesPattern) Build

func (pattern *MinutesPattern) Build() *RecurringPattern

type Monthday

type Monthday struct {
	Day       *int `json:",omitempty"`
	IsLastDay bool
	IsWorkday bool
}

type MonthdayPattern

type MonthdayPattern struct {
	// contains filtered or unexported fields
}

func (*MonthdayPattern) AtHour

func (pattern *MonthdayPattern) AtHour(hour int) *MinutesPattern

func (*MonthdayPattern) AtMinute

func (pattern *MonthdayPattern) AtMinute(minute int) *SecondsPattern

func (*MonthdayPattern) AtSecond

func (pattern *MonthdayPattern) AtSecond(second int) *RecurringPattern

func (*MonthdayPattern) Build

func (pattern *MonthdayPattern) Build() *RecurringPattern

func (*MonthdayPattern) FromLastDay

func (pattern *MonthdayPattern) FromLastDay() *LastMonthdayPattern

func (*MonthdayPattern) OnWorkday

func (pattern *MonthdayPattern) OnWorkday() *TimePattern

type MonthlyPattern

type MonthlyPattern struct {
	// contains filtered or unexported fields
}

func EveryMonths

func EveryMonths(months int) *MonthlyPattern

func Monthly

func Monthly() *MonthlyPattern

func OnMonths

func OnMonths(months ...int) *MonthlyPattern

func (*MonthlyPattern) AtHour

func (pattern *MonthlyPattern) AtHour(hour int) *MinutesPattern

func (*MonthlyPattern) AtMinute

func (pattern *MonthlyPattern) AtMinute(minute int) *SecondsPattern

func (*MonthlyPattern) AtSecond

func (pattern *MonthlyPattern) AtSecond(second int) *RecurringPattern

func (*MonthlyPattern) Build

func (pattern *MonthlyPattern) Build() *RecurringPattern

func (*MonthlyPattern) FromLastDay

func (pattern *MonthlyPattern) FromLastDay() *LastMonthdayPattern

func (*MonthlyPattern) OnDay

func (pattern *MonthlyPattern) OnDay(day int) *MonthdayPattern

func (*MonthlyPattern) OnLastWeek

func (pattern *MonthlyPattern) OnLastWeek(dayOfWeek time.Weekday) *TimePattern

func (*MonthlyPattern) OnWeek

func (pattern *MonthlyPattern) OnWeek(weekOfMonth int, dayOfWeek time.Weekday) *TimePattern

func (*MonthlyPattern) OnWorkday

func (pattern *MonthlyPattern) OnWorkday() *TimePattern

type Pattern

type Pattern struct {
	// contains filtered or unexported fields
}

func (*Pattern) Build

func (pattern *Pattern) Build() *RecurringPattern

func (*Pattern) EveryYears

func (pattern *Pattern) EveryYears(years int) *YearlyPattern

func (*Pattern) Yearly

func (pattern *Pattern) Yearly() *YearlyPattern

type PatternBuilder

type PatternBuilder interface {
	Build() *RecurringPattern
}

type RecurSettings

type RecurSettings struct {
	DateTimeKind *time.Location
	// contains filtered or unexported fields
}

func (*RecurSettings) GetWeeklyOffDays

func (settings *RecurSettings) GetWeeklyOffDays() []time.Weekday

func (*RecurSettings) SetWeeklyOffDays

func (settings *RecurSettings) SetWeeklyOffDays(offDays ...time.Weekday) error

type RecurringPattern

type RecurringPattern struct {
	Start time.Time

	WaitSeconds     *int       `json:",omitempty"`
	WaitMonths      *int       `json:",omitempty"`
	WaitYears       *int       `json:",omitempty"`
	AllowedWeekdays []Weekday  `json:",omitempty"`
	Weeks           []int      `json:",omitempty"`
	AllowedDays     []Monthday `json:",omitempty"`
	AllowedMonths   []int      `json:",omitempty"`
	WeeklyOffDays   []time.Weekday
	// contains filtered or unexported fields
}

func Every

func Every(delay time.Duration) *RecurringPattern

func EverySeconds

func EverySeconds(seconds int) *RecurringPattern

func NewRecurringPattern

func NewRecurringPattern() *RecurringPattern

func (*RecurringPattern) Build

func (pattern *RecurringPattern) Build() *RecurringPattern

func (*RecurringPattern) GetWaitTime

func (recurPattern *RecurringPattern) GetWaitTime() *time.Duration

func (*RecurringPattern) IsMatching

func (recurPattern *RecurringPattern) IsMatching(chkTime time.Time) bool

func (*RecurringPattern) MarshalJSON

func (pattern *RecurringPattern) MarshalJSON() ([]byte, error)

func (*RecurringPattern) NextTime

func (recurPattern *RecurringPattern) NextTime() time.Time

func (*RecurringPattern) SetWeeklyOffDays

func (recurPattern *RecurringPattern) SetWeeklyOffDays(offDays ...time.Weekday) error

func (*RecurringPattern) String

func (recurPattern *RecurringPattern) String() string

func (*RecurringPattern) UnmarshalJSON

func (pattern *RecurringPattern) UnmarshalJSON(data []byte) error

type SecondsPattern

type SecondsPattern struct {
	// contains filtered or unexported fields
}

func EveryMinutes

func EveryMinutes(minutes int) *SecondsPattern

func (*SecondsPattern) AtSecond

func (pattern *SecondsPattern) AtSecond(second int) *RecurringPattern

func (*SecondsPattern) Build

func (pattern *SecondsPattern) Build() *RecurringPattern

type TimePattern

type TimePattern struct {
	// contains filtered or unexported fields
}

func Daily

func Daily() *TimePattern

func DailyWithin

func DailyWithin(from time.Weekday, to time.Weekday) *TimePattern

func EveryDays

func EveryDays(days int) *TimePattern

func (*TimePattern) AtHour

func (pattern *TimePattern) AtHour(hour int) *MinutesPattern

func (*TimePattern) AtMinute

func (pattern *TimePattern) AtMinute(minute int) *SecondsPattern

func (*TimePattern) AtSecond

func (pattern *TimePattern) AtSecond(second int) *RecurringPattern

func (*TimePattern) Build

func (pattern *TimePattern) Build() *RecurringPattern

type Weekday

type Weekday struct {
	Day         time.Weekday
	WeekOfMonth *int `json:",omitempty"`
	IsLastWeek  bool
}

type WeeklyPattern

type WeeklyPattern struct {
	// contains filtered or unexported fields
}

func EveryWeeks

func EveryWeeks(weeks int) *WeeklyPattern

func Weekly

func Weekly() *WeeklyPattern

func (*WeeklyPattern) Build

func (pattern *WeeklyPattern) Build() *RecurringPattern

func (*WeeklyPattern) OnDayOfWeek

func (pattern *WeeklyPattern) OnDayOfWeek(dayOfWeek time.Weekday) *TimePattern

type YearlyPattern

type YearlyPattern struct {
	// contains filtered or unexported fields
}

func EveryYears

func EveryYears(years int) *YearlyPattern

func Yearly

func Yearly() *YearlyPattern

func (*YearlyPattern) Build

func (pattern *YearlyPattern) Build() *RecurringPattern

func (*YearlyPattern) Daily

func (pattern *YearlyPattern) Daily() *TimePattern

func (*YearlyPattern) DailyWithin

func (pattern *YearlyPattern) DailyWithin(from time.Weekday, to time.Weekday) *TimePattern

func (*YearlyPattern) Every

func (pattern *YearlyPattern) Every(delay time.Duration) *RecurringPattern

func (*YearlyPattern) EveryDays

func (pattern *YearlyPattern) EveryDays(days int) *TimePattern

func (*YearlyPattern) EveryHours

func (pattern *YearlyPattern) EveryHours(hours int) *MinutesPattern

func (*YearlyPattern) EveryMinutes

func (pattern *YearlyPattern) EveryMinutes(minutes int) *SecondsPattern

func (*YearlyPattern) EveryMonths

func (pattern *YearlyPattern) EveryMonths(months int) *MonthlyPattern

func (*YearlyPattern) EverySeconds

func (pattern *YearlyPattern) EverySeconds(seconds int) *RecurringPattern

func (*YearlyPattern) EveryWeeks

func (pattern *YearlyPattern) EveryWeeks(weeks int) *WeeklyPattern

func (*YearlyPattern) Monthly

func (pattern *YearlyPattern) Monthly() *MonthlyPattern

func (*YearlyPattern) OnMonths

func (pattern *YearlyPattern) OnMonths(months ...int) *MonthlyPattern

func (*YearlyPattern) Weekly

func (pattern *YearlyPattern) Weekly() *WeeklyPattern

Jump to

Keyboard shortcuts

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