time

package
v1.15.5 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidNil
	InvalidUnderflow
	InvalidOverflow
	InvalidNanos
)
View Source
const (
	SecondsOfDay    = 24 * 60 * 60
	SecondsOfMinute = 60
	TimeDay         = SecondsOfDay * time.Second
)
View Source
const (
	LayoutTimeMacro   = "2006-01-02 15:04:05.999999"
	LayoutDateTime    = "2006-01-02 15:04:05"
	LayoutRFC3339     = time.RFC3339
	LayoutTime        = "15:04:05"
	LayoutDate        = "2006-01-02"
	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
)
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 ZeroTime = time.Time{}

Functions

func Check added in v1.5.11

func Check(x TimeCheck) uint

func CheckValid added in v1.5.11

func CheckValid(x TimeCheck) error

func Format

func Format(t time.Time) string

func FormatRelativeTime added in v1.5.11

func FormatRelativeTime(fromTime time.Time) string

func GetTodayZeroTime

func GetTodayZeroTime() time.Time

GetTodayZeroTime 返回今天零点的time

func GetTomorrowYMD

func GetTomorrowYMD(sep string) string

GetTomorrowYMD 得到以sep为分隔符的年、月、日字符串(明天)

func GetYM

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

GetYM 得到以sep为分隔符的年、月字符串(今天所属于的月份)

func GetYMD

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

GetTodayYMD 得到以sep为分隔符的年、月、日字符串(今天)

func GetYesterdayYMD

func GetYesterdayYMD(sep string) string

GetYesterdayYMD 得到以sep为分隔符的年、月、日字符串(昨天)

func GetYesterdayZeroTime

func GetYesterdayZeroTime() time.Time

GetYesterdayZeroTime 返回昨天零点的time

func IsValid added in v1.5.11

func IsValid(x TimeCheck) bool

func MarshalJSON added in v1.5.11

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

func MarshalText added in v1.5.11

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

func Parse

func Parse(layout, value string) (time.Time, error)

func SetEncodingLayout added in v1.5.11

func SetEncodingLayout(l string)

func SetEncodingType added in v1.5.11

func SetEncodingType(typ EncodeType)

func SetUnixSysTime

func SetUnixSysTime(t time.Time)

设置系统时间

func StdDuration

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

标准化TimeDuration

func StrToIntMonth

func StrToIntMonth(month string) int

StrToIntMonth 字符串月份转整数月份

func SyncHwTime

func SyncHwTime()

func TimeCost

func TimeCost(start time.Time) time.Duration

func TodayZeroTime

func TodayZeroTime() time.Time

func UnixNano added in v1.5.11

func UnixNano(nsec int64) time.Time

func UnmarshalJSON added in v1.5.11

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

func UnmarshalText added in v1.5.11

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

Types

type Date

type Date int64

func (Date) GormDataType

func (ts Date) GormDataType() string

func (Date) MarshalJSON

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

func (*Date) Scan

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

Scan scan time.

func (Date) Time added in v1.5.11

func (d Date) Time() time.Time

func (*Date) UnmarshalJSON

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

func (Date) Value

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

Value get time value.

type DateStr added in v1.5.11

type DateStr = TimeStr[Edate]

func NewDateStr added in v1.5.11

func NewDateStr(t time.Time) DateStr

type DateTime added in v1.5.11

type DateTime int64

func (DateTime) GormDataType added in v1.5.11

func (ts DateTime) GormDataType() string

func (DateTime) MarshalJSON added in v1.5.11

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

func (*DateTime) Scan added in v1.5.11

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

Scan scan time.

func (DateTime) Time added in v1.5.11

func (d DateTime) Time() time.Time

func (*DateTime) UnmarshalJSON added in v1.5.11

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

func (DateTime) Value added in v1.5.11

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

Value get time value.

type DateTimeStr added in v1.5.11

type DateTimeStr = TimeStr[EdateTime]

time.DateTime

func NewDateTimeStr added in v1.5.11

func NewDateTimeStr(t time.Time) DateTimeStr

type Duration

type Duration time.Duration

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

func (Duration) MarshalText added in v1.1.0

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

func (Duration) Shrink

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

func (*Duration) UnmarshalText

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

UnmarshalText unmarshal text to duration.

type Edate added in v1.5.11

type Edate struct{}

func (Edate) Encoding added in v1.5.11

func (Edate) Encoding() *Encoding

func (Edate) Layout added in v1.5.11

func (Edate) Layout() string

type EdateTime added in v1.5.11

type EdateTime struct{}

func (EdateTime) Encoding added in v1.5.11

func (EdateTime) Encoding() *Encoding

func (EdateTime) Layout added in v1.5.11

func (EdateTime) Layout() string

type Encode added in v1.5.11

type Encode interface {
	Encoding() *Encoding
}

type EncodeType added in v1.5.11

