dates

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2018 License: Apache-2.0 Imports: 5 Imported by: 14

Documentation

Index

Constants

View Source
const (
	// DefaultServerDateFormat is the Go layout for Date objects
	DefaultServerDateFormat = "2006-01-02"
	// DefaultServerDateTimeFormat is the Go layout for DateTime objects
	DefaultServerDateTimeFormat = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date struct {
	time.Time
}

Date type that JSON marshal and unmarshals as "YYYY-MM-DD"

func ParseDate

func ParseDate(value string) Date

ParseDate returns a date from the given string value that is formatted with the default YYYY-MM-DD format.

It panics in case the parsing cannot be done.

func ParseDateWithLayout

func ParseDateWithLayout(layout, value string) (Date, error)

ParseDateWithLayout returns a date from the given string value that is formatted with layout.

func Today

func Today() Date

Today returns the current date

func (Date) AddDate

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

AddDate adds the given years, months or days to the current date

func (Date) Equal

func (d Date) Equal(other Date) bool

Equal reports whether d and other represent the same day

func (Date) Greater

func (d Date) Greater(other Date) bool

Greater returns true if d is strictly greater than other

func (Date) GreaterEqual

func (d Date) GreaterEqual(other Date) bool

GreaterEqual returns true if d is greater than or equal to other

func (Date) Lower

func (d Date) Lower(other Date) bool

Lower returns true if d is strictly lower than other

func (Date) LowerEqual

func (d Date) LowerEqual(other Date) bool

LowerEqual returns true if d is lower than or equal to other

func (Date) MarshalJSON

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

MarshalJSON for Date type

func (*Date) Scan

func (d *Date) Scan(src interface{}) error

Scan casts the database output to a Date

func (Date) String

func (d Date) String() string

String method for Date.

func (Date) Sub

func (d Date) Sub(t Date) time.Duration

Sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).

func (Date) Value

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

Value formats our Date for storing in database Especially handles empty Date.

type DateTime

type DateTime struct {
	time.Time
}

DateTime type that JSON marshals and unmarshals as "YYYY-MM-DD HH:MM:SS"

func Now

func Now() DateTime

Now returns the current date/time

func ParseDateTime

func ParseDateTime(value string) DateTime

ParseDateTime returns a datetime from the given string value that is formatted with the default YYYY-MM-DD HH:MM:SSformat.

It panics in case the parsing cannot be done.

func ParseDateTimeWithLayout

func ParseDateTimeWithLayout(layout, value string) (DateTime, error)

ParseDateTimeWithLayout returns a datetime from the given string value that is formatted with layout.

func (DateTime) Add

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

Add adds the given duration to this DateTime

func (DateTime) AddDate

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

AddDate adds the given years, months or days to the current DateTime

func (DateTime) Equal

func (d DateTime) Equal(other DateTime) bool

Equal reports whether d and other represent the same time instant

func (DateTime) Greater

func (d DateTime) Greater(other DateTime) bool

Greater returns true if d is strictly greater than other

func (DateTime) GreaterEqual

func (d DateTime) GreaterEqual(other DateTime) bool

GreaterEqual returns true if d is greater than or equal to other

func (DateTime) Lower

func (d DateTime) Lower(other DateTime) bool

Lower returns true if d is strictly lower than other

func (DateTime) LowerEqual

func (d DateTime) LowerEqual(other DateTime) bool

LowerEqual returns true if d is lower than or equal to other

func (DateTime) MarshalJSON

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

MarshalJSON for DateTime type

func (*DateTime) Scan

func (d *DateTime) Scan(src interface{}) error

Scan casts the database output to a DateTime

func (DateTime) String

func (d DateTime) String() string

String method for DateTime.

func (DateTime) Sub

func (d DateTime) Sub(t DateTime) time.Duration

Sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).

func (DateTime) ToDate

func (d DateTime) ToDate() Date

ToDate returns the Date of this DateTime

func (DateTime) Value

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

Value formats our DateTime for storing in database Especially handles empty DateTime.

Jump to

Keyboard shortcuts

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