Small, user-friendly library to help you work with dates and dates ranges in Go. A time-zone-independent representation of time used that follows the rules of the proleptic Gregorian calendar with exactly 24-hour days, 60-minute hours, and 60-second minutes.
Date supports SQL scan and JSON marshalling/unmarshalling out of the box.
Date can be parsed from string start, err := date.Parse("2018-10-15")
or created manually d := date.Date{2018, 10, 1}
.
Two Dates define Range date.Range{date.Date{2018, 10, 1}, date.Date{2018, 10, 5}}
.
RangeSet can be used to work with Ranges:
ranges = date.RangeSet(ranges).
Filter(func(dr date.Range) bool {
return !dr.Empty()
}).
TrimEnd().
Sub(date.Range{date.Date{2018, 10, 1}, date.Date{2018, 10, 5}}).
ShiftEnd(5).
List()
go get github.com/furdarius/date
$ dep ensure -add github.com/furdarius/date
start, _ := date.Parse("2018-10-15")
end, _ := date.Parse("2018-10-20")
interval1 := date.Range{start, end}
interval2 := date.Range{start, end.AddDays(-1)}
base := []date.Range{
date.Range{date.Date{2018, 10, 1}, date.Date{2018, 10, 5}},
date.Range{date.Date{2018, 10, 8}, date.Date{2018, 10, 22}},
}
ranges := date.RangeSet(base).Sub(interval).Impose(interval2).ExtendEnd().List()
Pull requests are very much welcomed. Make sure a test or example is included that covers your change and your commits represent coherent changes that include a reason for the change.
Use gometalinter
to check code with linters:
gometalinter -t --vendor