date

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 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

This section is empty.

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

func (d Date) Add(duration Duration) 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) Sub

func (d Date) Sub(duration Duration) Date

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)

type Duration

type Duration int

Number of days.

const (
	Day      Duration = 1
	WorkWeek Duration = 5
	Week     Duration = 7
	Year     Duration = 365
	LeapYear Duration = 366
)

Jump to

Keyboard shortcuts

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