time

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: MIT Imports: 9 Imported by: 10

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

func Check(x TimeCheck) uint

func CheckValid

func CheckValid(x TimeCheck) error

func Format

func Format(t time.Time) string

func FormatRelativeTime

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

func IsValid(x TimeCheck) bool

func MarshalJSON

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

func MarshalText

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

func Parse

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

func SetEncodingLayout

func SetEncodingLayout(l string)

func SetEncodingType

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

func UnixNano(nsec int64) time.Time

func UnmarshalJSON

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

func UnmarshalText

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

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

type DateStr = TimeStr[Edate]

func NewDateStr

func NewDateStr(t time.Time) DateStr

type DateTime

type DateTime int64

func (DateTime) GormDataType

func (ts DateTime) GormDataType() string

func (DateTime) MarshalJSON

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

func (*DateTime) Scan

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

Scan scan time.

func (DateTime) Time

func (d DateTime) Time() time.Time

func (*DateTime) UnmarshalJSON

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

func (DateTime) Value

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

Value get time value.

type DateTimeStr

type DateTimeStr = TimeStr[EdateTime]

time.DateTime

func NewDateTimeStr

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

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

type Edate struct{}

func (Edate) Encoding

func (Edate) Encoding() *Encoding

func (Edate) Layout

func (Edate) Layout() string

type EdateTime

type EdateTime struct{}

func (EdateTime) Encoding

func (EdateTime) Encoding() *Encoding

func (EdateTime) Layout

func (EdateTime) Layout() string

type Encode

type Encode interface {
	Encoding() *Encoding
}

type EncodeType

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

type Encoding

type Encoding struct {
	EncodeType
	Layout string
}

func (*Encoding) SetLayout

func (u *Encoding) SetLayout(l string)

func (*Encoding) SetType

func (u *Encoding) SetType(typ EncodeType)

type Etime

type Etime struct{}

func (Etime) Encoding

func (Etime) Encoding() *Encoding

func (Etime) Layout

func (Etime) Layout() string

type FixTicker

type FixTicker time.Ticker

func (*FixTicker) Channel

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

func (*FixTicker) Reset

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

func (*FixTicker) Stop

func (t *FixTicker) Stop() bool

func (*FixTicker) Wait

func (t *FixTicker) Wait()

type Layout

type Layout interface {
	Layout() string
}

type MicroTime

type MicroTime = Time[microTime]

type MicroTimestamp

type MicroTimestamp = timestamp[microTime]

type MilliTime

type MilliTime = Time[milliTime]

type MilliTimestamp

type MilliTimestamp = timestamp[milliTime]

type NanoTime

type NanoTime = Time[nanoTime]

type NanoTimestamp

type NanoTimestamp = timestamp[nanoTime]

type RandTicker

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

func (*RandTicker) Channel

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

func (*RandTicker) Reset

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

设置最小间隔

func (*RandTicker) Stop

func (t *RandTicker) Stop() bool

func (*RandTicker) Wait

func (t *RandTicker) Wait()

type SecondTime

type SecondTime = Time[secondTime]

type SecondTimestamp

type SecondTimestamp = timestamp[secondTime]

type Ticker

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

func NewRandTicker

func NewRandTicker(minInterval, maxInterval time.Duration) Ticker

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

func NewTicker

func NewTicker(interval time.Duration) Ticker

type Time

type Time[T Encode] time.Time

func NewTime

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

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

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

type TimeStr

type TimeStr[T Layout] string

func (TimeStr[T]) MarshalJSON

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

func (TimeStr[T]) Time

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

func (*TimeStr[T]) UnmarshalJSON

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

type Timestamp

type Timestamp = timestamp[milliTime]

毫秒

func NewTimeStamp

func NewTimeStamp(t time.Time) Timestamp

type TimestampConstraints

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