Awesome Go

go-rampart

CategoryData Structures and Algorithms
SubcategoryMiscellaneous Data Structures and Algorithms
Stars0

Determine how intervals relate to each other

About go-rampart

go-rampart

Go Reference github.com/francesconi/go-rampart Codecov Go Report Card

Go port of the Haskell Rampart library by Taylor Fausak.

This package provides types and functions for defining intervals and determining how they relate to each other. This can be useful to determine if an event happened during a certain time frame, or if two time frames overlap (and if so, how exactly they overlap).

Install

go get github.com/francesconi/go-rampart

Examples

Ordered types

Any type that supports the operators < <= >= >.

a := rampart.NewInterval(2, 3)
b := rampart.NewInterval(3, 7)
rel := a.Relate(b)
// rel: RelationMeets

Any other type

NewIntervalFunc accepts any type as long as a comparison function is provided. The comparison function should return values as follows:

cmp(t1, t2) < 0 if t1 < t2
cmp(t1, t2) > 0 if t1 > t2
cmp(t1, t2) == 0 if t1 == t2

time.Time

func compareTimes(t1, t2 time.Time) int {
    return int(t1.Sub(t2))
}

a := rampart.NewIntervalFunc(
    time.Date(2022, time.April, 1, 0, 0, 0, 0, time.UTC),
    time.Date(2022, time.April, 8, 0, 0, 0, 0, time.UTC),
    compareTimes,
)
b := rampart.NewIntervalFunc(
    time.Date(2022, time.April, 6, 0, 0, 0, 0, time.UTC),
    time.Date(2022, time.April, 15, 0, 0, 0, 0, time.UTC),
    compareTimes,
)
rel := a.Relate(b)
// rel: RelationOverlaps

Frequently Asked Questions

What is go-rampart?

go-rampart is a Data Structures and Algorithms library for the Go programming language. Determine how intervals relate to each other

How do I install go-rampart?

Install go-rampart with the Go module system using `go get francesconi/go-rampart`. Check the repository for the current installation instructions.

What category does go-rampart belong to?

go-rampart is listed under Data Structures and Algorithms, specifically Miscellaneous Data Structures and Algorithms.

← Back to Miscellaneous Data Structures and Algorithms