furdarius / date

A package to help you work with dates in Go.

Home Page:https://godoc.org/github.com/furdarius/date

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoDoc Build Status Go Report Card

Date it easy

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()

Install

go get github.com/furdarius/date

Adding as dependency by "go dep"

$ dep ensure -add github.com/furdarius/date

Usage

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()

Contributing

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

About

A package to help you work with dates in Go.

https://godoc.org/github.com/furdarius/date

License:MIT License


Languages

Language:Go 100.0%