date

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 4 Imported by: 0

README

date

Simple Go package for dealing with dates as a serializable type. Like time.Time, but just the date.

The date.Date type implements json.Marshaler, json.Unmarshaler, sql.Scanner, and driver.Valuer, meaning you can serialize it to and from json as well as databases.

You can perform simple arithmetic on date values using date.Duration. For example, you can do date.Today().Add(3 * date.Day) to specify a date 3 days in the future.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DaysSince added in v1.2.0

func DaysSince(d Date) int

func MonthsSince added in v1.1.0

func MonthsSince(d Date) int

func YearsSince added in v1.1.0

func YearsSince(d Date) int

Types

type Date

type Date struct {
	Day   int
	Month time.Month
	Year  int
}

Like time.Time, but only has a date.

func FromTime

func FromTime(t time.Time) Date

func MustParse

func MustParse(str string) Date

func New

func New(year int, month time.Month, day int) Date

func Parse

func Parse(str string) (Date, error)

func Today

func Today() Date

func (Date) AddDays added in v1.1.0

func (d Date) AddDays(days int) Date

func (Date) AddMonths added in v1.1.1

func (d Date) AddMonths(months int) Date

func (Date) AddYears added in v1.1.1

func (d Date) AddYears(years int) Date

func (Date) EndOfDay

func (d Date) EndOfDay() time.Time

func (Date) EndOfDayUTC

func (d Date) EndOfDayUTC() time.Time

func (Date) Equal

func (d Date) Equal(u Date) bool

func (Date) IsZero

func (d Date) IsZero() bool

func (Date) MarshalJSON

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

func (Date) Noon

func (d Date) Noon() time.Time

func (Date) NoonUTC

func (d Date) NoonUTC() time.Time

func (*Date) Scan

func (d *Date) Scan(src any) error

func (Date) StartOfDay

func (d Date) StartOfDay() time.Time

func (Date) StartOfDayUTC

func (d Date) StartOfDayUTC() time.Time

func (Date) String

func (d Date) String() string

func (Date) SubDays added in v1.1.0

func (d Date) SubDays(u Date) int

func (Date) SubMonths added in v1.1.0

func (d Date) SubMonths(u Date) int

func (Date) SubYears added in v1.1.0

func (d Date) SubYears(u Date) int

func (Date) TimeAt

func (d Date) TimeAt(hour, min, sec, nsec int) time.Time

func (Date) TimeAtUTC

func (d Date) TimeAtUTC(hour, min, sec, nsec int) time.Time

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

func (Date) Value

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

Jump to

Keyboard shortcuts

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