date

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const RFC3339Date = `2006-01-02`
View Source
const RFC3339DateJSON = `"` + RFC3339Date + `"`

Variables

View Source
var ErrInvalidDate = errors.New("invalid date")

Functions

This section is empty.

Types

type Date

type Date struct {
	// contains filtered or unexported fields
}

Date represents a date without time. It is a wrapper around time.Time.

func From

func From(t time.Time) Date

From returns a new date from the given time. The time is truncated to the day.

func New

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

New returns a new date with the given year, month and day.

func Parse

func Parse(s string) (Date, bool)

Parse parses a date in RFC3339 format (yyyy-mm-dd).

func Today

func Today() Date

Today returns the current date in UTC. It is a convenience function for From(time.Now()). It is equivalent to the current day at 00:00 time.

func (Date) Add

func (d Date) Add(duration time.Duration) Date

Add returns the date with the given duration added. Only the date part is used, the time part is ignored.

func (Date) AddDate

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

AddDate returns the date with the given number of years, months and days added. To subtract, use negative values.

func (Date) AddDays

func (d Date) AddDays(days int) Date

AddDays returns the date with the given number of days added. To subtract, use negative values.

func (Date) Day

func (d Date) Day() int

Day returns the day of the date.

func (Date) Format

func (d Date) Format(layout string) string

Format returns a textual representation of the date in the provided format.

func (Date) IsZero

func (d Date) IsZero() bool

IsZero returns true if the date is the zero value. January 1, year 1, UTC

func (Date) MarshalBSONValue

func (d Date) MarshalBSONValue() (bsontype.Type, []byte, error)

func (Date) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface. Converts to "yyyy-MMM-dd" format.

func (Date) Month

func (d Date) Month() time.Month

Month returns the month of the date.

func (Date) Time

func (d Date) Time() time.Time

Time returns the time.Time representation of the date.

func (*Date) UnmarshalBSONValue

func (d *Date) UnmarshalBSONValue(t bsontype.Type, data []byte) error

func (*Date) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface. Converts from "yyyy-MMM-dd" format.

func (Date) Weekday

func (d Date) Weekday() time.Weekday

Weekday returns the day of the week specified by the date. Sunday is day 0.

func (Date) Year

func (d Date) Year() int

Year returns the year of the date.

Jump to

Keyboard shortcuts

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