date

package
v0.48.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

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

Variables

View Source
var Empty = Date{}

Empty is the zero value for a date. It is January 1, year 1, UTC.

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 FromIn added in v0.42.0

func FromIn(t time.Time, locationName string) (Date, error)

FromIn returns a new date from the given time in the given location name. The time is truncated to the day.

func FromInLoc added in v0.42.0

func FromInLoc(t time.Time, loc *time.Location) Date

FromInLoc returns a new date from the given time in the given location. The time is truncated to the day.

func FromInMust added in v0.42.0

func FromInMust(t time.Time, locationName string) Date

FromInMust returns a new date from the given time in the given location name. The time is truncated to the day.

func FromProto added in v0.36.2

func FromProto(p ProtoDate) Date

FromProto converts a google proto date to a date.

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 MustTodayIn added in v0.42.0

func MustTodayIn(locationName string) Date

MustTodayIn returns the current date in the given location name. If locationName is invalid, it panics.

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 TodayIn added in v0.42.0

func TodayIn(locationName string) (Date, error)

TodayIn returns the current date in the given location name. If locationName is invalid, an error is returned.

func TodayInLoc added in v0.42.0

func TodayInLoc(loc *time.Location) Date

TodayInLoc returns the current date in the given location. It is a convenience function for From(time.Now().In(loc)).

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) Earliest added in v0.46.0

func (d Date) Earliest(other Date) Date

Earliest returns the earliest of the dates.

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) GoString added in v0.36.0

func (d Date) GoString() string

GoString returns a string representation of the date in Go syntax.

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) Latest added in v0.46.0

func (d Date) Latest(other Date) Date

Latest returns the latest of the dates.

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) MarshalText added in v0.40.0

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

MarshalText Implements encoding.TextMarshaler for Date

func (Date) Max added in v0.46.0

func (d Date) Max(other Date) Date

Max returns the latest of the two dates.

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) UnmarshalText added in v0.40.0

func (d *Date) UnmarshalText(text []byte) error

UnmarshalText Implements encoding.TextUnmarshaler for Date

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.

type ProtoDate added in v0.36.2

type ProtoDate interface {
	GetYear() int32
	GetMonth() int32
	GetDay() int32
}

ProtoDate is a date proto interface to read Proto buffer google dates.

Jump to

Keyboard shortcuts

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