dates

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: Apache-2.0 Imports: 5 Imported by: 3

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

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

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

func (d Date) AddWeeks(amount int) Date

AddWeeks adds the given amount of weeks to d

func (Date) Copy

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

func (d Date) SetDay(day int) Date

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

func (Date) SetMonth

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

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

func (Date) SetUnix

func (d Date) SetUnix(sec int64) Date

SetUnix returns the date corresponding to the given unix timestamp

func (Date) SetYear

func (d Date) SetYear(year int) Date

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

func (Date) StartOfMonth

func (d Date) StartOfMonth() Date

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

func (Date) StartOfYear

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

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

func (d DateTime) AddWeeks(amount int) DateTime

AddWeeks adds the given amount of weeks to d

func (DateTime) Copy

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

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

func (d DateTime) SetDay(day int) DateTime

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

func (DateTime) SetHour

func (d DateTime) SetHour(hour int) DateTime

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

func (DateTime) SetMinute

func (d DateTime) SetMinute(min int) DateTime

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

func (DateTime) SetMonth

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

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

func (DateTime) SetSecond

func (d DateTime) SetSecond(sec int) DateTime

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

func (DateTime) SetUnix

func (d DateTime) SetUnix(sec int64) DateTime

SetUnix returns the DateTime corresponding to the given unix timestamp

func (DateTime) SetYear

func (d DateTime) SetYear(year int) DateTime

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

func (DateTime) StartOfDay

func (d DateTime) StartOfDay() DateTime

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

func (DateTime) StartOfHour

func (d DateTime) StartOfHour() DateTime

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

func (DateTime) StartOfMonth

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

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

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

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