time

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT, Apache-2.0 Imports: 12 Imported by: 11

Documentation

Index

Constants

View Source
const (
	InvalidNil
	InvalidUnderflow
	InvalidOverflow
	InvalidNanos
)
View Source
const (
	LayoutTimeMacro   = "2006-01-02 15:04:05.999999"
	LayoutCompactDate = "20060102"
	LayoutCompactTime = "20060102150405"
	LayoutRFC1        = "2006/01/02 - 15:04:05"
)
View Source
const (
	DayEndTime            = "23:59:59"
	DayEndTimeWithSpace   = " 23:59:59"
	DayBeginTime          = "00:00:00"
	DayBeginTimeWithSpace = " 00:00:00"
)
View Source
const (
	Day             = time.Hour * 24
	MonthDay30      = Day * 30
	MonthDay31      = Day * 31
	MonthDay28      = Day * 28
	MonthDay29      = Day * 29
	Month           = MonthDay30
	YearDay365      = Day * 365
	YearDay366      = Day * 366
	Year            = YearDay365
	SecondsOfDay    = HoursOfDay * SecondsOfHour
	SecondsOfMinute = 60
	SecondsOfHour   = MinutesOfHour * SecondsOfMinute
	MinutesOfHour   = 60
	MinutesOfDay    = MinutesOfHour * HoursOfDay
	HoursOfDay      = 24
)
View Source
const (
	January   = "January"
	February  = "February"
	March     = "March"
	April     = "April"
	May       = "May"
	June      = "June"
	July      = "July"
	August    = "August"
	September = "September"
	October   = "October"
	November  = "November"
	December  = "December"
)
View Source
const (
	Monday    = "Monday"
	Tuesday   = "Tuesday"
	Wednesday = "Wednesday"
	Thursday  = "Thursday"
	Friday    = "Friday"
	Saturday  = "Saturday"
	Sunday    = "Sunday"
)

Variables

View Source
var (
	DefaultEncoding = &Encoding{
		Layout: time.RFC3339Nano,
	}
	EncodingUnixSeconds = &Encoding{
		encodeType: encodeTypeUnixSeconds,
	}
	EncodingUnixMilliseconds = &Encoding{
		encodeType: encodeTypeUnixMilliseconds,
	}
	EncodingUnixMicroseconds = &Encoding{
		encodeType: encodeTypeUnixMicroseconds,
	}
	EncodingUnixNanoseconds = &Encoding{
		encodeType: encodeTypeUnixNanoseconds,
	}
)
View Source
var ZeroTime = time.Time{}

Functions

func Check

func Check(x Time) uint

Check returns the result.

func CheckValid

func CheckValid(x Time) error

CheckValid reports whether the condition holds.

func GetTomorrowYMD

func GetTomorrowYMD(sep string) string

GetTomorrowYMD formats tomorrow as YYYY{sep}MM{sep}DD.

func GetYM

func GetYM(time time.Time, sep string) string

GetYM formats the date as YYYY{sep}MM.

func GetYMD

func GetYMD(time time.Time, sep string) string

GetYMD formats the date as YYYY{sep}MM{sep}DD.

func GetYesterdayYMD

func GetYesterdayYMD(sep string) string

GetYesterdayYMD formats yesterday as YYYY{sep}MM{sep}DD.

func IsValid

func IsValid(x Time) bool

IsValid reports whether the condition holds.

func MarshalJSON

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

MarshalJSON encodes the value.

func MarshalText

func MarshalText(t time.Time) ([]byte, error)

MarshalText encodes the value.

func NormalizeDuration added in v1.3.20

func NormalizeDuration(td time.Duration, stdTd time.Duration) time.Duration

NormalizeDuration scales td relative to stdTd when td is given without an explicit unit.

func ParseDate

func ParseDate(t string) (time.Time, error)

ParseDate parses a date-only string.

func ParseDateTime

func ParseDateTime(t string) (time.Time, error)

ParseDateTime parses a full date-time string.

func ParseTime

func ParseTime(t string) (time.Time, error)

ParseTime parses a time-only string.

func SetSysTime added in v1.3.20

func SetSysTime(t time.Time)

SetSysTime updates or inserts a value.

func StrToIntMonth

func StrToIntMonth(month string) int

StrToIntMonth converts a month name to its numeric value.

func SyncHwTime

func SyncHwTime()

SyncHwTime performs the operation.

func TodayZeroTime

func TodayZeroTime() time.Time

TodayZeroTime returns today's date in the local time zone with time set to 00:00:00.

func UnixNano

func UnixNano(nsec int64) time.Time

UnixNano converts a Unix nanosecond timestamp to time.Time.

func UnmarshalJSON

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

UnmarshalJSON decodes into the value.

func UnmarshalText

func UnmarshalText(t *time.Time, data []byte) error

UnmarshalText decodes into the value.

func YesterdayZeroTime added in v1.6.3

func YesterdayZeroTime() time.Time

YesterdayZeroTime returns the local date for yesterday at 00:00:00.

Types

type Date

type Date int32

1-01-01~9999-12-31

func DateFromTime

func DateFromTime(t time.Time) Date

DateFromTime returns the result.

func (*Date) GobDecode

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

GobDecode decodes into the value.

