week

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: MIT Imports: 6 Imported by: 0

README

CircleCI codecov GoDoc

go-week

The package go-week provides a simple data type representing a week date as defined by ISO 8601.

Versions and stability

This package can be considered stable and ready to use. All releases follow the rules of semantic versioning.

Although the master branch is supposed to remain stable, there is not guarantee that braking changes will not be merged into master when major versions are released. Therefore the repository contains version tags in order to support vendoring tools. The tag names follow common conventions and have the following format v1.0.0. This package supports Go modules introduced with version 1.11.

Dependencies

Build dependencies

  • github.com/pkg/errors

Test dependencies

  • github.com/DATA-DOG/go-sqlmock
  • github.com/lib/pq (integration tests only)
  • github.com/stretchr/testify

Run unit and integration tests

To run the code analysis and tests, use the following commands:

golangci-lint run -v --config .golangci.yml ./...

# without integration tests
go test ./...

# with integration tests (requires test db)
go test -tags=integration ./...

License

This project is open source an published under the MIT license.

Documentation

Overview

Package week provides a simple data type representing a week date as defined by ISO 8601.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NullWeek

type NullWeek struct {
	Week  Week
	Valid bool
}

NullWeek is a nullable Week representation.

func NewNullWeek

func NewNullWeek(week Week, valid bool) NullWeek

NewNullWeek creates a new NullWeek.

func NullWeekFrom

func NullWeekFrom(week Week) NullWeek

NullWeekFrom creates a new NullWeek that will always be valid.

func NullWeekFromPtr

func NullWeekFromPtr(week *Week) NullWeek

NullWeekFromPtr creates a new NullWeek that may be null if week is nil.

func (NullWeek) IsZero

func (n NullWeek) IsZero() bool

IsZero returns true for invalid NullWeeks.

func (NullWeek) MarshalJSON

func (n NullWeek) MarshalJSON() ([]byte, error)

MarshalJSON implements the json Marshaler interface.

func (NullWeek) MarshalText

func (n NullWeek) MarshalText() ([]byte, error)

MarshalText implements the encoding TextMarshaler interface.

func (NullWeek) Ptr

func (n NullWeek) Ptr() *Week

Ptr returns a pointer to this NullWeek's value, or a nil pointer it it is invalid.

func (*NullWeek) Scan

func (n *NullWeek) Scan(value interface{}) error

Scan implements the sql Scanner interface.

func (*NullWeek) UnmarshalJSON

func (n *NullWeek) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json Unmarshaler interface.

func (*NullWeek) UnmarshalText

func (n *NullWeek) UnmarshalText(text []byte) error

UnmarshalText implements the encoding TextUnmarshaler interface.

func (NullWeek) Value

func (n NullWeek) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Week

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

Week represents a week date as defined by ISO 8601. Week can be marshaled to and unmarshaled from numerous formats such as plain text or json.

func FromTime added in v0.0.2

func FromTime(t time.Time) Week

FromTime converts time.Time into a Week

func New

func New(year, week int) (Week, error)

New creates a new Week object from the specified year and week.

func (*Week) Add added in v0.0.5

func (w *Week) Add(weeks int) (Week, error)

Add calculates and returns a week that is the given positive distance (number of weeks) from the current week

func (*Week) After added in v0.0.6

func (w *Week) After(u Week) bool

After reports whether the week instant w is after u

func (*Week) Before added in v0.0.6

func (w *Week) Before(u Week) bool

Before reports whether the week w is before u

func (*Week) Equal added in v0.0.6

func (w *Week) Equal(u Week) bool

Equal reports whether w and u are the same week of the same year

func (Week) MarshalJSON

func (w Week) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Week.

func (Week) MarshalText

func (w Week) MarshalText() ([]byte, error)

MarshalText implements TextMarshaler for Week.

func (*Week) Next

func (w *Week) Next() (Week, error)

Next calculates and returns the next week. If the next week is invalid (year > 9999) the function returns an error.

func (*Week) Previous

func (w *Week) Previous() (Week, error)

Previous calculates and returns the previous week. If the previous week is invalid (year < 0) the function returns an error.

func (*Week) Scan

func (w *Week) Scan(src interface{}) error

Scan implements scanner for Week.

func (Week) String added in v1.1.0

func (w Week) String() string

String converts a Week into its string representation

func (*Week) Sub added in v0.0.5

func (w *Week) Sub(u Week) int

Sub calculates the positive difference between w and u (w-u) in number of weeks

func (*Week) Time added in v0.0.3

func (w *Week) Time(weekday time.Weekday) time.Time

Time converts a week to a time.Time object which represents the midnight of the provided weekday.

func (*Week) UnmarshalJSON

func (w *Week) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for Week.

func (*Week) UnmarshalText

func (w *Week) UnmarshalText(data []byte) error

UnmarshalText implements TextUnmarshaler for Week.

func (Week) Value

func (w Week) Value() (driver.Value, error)

Value implements Valuer for Week.

func (*Week) Week added in v0.0.2

func (w *Week) Week() int

Week returns the week of the ISO week date.

func (*Week) Year added in v0.0.2

func (w *Week) Year() int

Year returns the year of the ISO week date.

Jump to

Keyboard shortcuts

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