A package to create a sequence series of daily dates, written in golang.
Sequence is an immutable struct, each operations returns a new Sequence and leaves the original untouched.
seq := dateseq.New()
seq = seq.Steps(10)
for k, v := range seq.Sequence() {
fmt.Printf("%v. %v\n", k, v.Format("2006-01-02 Mon"))
}Returns a sequence of dates from the current date counted backwards (assuming, you start this this programm on 2017-10-09):
0. 2017-10-09 Mon
1. 2017-10-08 Sun
2. 2017-10-07 Sat
3. 2017-10-06 Fri
4. 2017-10-05 Thu
5. 2017-10-04 Wed
6. 2017-10-03 Tue
7. 2017-10-02 Mon
8. 2017-10-01 Sun
9. 2017-09-30 SatWeekends can be excluded with ExcludeWeekends() from the sequence series. IncludeWeekends() will include them again, which is also the default behavior.
seq := dateseq.New()
seq = seq.ExcludeWeekends().Steps(10)
for k, v := range seq.Sequence() {
fmt.Printf("%v. %v\n", k, v.Format("2006-01-02 Mon"))
}Returns:
0. 2017-10-09 Mon
1. 2017-10-06 Fri
2. 2017-10-05 Thu
3. 2017-10-04 Wed
4. 2017-10-03 Tue
5. 2017-10-02 Mon
6. 2017-09-29 Fri
7. 2017-09-28 Thu
8. 2017-09-27 Wed
9. 2017-09-26 TueExclude some specific dates with Exclude(list []string).
seq := dateseq.New()
exclude := []string{
"2017-12-25",
"2017-12-26",
}
seq = seq.Steps(10).Exclude(exclude)The sequence methods are chainable, which allows creation and retrieving of the sequence slice in one go.
seq := dateseq.New().Steps(10).Sequence()Need a slice with only the string representations of the dates?
seq := dateseq.New().Steps(10).String()
fmt.Println(seq)Returns the dates in format YYYY-MM-DD:
[2017-10-09 2017-10-08 2017-10-07 2017-10-06 2017-10-05]For a custom output format use the Format(layout string) method, which returns the string in a layout defined by the time package.
seq := dateseq.New().Steps(10).Format("Jan 01. 2006")