dateseq

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2017 License: MIT Imports: 2 Imported by: 0

README

Software License Go Doc Go Report Card

dateseq

A package to create a sequence series of daily dates, written in golang.

seq := dateseq.New()
seq = seq.Duration(10)

for k, v := range seq.Seq() {
    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 Tue

Weekends can be included with InclWeekends() into the sequence series. ExclWeekends() will exclude them again, which is also the default behavior.

seq := dateseq.New()
seq = seq.InclWeekends().Duration(10)

for k, v := range seq.Seq() {
    fmt.Printf("%v. %v\n", k, v.Format("2006-01-02 Mon"))
}

Returns:

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 Sat

The sequence methods are chainable, wich allows creation and retrieving of the sequence slice in one go.

seq := dateseq.New().Duration(10).Seq()

Need a slice with only the string representations of the dates?

seq := dateseq.New().Duration(10).String()
fmt.Println(seq)

Returns:

[2017-10-09 2017-10-08 2017-10-07 2017-10-06 2017-10-05]

Documentation

Overview

Package dateseq creates a sequence series of daily dates

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sequence

type Sequence struct {
	// contains filtered or unexported fields
}

Sequence represents a slice of dates.

func New

func New() Sequence

New returns a Sequence ready for use.

func (Sequence) Asc added in v0.1.2

func (s Sequence) Asc() Sequence

Asc sorts a slice of dates in ascending order, i.e. 2006-01-02 comes before 2006-01-03

func (Sequence) Desc added in v0.1.2

func (s Sequence) Desc() Sequence

Desc sorts a slice of dates in descending order, i.e. 2006-01-01 comes after 2006-01-02

func (Sequence) Duration

func (s Sequence) Duration(i int) Sequence

Duration creates a date sequence with the specified length of days ending now. Calls to Duration will reset the sequence slice to nil before generating an new sequence.

func (Sequence) ExclWeekends

func (s Sequence) ExclWeekends() Sequence

ExclWeekends excludes Saturday and Sunday from the sequence. This is the default setting for weekends.

func (Sequence) InclWeekends

func (s Sequence) InclWeekends() Sequence

InclWeekends includes Saturday and Sunday into the sequence.

func (Sequence) Seq

func (s Sequence) Seq() []time.Time

Seq returns the sequence slice.

func (Sequence) String added in v0.1.2

func (s Sequence) String() []string

String returns the sequence as slice with a simple string repesentation of the date in the format YYYY-MM-DD.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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