timeutil

package
v1.0.0-beta.198 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const MAX_SAFE_ITERATIONS = 10000

Variables

This section is empty.

Functions

func AsTimed

func AsTimed[T any](fn func(T) time.Time) func(T) Timed[T]

AsTimed returns a function that converts a value of type T to a Timed value.

func Compare

func Compare(a, b time.Time) int

Types

type Period

type Period struct {
	From time.Time `json:"from"`
	To   time.Time `json:"to"`
}

func (Period) Contains

func (p Period) Contains(t time.Time) bool

Inclusive at start, exclusive at end

func (Period) ContainsExclusive

func (p Period) ContainsExclusive(t time.Time) bool

Exclusive at both start and end

func (Period) ContainsInclusive

func (p Period) ContainsInclusive(t time.Time) bool

Inclusive at both start and end

func (Period) Duration

func (p Period) Duration() time.Duration

func (Period) Overlaps

func (p Period) Overlaps(other Period) bool

Returns true if the two periods overlap at any point Returns false if the periods are exactly sequential, e.g.: [1, 2] and [2, 3]

func (Period) OverlapsInclusive

func (p Period) OverlapsInclusive(other Period) bool

Returns true if the two periods overlap at any point Returns true if the periods are exactly sequential, e.g.: [1, 2] and [2, 3]

type Recurrence

type Recurrence struct {
	Interval RecurrenceInterval `json:"period"`
	// Anchor can be an arbitrary anchor time for the recurrence.
	// It does not have to be the last or the next time.
	Anchor time.Time `json:"anchor"`
}

func FromISODuration

func FromISODuration(p *isodate.Period, anchor time.Time) (Recurrence, error)

func (Recurrence) GetPeriodAt

func (r Recurrence) GetPeriodAt(t time.Time) (Period, error)

Returns a period where p.ContainsInclusive(t) is true

func (Recurrence) Next

func (r Recurrence) Next(t time.Time) (time.Time, error)

func (Recurrence) NextAfter

func (r Recurrence) NextAfter(t time.Time) (time.Time, error)

NextAfter returns the next time after t that the recurrence should occur. If at t the recurrence should occur, it will return t.

func (Recurrence) Prev

func (r Recurrence) Prev(t time.Time) (time.Time, error)

func (Recurrence) PrevBefore

func (r Recurrence) PrevBefore(t time.Time) (time.Time, error)

PrevBefore returns the previous time before t that the recurrence should occur.

type RecurrenceInterval

type RecurrenceInterval struct {
	isodate.Period
}
var (
	RecurrencePeriodDaily RecurrenceInterval = RecurrenceInterval{isodate.NewPeriod(0, 0, 0, 1, 0, 0, 0)}
	RecurrencePeriodWeek  RecurrenceInterval = RecurrenceInterval{isodate.NewPeriod(0, 0, 1, 0, 0, 0, 0)}
	RecurrencePeriodMonth RecurrenceInterval = RecurrenceInterval{isodate.NewPeriod(0, 1, 0, 0, 0, 0, 0)}
	RecurrencePeriodYear  RecurrenceInterval = RecurrenceInterval{isodate.NewPeriod(1, 0, 0, 0, 0, 0, 0)}
)

type SimpleTimeline

type SimpleTimeline = Timeline[time.Time]

func NewSimpleTimeline

func NewSimpleTimeline(times []time.Time) SimpleTimeline

type Timed

type Timed[T any] struct {
	// contains filtered or unexported fields
}

func (Timed[T]) GetTime

func (t Timed[T]) GetTime() time.Time

func (Timed[T]) GetValue

func (t Timed[T]) GetValue() T

type Timeline

type Timeline[T any] struct {
	// contains filtered or unexported fields
}

func NewTimeline

func NewTimeline[T any](times []Timed[T]) Timeline[T]

func (Timeline[T]) After

func (t Timeline[T]) After(at time.Time) Timeline[T]

func (Timeline[T]) GetAt

func (t Timeline[T]) GetAt(idx int) Timed[T]

func (Timeline[T]) GetBoundingPeriod

func (t Timeline[T]) GetBoundingPeriod() Period

func (Timeline[T]) GetPeriods

func (t Timeline[T]) GetPeriods() []Period

func (Timeline[T]) GetTimes

func (t Timeline[T]) GetTimes() []time.Time

Jump to

Keyboard shortcuts

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