datetime

package
v0.0.0-...-4d895cd Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDateFormat = "2006-01-02"
View Source
const DefaultDateTimeFormat = "2006-01-02 15:04"
View Source
const DefaultTimeFormat = "15:04"
View Source
const FullDateTimeFormat = "2006-01-02 15:04:05"
View Source
const FullDateTimeFormatWithT = "2006-01-02T15:04:05"
View Source
const RussianDateFormat = "02-01-2006"

Variables

This section is empty.

Functions

This section is empty.

Types

type Date

type Date struct {
	time.Time
}

Date type represents a date with day precision. Date values can be created from YYYY-MM-DD strings and are serialized using the same layout. swaggen:type=string swaggen:format=date

func MustParseDate

func MustParseDate(str string) Date

MustParseDate creates a Date object from a string in YYYY-MM-DD format and panics if the string is not properly formatted.

func NewDate

func NewDate(t time.Time) Date

func ParseDate

func ParseDate(str string) (Date, error)

ParseDate creates a Date value from a string in YYYY-MM-DD format. It will return an error if the string is not properly formatted.

func (Date) EncodeValues

func (d Date) EncodeValues(key string, v *url.Values) error

func (Date) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface and serializes Date value in YYYY-MM-DD format string.

func (Date) String

func (d Date) String() string

String returns a string representation of a Date in YYYY-MM-DD format.

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface and parses a string in YYYY-MM-DD format to Date value.

type DateTime

type DateTime struct {
	time.Time
}

DateTime type represents a time with date with minute precision. swaggen: type=string swaggen: format=date-time

func MustParseDateTime

func MustParseDateTime(str string) DateTime

MustParseDateTime creates a DateTime object from a string in "YYYY-MM-DD HH:mm" format and panics if the string is not properly formatted.

func MustParseTime

func MustParseTime(str string) DateTime

MustParseTime creates a DateTime object from a string in "HH:mm" format. It will return DateTime with date in "0000-01-01" format. It will panic if the string is not properly formatted.

func NewDateTime

func NewDateTime(t time.Time) DateTime

func Now

func Now() DateTime

func ParseDateTime

func ParseDateTime(str string) (DateTime, error)

ParseDateTime creates a DateTime value from a string in "YYYY-MM-DD HH:mm" format. It will return an error if the string is not properly formatted.

func ParseTime

func ParseTime(str string) (DateTime, error)

ParseTime creates a DateTime value from a string in "HH:mm" format. It will return DateTime with date in "0000-01-01" format. It will return an error if the string is not properly formatted.

func (DateTime) AsTime

func (dt DateTime) AsTime() Time

func (DateTime) DefaultDateFormat

func (dt DateTime) DefaultDateFormat() string

DefaultDateFormat returns a string representation of a DateTime in "YYYY-MM-DD" format.

func (DateTime) DefaultTimeFormat

func (dt DateTime) DefaultTimeFormat() string

DefaultTimeFormat returns a string representation of a DateTime in "HH:mm" format.

func (DateTime) EncodeValues

func (dt DateTime) EncodeValues(key string, v *url.Values) error

func (DateTime) EndOfDay

func (dt DateTime) EndOfDay() DateTime

func (DateTime) LocalTimestamp

func (dt DateTime) LocalTimestamp() int64

LocalTimestamp returns unix timestamp + time zone offset.

func (DateTime) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface and serializes DateTime value in "YYYY-MM-DD HH:mm" format string.

func (DateTime) MinutesSinceDateMidnight

func (dt DateTime) MinutesSinceDateMidnight(since DateTime) int

func (DateTime) MinutesSinceMidnight

func (dt DateTime) MinutesSinceMidnight() int

func (DateTime) RoundDown

func (dt DateTime) RoundDown(d time.Duration) DateTime

func (DateTime) RoundUp

func (dt DateTime) RoundUp(d time.Duration) DateTime

func (DateTime) String

func (dt DateTime) String() string

String returns a string representation of a DateTime in "YYYY-MM-DD HH:mm" format.

func (DateTime) TruncateDate

func (dt DateTime) TruncateDate() DateTime

func (*DateTime) UnmarshalJSON

func (dt *DateTime) UnmarshalJSON(input []byte) error

UnmarshalJSON implements the json.Unmarshaler interface and parses a string in "YYYY-MM-DD HH:MM" format to DateTime value.

func (DateTime) WithDate

func (dt DateTime) WithDate(year int, month time.Month, day int) DateTime

type DateTimeProvider

type DateTimeProvider struct{}

func (DateTimeProvider) Now

func (p DateTimeProvider) Now() DateTime

type Time

type Time struct {
	time.Time
}

Time type represents a time with seconds precision. Time values can be created from HH:MM:SS strings and are serialized using the same layout. swaggen:type=string

func MustParseAsTime

func MustParseAsTime(str string) Time

MustParseAsTime creates a Time object from a string in HH:MM:SS format and panics if the string is not properly formatted.

func NewTime

func NewTime(t time.Time) Time

func ParseAsTime

func ParseAsTime(str string) (Time, error)

ParseAsTime creates a Time value from a string in HH:MM:SS format. It will return an error if the string is not properly formatted.

func (Time) DefaultTimeFormat

func (t Time) DefaultTimeFormat() string

DefaultTimeFormat returns a string representation of a Time in HH:MM format.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface and serializes Time value in HH:MM:SS format string.

func (Time) String

func (t Time) String() string

String returns a string representation of a Time in HH:MM:SS format.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface and parses a string in HH:MM:SS format to Time value.

Jump to

Keyboard shortcuts

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