dates

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 5 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// DefaultServerDateFormat is the Go layout for Date objects
	DefaultServerDateFormat = "2006-01-02"
)
View Source
const (
	// 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) AddWeeks added in v0.0.9

func (d Date) AddWeeks(amount int) Date

AddWeeks adds the given amount of weeks to d

func (Date) Copy added in v0.0.9

func (d Date) Copy() Date

Copy returns a copy of d

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) SetDay added in v0.0.9

func (d Date) SetDay(day int) Date

SetDay changes the day value of d returns d for chained calls

func (Date) SetMonth added in v0.0.9

func (d Date) SetMonth(month time.Month) Date

SetMonth changes the month value of d returns d for chained calls

func (Date) SetUnix added in v0.0.9

func (d Date) SetUnix(sec int64) Date

SetUnix returns the date corresponding to the given unix timestamp

func (Date) SetYear added in v0.0.9

func (d Date) SetYear(year int) Date

SetYear changes the year value of d returns d for chained calls

func (Date) StartOfMonth added in v0.0.9

func (d Date) StartOfMonth() Date

StartOfMonth returns the date corresponding to the first day of d's current month

func (Date) StartOfYear added in v0.0.9

func (d Date) StartOfYear() Date

StartOfYear returns the date corresponding to the first day of d's year

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) ToDateTime added in v0.0.9

func (d Date) ToDateTime() DateTime

ToDateTime returns the Date of this DateTime

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) AddWeeks added in v0.0.9

func (d DateTime) AddWeeks(amount int) DateTime

AddWeeks adds the given amount of weeks to d

func (DateTime) Copy added in v0.0.9

func (d DateTime) Copy() DateTime

Copy returns a copy of d

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) SetDay added in v0.0.9

func (d DateTime) SetDay(day int) DateTime

SetDay changes the day value of d returns d for chained calls

func (DateTime) SetHour added in v0.0.9

func (d DateTime) SetHour(hour int) DateTime

SetHour changes the hour value of d returns d for chained calls

func (DateTime) SetMinute added in v0.0.9

func (d DateTime) SetMinute(min int) DateTime

SetMinute changes the minute value of d returns d for chained calls

func (DateTime) SetMonth added in v0.0.9

func (d DateTime) SetMonth(month time.Month) DateTime

SetMonth changes the month value of d returns d for chained calls

func (DateTime) SetSecond added in v0.0.9

func (d DateTime) SetSecond(sec int) DateTime

SetSecond changes the second value of d returns d for chained calls

func (DateTime) SetUnix added in v0.0.9

func (d DateTime) SetUnix(sec int64) DateTime

SetUnix returns the DateTime corresponding to the given unix timestamp

func (DateTime) SetYear added in v0.0.9

func (d DateTime) SetYear(year int) DateTime

SetYear changes the year value of d returns d for chained calls

func (DateTime) StartOfDay added in v0.0.9

func (d DateTime) StartOfDay() DateTime

StartOfDay returns the DateTime corresponding to the beginning of the day, at 00:00

func (DateTime) StartOfHour added in v0.0.9

func (d DateTime) StartOfHour() DateTime

StartOfHour returns the DateTime corresponding to the beginning of the current hour

func (DateTime) StartOfMonth added in v0.0.9

func (d DateTime) StartOfMonth() DateTime

StartOfMonth returns the DateTime corresponding to the first day of d's current month at 00:00

func (DateTime) StartOfYear added in v0.0.9

func (d DateTime) StartOfYear() DateTime

StartOfYear returns the DateTime corresponding to the first day of d's year at 00:00

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