date

package module
v0.0.0-...-cb627d2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 6 Imported by: 0

README

date - dates as Julian Days with methods to make them easy to work with - Golang

GoDoc Maintainability Coverage

Install:

go get github.com/muir/date

Date

Go has a very nice time package. Using times for dates is a bit awkward for a number of reasons.

Using YYYY-MM-DD strings as dates is easy to work read, but hard to manipulate.

Using Julian Days is efficient and date math is super easy, but they're not human readable.

This package makes Julian Days human readable by providing a .String() method and by implementing encoding.TextMarshaler and encoding.TextUnmarshaler so that dates look great when used as map keys and as values.

Database convience is provided by implementations of sql.Valuer and sql.Scanner

Development status

This is brand new code. It has tests, but it isn't used anywhere yet.

Documentation

Index

Constants

View Source
const Zero = Date(0)

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date int

Date represents a date using a Julian Day that has been wrapped with methods to make it easy to use and easy to work with. Potentially the structure of Date could change in the future for performance reasons. The internal structure is guaranteed to remain compatible for use as a map key and remain comparable for < = >.

func FromJD

func FromJD(j int) Date

func FromString

func FromString(s string) (Date, error)

FromString parses dates in the format YYYY-MM-DD The empty string becomes the zero date.

func FromTime

func FromTime(t time.Time) Date

func MustFromString

func MustFromString(s string) Date

func MustParse

func MustParse(format string, date string) Date

func Parse

func Parse(format string, date string) (Date, error)

Parse works the same as time.Parse but only pays attention to 2006 01 02

func (Date) AddDate

func (d Date) AddDate(years int, months int, days int) Date

AddDate is just like time.AddDate

func (Date) Format

func (d Date) Format(format string) string

Format is just time.Format

func (Date) IsZero

func (d Date) IsZero() bool

func (Date) JD

func (d Date) JD() int

func (Date) MarshalText

func (d Date) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler so that dates look good in JSON map keys and other places.

func (*Date) Scan

func (d *Date) Scan(src interface{}) error

Scan implements sql.Scanner for database reads

func (Date) String

func (d Date) String() string

String formats dates as YYYY-MM-DD The zero date becomes the empty string.

func (Date) Sub

func (d1 Date) Sub(d2 Date) int

func (Date) Time

func (d Date) Time() time.Time

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler

func (Date) Value

func (d Date) Value() (driver.Value, error)

Value implements sql.Valuer

Jump to

Keyboard shortcuts

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