func (Date) GobEncode

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

GobEncode encodes the value.

func (Date) GormDataType

func (d Date) GormDataType() string

GormDataType returns the result.

func (Date) MarshalBinary

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

MarshalBinary encodes the value.

func (Date) MarshalGQL

func (d Date) MarshalGQL(w io.Writer)

MarshalGQL encodes the value.

func (Date) MarshalJSON

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

MarshalJSON encodes the value.

func (Date) MarshalText

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

MarshalText encodes the value.

func (*Date) Scan

func (d *Date) Scan(value interface{}) (err error)

Scan scan time.

func (Date) String

func (d Date) String() string

String returns the string representation.

func (Date) Time

func (d Date) Time() time.Time

Time returns the result.

func (*Date) UnmarshalBinary

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

UnmarshalBinary implements the DefaultEncoding.BinaryUnmarshaler interface.

func (*Date) UnmarshalGQL

func (d *Date) UnmarshalGQL(v interface{}) error

UnmarshalGQL decodes into the value.

func (*Date) UnmarshalJSON

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

UnmarshalJSON decodes into the value.

func (*Date) UnmarshalText

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

UnmarshalText decodes into the value.

func (Date) Value

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

Value get time value.

type DateTime

type DateTime int64

01-01-01 00:00:00~9999-12-31 23:59:59

func DateTimeFromTime

func DateTimeFromTime(t time.Time) DateTime

DateTimeFromTime returns the result.

func (DateTime) Date

func (ts DateTime) Date() Date

Date returns the result.

func (DateTime) GormDataType

func (ts DateTime) GormDataType() string

GormDataType returns the result.

func (DateTime) MarshalJSON

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

MarshalJSON encodes the value.

func (DateTime) MarshalText

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

MarshalText encodes the value.

func (*DateTime) Scan

func (d *DateTime) Scan(value interface{}) (err error)

Scan scan time.

func (DateTime) Time

func (d DateTime) Time() time.Time

Time returns the result.

func (*DateTime) UnmarshalJSON

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

UnmarshalJSON decodes into the value.

func (*DateTime) UnmarshalText

func (d *DateTime) UnmarshalText(data []byte) error

UnmarshalText decodes into the value.

func (DateTime) Value

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

Value get time value.

type Duration

type Duration int64

Duration be used toml unmarshal string time, like 1s, 500ms.

func (Duration) MarshalJSON added in v1.6.7

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

MarshalJSON encodes the duration as a JSON string.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText encodes the duration as a string.

func (Duration) Shrink

Shrink will decrease the duration by comparing with context's timeout duration and return new timeout\context\CancelFunc.

func (*Duration) UnmarshalJSON added in v1.6.7

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

UnmarshalJSON implements the encoding/json.Unmarshaler interface. The time must be a quoted string in the RFC 3339 format.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText unmarshal text to duration.

type Encoding

type Encoding struct {
	Layout string
	// contains filtered or unexported fields
}

func NewLayOutEncoding added in v1.7.18

func NewLayOutEncoding(layout string) *Encoding

NewLayOutEncoding creates and returns a new instance.

type EncodingTime

type EncodingTime struct {
	time.Time
	*Encoding
}

func (EncodingTime) MarshalJSON

func (u EncodingTime) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value.

func (*EncodingTime) UnmarshalJSON

func (u *EncodingTime) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes into the value.

type FixedTicker added in v1.7.18

type FixedTicker time.Ticker

func (*FixedTicker) Channel added in v1.7.18

func (t *FixedTicker) Channel() <-chan time.Time

Channel returns the result.

func (*FixedTicker) Reset added in v1.7.18

func (t *FixedTicker) Reset(d time.Duration) bool

Reset removes or resets state.

func (*FixedTicker) Stop added in v1.7.18

func (t *FixedTicker) Stop() bool

Stop closes and releases resources.

func (*FixedTicker) Wait added in v1.7.18

func (t *FixedTicker) Wait()

Wait performs the operation.

type GlobEncodingTime added in v1.3.20

type GlobEncodingTime time.Time

func (GlobEncodingTime) MarshalJSON added in v1.3.20

func (u GlobEncodingTime) MarshalJSON() ([]byte, error)

MarshalJSON encodes the value.

func (*GlobEncodingTime) UnmarshalJSON added in v1.3.20

func (u *GlobEncodingTime) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes into the value.

type RandTicker

type RandTicker struct {
	// contains filtered or unexported fields
}

func (*RandTicker) Reset

func (t *RandTicker) Reset(d time.Duration) bool

Reset removes or resets state.

func (*RandTicker) Stop

func (t *RandTicker) Stop() bool

Stop closes and releases resources.

func (*RandTicker) Wait

func (t *RandTicker) Wait()

Wait performs the operation.

type Ticker

type Ticker interface {
	Reset(time.Duration) bool
	Stop() bool
	Wait()
}

func NewRandTicker

func NewRandTicker(minInterval, maxInterval time.Duration) Ticker

NewRandTicker creates and returns a new instance.

func NewTicker

func NewTicker(interval time.Duration) Ticker

NewTicker creates and returns a new instance.

type Time

type Time interface {
	GetSeconds() int64
	GetNanos() int32
}

Jump to

Keyboard shortcuts

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