date

package
v0.0.0-...-9d7fed6 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date struct {
	Year  int
	Month int
	Day   int
}

Date represents a date without time information; it may represent only a year (month and day may be zero, comparisons work correctly in this case).

func AsDate

func AsDate(t time.Time) Date

AsDate converts a time.Time into a Date object.

func Build

func Build(year, month, day int) Date

Build creates a Date from year, month, day

func ParseAllDates

func ParseAllDates(s string) []Date

ParseAllDates returns a slice of Date objects found in the given string.

func ParseDate

func ParseDate(s string) (Date, int)

ParseDate parses a string and looks for the first thing in it that could be a date. If none are found, it returns a zero date. It also returns an index into the string pointing past the date that was found. If no date was found, the index is 0. The regex and logic are fairly finicky, which avoids lots of conditionals (perhaps at the expense of clarity).

func ParseOnly

func ParseOnly(s string) Date

ParseOnly calls ParseDate and ignores its returned index.

func (Date) AsTime

func (d Date) AsTime() time.Time

AsTime converts the date object into the best representation of a time.Time

func (Date) CompareTo

func (d Date) CompareTo(other Date) int

CompareTo compares two date objects to an appropriate level of precision, and returns <0 if the receiver is less than other, >0 if it's greater than, and 0 if they're equal (at the level to which they can be compared). If one of the dates has different precision than the other, they are only compared to the lesser precision. An empty Date is considered to be less than any non-empty date and equal to itself.

func (Date) IsZero

func (d Date) IsZero() bool

IsZero returns true if the Date object is the zero value

func (Date) MarshalJSON

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

MarshalJSON implements json.Marshaler

func (Date) ToString

func (d Date) ToString() string

ToString returns a string representation of the date to the appropriate level of precision.

Jump to

Keyboard shortcuts

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