date

package
v2.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 6 Imported by: 0

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

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

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

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

func FromProto(p ProtoDate) Date

FromProto converts a google proto date to a date.

func MustParse

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

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

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

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

func (d Date) After(other Date) bool

After reports whether the date is after the other.

func (Date) AsNullable

func (d Date) AsNullable() *Date

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

func (Date) Before

func (d Date) Before(other Date) bool

Before reports whether this date is before the other.

func (Date) Day

func (d Date) Day() int

Day returns the day of the date.

func (Date) Earliest

func (d Date) Earliest(other Date) Date

Earliest returns the earliest of the dates.

func (Date) Equal

func (d Date) Equal(other Date) bool

Equal reports whether this date is equal to the other.

func (Date) Format

func (d Date) Format(layout string) string

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

func (Date) GoString

func (d Date) GoString() string

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

func (Date) IsAfter

func (d Date) IsAfter(date Date) bool

IsAfter reports whether the date is after the other date.

func (Date) IsBefore

func (d Date) IsBefore(date Date) bool

IsBefore reports whether the date is before the other date.

func (Date) IsBetween

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

func (d Date) IsEqual(date Date) bool

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

func (Date) IsNotEqual added in v2.4.0

func (d Date) IsNotEqual(other Date) bool

IsNotEqual reports whether this date is not equal to the other.

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

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

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

MarshalText Implements encoding.TextMarshaler for Date

func (Date) Max

func (d Date) Max(other Date) Date

Max returns the latest of the two dates.

func (Date) Min

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

func (d Date) NonZeroMin(other Date) Date

NonZeroMin returns the earlier of the two dates ignoring zero values. If both are zero, returns Zero.

func (Date) String

func (d Date) String() string

func (Date) Sub

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

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 this date. Sunday is day 0.

func (Date) Year

func (d Date) Year() int

Year returns the year of the date.

type ProtoDate

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