dates

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2019 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

View Source
var TimeZoneList = []string{}/* 592 elements not displayed */

TimeZoneList is the list of all known time zones. Use this var if you need to add a new TimeZone, but Call dates.TimeZones to get the list.

Functions

func LoadLocation added in v0.0.6

func LoadLocation(name string) (*time.Location, error)

LoadLocation returns the Location with the given name.

If the name is "" or "UTC", LoadLocation returns UTC. If the name is "Local", LoadLocation returns Local.

Otherwise, the name is taken to be a location name corresponding to a file in the IANA Time Zone database, such as "America/New_York".

func TimeZones added in v0.0.6

func TimeZones() []string

TimeZones returns a list of all known time zones.

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 with UTC timezone

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) In added in v0.0.6

func (d DateTime) In(loc *time.Location) DateTime

In returns d with the location information set to loc. In panics if loc is nil.

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) UTC added in v0.0.6

func (d DateTime) UTC() DateTime

UTC returns d with the location set to UTC.

func (DateTime) Value

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

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

func (DateTime) WithTimezone added in v0.0.6

func (d DateTime) WithTimezone(tz string) (DateTime, error)

WithTimezone returns d with a location corresponding to the given timezone identifier (IANA Time Zone database) returns an error if the name is not found

Jump to

Keyboard shortcuts

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