dateseq

package module
v0.1.4 Latest Latest
Warning

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

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

README

Software License Travis Go Doc Coverage Status Go Report Card

dateseq

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

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

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

Weekends can be excluded with ExclWeekends() from the sequence series. InclWeekends() will include them again, which is also the default behavior.

seq := dateseq.New()
seq = seq.ExclWeekends().Steps(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

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

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

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 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")
fmt.Println(seq)

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

func (s Sequence) ExclWeekends() Sequence

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

func (Sequence) Format added in v0.1.3

func (s Sequence) Format(layout string) []string

Format returns the sequence as slice with a string repesentation of the date in the specified layout.

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) Steps added in v0.1.4

func (s Sequence) Steps(i int) Sequence

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

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