date

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package date implements types a time-zone-independent representation of time.

Use time.Time for that purpose if location information is required.

Index

Constants

View Source
const ISO8601 = "2006-01-02"

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date struct {
	Year  int
	Month Month
	Day   int
}

A Date represents a date (year, month, day).

func DateOf

func DateOf(t time.Time) (d Date)

DateOf

func Now

func Now() Date

Now returns the current Date.

func Parse

func Parse(s string) (Date, error)

Parse parses a string in RFC3339 full-date formate and returns the value as a Date.

func (Date) Add

func (d Date) Add(n int) Date

Add returns the Date that is n days in the future. n can also be negative to go into the past.

func (Date) After

func (d Date) After(d2 Date) bool

After reports whether d occurs after d2.

func (Date) Before

func (d Date) Before(d2 Date) bool

Before reports whether d occurs before d2.

func (Date) Compare

func (d Date) Compare(d2 Date) int

Compare compares two Date instances. If d is before d2, it returns -1; if d is after d2, it returns +1; if they're the same, it returns 0.

func (Date) In

func (d Date) In(loc *time.Location) time.Time

In returns the time.Time corresponding to time 00:00:00 of the Date in the location.

func (Date) IsValid

func (d Date) IsValid() bool

IsValid reports whether the Date is valid.

func (Date) IsZero

func (d Date) IsZero() bool

IsZero reports whether date fields are set to their default value.

func (Date) MarshalText

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

func (*Date) Scan

func (d *Date) Scan(v any) (err error)

Scan

func (Date) Since

func (d Date) Since(s Date) (days int)

Since returns the signed number of days between the date and s, not including the end day. This is the inverse operation to [Time.Add].

func (Date) String

func (d Date) String() string

func (*Date) UnmarshalText

func (d *Date) UnmarshalText(p []byte) (err error)

func (Date) Value

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

Value

type Month

type Month = time.Month
const (
	January Month = iota + 1
	February
	March
	April
	May
	June
	July
	August
	September
	October
	November
	December
)

Jump to

Keyboard shortcuts

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