date

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 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 MustParse added in v0.25.2

func MustParse(s string) Date

MustParse parses a date in RFC3339 format (yyyy-mm-dd) and panics if the date is invalid. It is intended for use in variable initializations and tests.

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) After added in v0.16.0

func (d Date) After(other Date) bool

After reports whether the date is after the other.

func (Date) AsNullable added in v0.25.0

func (d Date) AsNullable() *Date

AsNullable returns the date as a nullable date (pointer to).

func (Date) Before added in v0.16.0

func (d Date) Before(other Date) bool

Before reports whether the date is before the other.

func (Date) Day

func (d Date) Day() int

Day returns the day of the date.

func (Date) Equal added in v0.16.0

func (d Date) Equal(other Date) bool

Equal reports whether the date is equal to the other.

func (Date) Format

func (d Date) Format(layout string) string

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

func (Date) IsAfter added in v0.32.0

func (d Date) IsAfter(date Date) bool

IsAfter reports whether the date is after the other date.

func (Date) IsBefore added in v0.32.0

func (d Date) IsBefore(date Date) bool

IsBefore reports whether the date is before the other date.

func (Date) IsBetween added in v0.32.0

func (d Date) IsBetween(start, end Date) bool

IsBetween reports whether the date is between the start and end dates (not inclusive).

func (Date) IsEqual added in v0.32.0

func (d Date) IsEqual(date Date) bool

IsEqual reports whether the date is equal to the other date.

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) Min added in v0.20.0

func (d Date) Min(other Date) Date

Min returns the earlier of the two dates.

func (Date) Month

func (d Date) Month() time.Month

Month returns the month of the date.

func (Date) NonZeroMin added in v0.20.0

func (d Date) NonZeroMin(other Date) Date

func (Date) String added in v0.25.1

func (d Date) String() string

func (Date) Sub added in v0.32.0

func (d Date) Sub(other Date) int

Sub returns the number of days between this date and the other 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