type EncodeType int8
const (
	EncodeTypeLayout EncodeType = iota
	EncodeTypeUnixSeconds
	EncodeTypeUnixMilliseconds
	EncodeTypeUnixMicroseconds
	EncodeTypeUnixNanoseconds
)

type Encoding added in v1.5.11

type Encoding struct {
	EncodeType
	Layout string
}

func (*Encoding) SetLayout added in v1.5.11

func (u *Encoding) SetLayout(l string)

func (*Encoding) SetType added in v1.5.11

func (u *Encoding) SetType(typ EncodeType)

type Etime added in v1.5.11

type Etime struct{}

func (Etime) Encoding added in v1.5.11

func (Etime) Encoding() *Encoding

func (Etime) Layout added in v1.5.11

func (Etime) Layout() string

type FixTicker added in v1.5.11

type FixTicker time.Ticker

func (*FixTicker) Channel added in v1.5.11

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

func (*FixTicker) Reset added in v1.5.11

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

func (*FixTicker) Stop added in v1.5.11

func (t *FixTicker) Stop() bool

func (*FixTicker) Wait added in v1.5.11

func (t *FixTicker) Wait()

type Layout added in v1.5.11

type Layout interface {
	Layout() string
}

type MicroTime added in v1.5.11

type MicroTime = Time[microTime]

type MicroTimestamp added in v1.5.11

type MicroTimestamp = timestamp[microTime]

type MilliTime added in v1.5.11

type MilliTime = Time[milliTime]

type MilliTimestamp added in v1.5.11

type MilliTimestamp = timestamp[milliTime]

type NanoTime added in v1.5.11

type NanoTime = Time[nanoTime]

type NanoTimestamp added in v1.5.11

type NanoTimestamp = timestamp[nanoTime]

type RandTicker added in v1.5.11

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

func (*RandTicker) Channel added in v1.5.11

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

func (*RandTicker) Reset added in v1.5.11

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

设置最小间隔

func (*RandTicker) Stop added in v1.5.11

func (t *RandTicker) Stop() bool

func (*RandTicker) Wait added in v1.5.11

func (t *RandTicker) Wait()

type SecondTime added in v1.5.11

type SecondTime = Time[secondTime]

type SecondTimestamp added in v1.5.11

type SecondTimestamp = timestamp[secondTime]

type Ticker added in v1.5.11

type Ticker interface {
	Reset(time.Duration) bool
	Stop() bool
	Wait()
	Channel() <-chan time.Time
}

func NewRandTicker added in v1.5.11

func NewRandTicker(minInterval, maxInterval time.Duration) Ticker

minInterval:最小等待时间 maxInterval:最大等待时间 maxInterval-minInterval: 等待范围

func NewTicker added in v1.5.11

func NewTicker(interval time.Duration) Ticker

type Time

type Time[T Encode] time.Time

func NewTime added in v1.5.11

func NewTime[T Encode](t time.Time) Time[T]

func (Time[T]) Format

func (dt Time[T]) Format(format string) string

func (*Time[T]) GobDecode

func (dt *Time[T]) GobDecode(data []byte) error

func (Time[T]) GobEncode

func (dt Time[T]) GobEncode() ([]byte, error)

func (Time[T]) GormDataType

func (dt Time[T]) GormDataType() string

func (Time[T]) MarshalBinary

func (dt Time[T]) MarshalBinary() ([]byte, error)

func (Time[T]) MarshalJSON

func (dt Time[T]) MarshalJSON() ([]byte, error)

func (*Time[T]) Scan

func (dt *Time[T]) Scan(value interface{}) (err error)

func (Time[T]) Time added in v1.5.11

func (dt Time[T]) Time() time.Time

func (*Time[T]) UnmarshalBinary

func (dt *Time[T]) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Time[T]) UnmarshalJSON

func (dt *Time[T]) UnmarshalJSON(data []byte) error

func (Time[T]) Value

func (dt Time[T]) Value() (driver.Value, error)

type TimeCheck added in v1.5.11

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

type TimeStr added in v1.5.11

type TimeStr[T Layout] string

func (TimeStr[T]) MarshalJSON added in v1.5.11

func (dt TimeStr[T]) MarshalJSON() ([]byte, error)

func (TimeStr[T]) Time added in v1.5.11

func (t TimeStr[T]) Time() (time.Time, error)

func (*TimeStr[T]) UnmarshalJSON added in v1.5.11

func (dt *TimeStr[T]) UnmarshalJSON(data []byte) error

type Timestamp added in v1.5.11

type Timestamp = timestamp[milliTime]

毫秒

func NewTimeStamp added in v1.5.11

func NewTimeStamp(t time.Time) Timestamp

type TimestampConstraints added in v1.5.11

type TimestampConstraints interface {
	Timestamp(time.Time) int64
	Time(int64) time.Time
}

type UnionTime

type UnionTime struct {
	time.Time
	Encoding
}

func (UnionTime) MarshalJSON

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

func (*UnionTime) UnmarshalJSON

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

Jump to

Keyboard shortcuts

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