ztime

package
v0.0.0-...-ca6a5ed Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimeForever = 0 // 永久
	TimeAbs     = 1 // 绝对时间,单位为s
	TimeDay     = 2 // 自然日
	TimeWeek    = 3 // 自然周
	TimeMonth   = 4 // 自然月
	TimeYear    = 5 // 自然年
	TimeBackAbs = 6 // 绝对时间,单位为s, 从当前时间往后
)
View Source
const (
	TimeTypeHand      = 0
	TimeTypeAbs       = 1
	TimeTypeNatureDay = 2
)
View Source
const (
	TimeFormatYear   = "2006-01-02"
	TimeFormatDate   = "01-02"
	TimeFormatTime24 = "15:04:05"
	TimeFormatTime12 = "03:04:05"
	TimeFormatAll    = "2006-01-02 15:04:05"
)

build format with string type and build a struct for this format func

Variables

This section is empty.

Functions

func CheckNeedUpdate

func CheckNeedUpdate(updateType int64, extra string, tm int64) (bool, error)

func CheckNeedUpdate2

func CheckNeedUpdate2(updateType int64, extra string, start, end int64) (bool, error)

func DayBeginStamp

func DayBeginStamp(now int64) int64

DayBeginStamp ...

func EndOfDay

func EndOfDay(now time.Time) time.Time

当天末

func EndOfMonth

func EndOfMonth(now time.Time) time.Time

本月末

func EndOfWeek

func EndOfWeek(now time.Time) time.Time

本周末

func EndOfYear

func EndOfYear(now time.Time) time.Time

本年初

func GetLocalTimeFromString

func GetLocalTimeFromString(ctx context.Context, format string, timestring string) (localtime time.Time)

func GetTimeFormStamp

func GetTimeFormStamp(strTime int64, format string) string

func GetTimeSE

func GetTimeSE(timeType int64, timeValue int64, now time.Time) (ST *time.Time, ET *time.Time, err error)

时间转换 返回请求对应的起止时间,如果是永久, 则返回 timeType 时间类型 timeValue

func GetTimeSE2

func GetTimeSE2(timeType int64, timeValue int64, now time.Time) (ST int64, ET int64, err error)

func HourBeginStamp

func HourBeginStamp(now int64) int64

HourBeginStamp ...

func MonthScope

func MonthScope(stamp int64) (int64, int64)

MonthScope ...

func StartOfDay

func StartOfDay(now time.Time) time.Time

当天初

func StartOfDayStampFromStr

func StartOfDayStampFromStr(day string) (int64, error)

StartOfDayStampFromStr 获取指定天的时间范围 天格式 2006-01-02 为空时候返回当天的

func StartOfMonth

func StartOfMonth(now time.Time) time.Time

本月初

func StartOfWeek

func StartOfWeek(now time.Time) time.Time

本周初

func StartOfYear

func StartOfYear(now time.Time) time.Time

本月末

func TimeCheckerValid

func TimeCheckerValid(updateType int64, extra string) error

func WeekScope

func WeekScope(stamp int64) (int64, int64)

WeekScope ...

Types

type AbsTimeChecker

type AbsTimeChecker struct {
	Value int64 `json:"value"`
}

==== 绝对时间

func (*AbsTimeChecker) Check

func (a *AbsTimeChecker) Check(start, end int64) bool

func (*AbsTimeChecker) Valid

func (a *AbsTimeChecker) Valid() error

type BackOffCtrl

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

BackOffCtrl ...

func NewBackOffCtrl

func NewBackOffCtrl(step time.Duration, ceil time.Duration) *BackOffCtrl

NewBackOffCtrl ...

func (*BackOffCtrl) BackOff

func (m *BackOffCtrl) BackOff()

BackOff 执行退避,会发生阻塞

func (*BackOffCtrl) Reset

func (m *BackOffCtrl) Reset()

Reset 终止退避过程,reset退避状态

func (*BackOffCtrl) SetCtrl

func (m *BackOffCtrl) SetCtrl(step time.Duration, ceil time.Duration)

SetCtrl ...

type Duration

type Duration time.Duration

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 HandTimeChecker

type HandTimeChecker struct{}

==== 手动更新

func (HandTimeChecker) Check

func (HandTimeChecker) Check(start, end int64) bool

func (HandTimeChecker) Valid

func (HandTimeChecker) Valid() error

type NatureDayTimeChecker

type NatureDayTimeChecker struct {
	Value int `json:"value"`
}

==== 自然日

func (*NatureDayTimeChecker) Check

func (n *NatureDayTimeChecker) Check(start, end int64) bool

func (*NatureDayTimeChecker) Valid

func (n *NatureDayTimeChecker) Valid() error

type RandTicker

type RandTicker struct {
	C <-chan time.Time
	// contains filtered or unexported fields
}

RandTicker is just like time.Ticker, except that it adds randomness to the events.

func NewRandTicker

func NewRandTicker(d, variance time.Duration) *RandTicker

NewRandTicker creates a new RandTicker. d is the duration, and variance specifies the variance. The ticker will tick every d +/- variance.

func (*RandTicker) Stop

func (tkr *RandTicker) Stop()

Stop stops the ticker and closes the underlying channel.

type RunTimeStat

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

RunTimeStat ...

func NewTimeStat

func NewTimeStat() *RunTimeStat

NewTimeStat ...

func (*RunTimeStat) Duration

func (m *RunTimeStat) Duration() time.Duration

Duration ...

func (*RunTimeStat) Microsecond

func (m *RunTimeStat) Microsecond() int64

Microsecond ...

func (*RunTimeStat) Millisecond

func (m *RunTimeStat) Millisecond() int64

Millisecond ...

func (*RunTimeStat) Nanosecond

func (m *RunTimeStat) Nanosecond() int64

Nanosecond ...

func (*RunTimeStat) Reset

func (m *RunTimeStat) Reset()

Reset ...

type TimeChecker

type TimeChecker interface {
	Check(start, end int64) bool
	Valid() error
}

func TimeCheckerFactory

func TimeCheckerFactory(updateType int64, extra string) (TimeChecker, error)

type Timer

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

Timer provides timer functionality that can be controlled by the user. You start the timer by providing it a callback function, which it will call at the specified interval.

var t = timer.NewTimer(1e9)
t.Start(KeepHouse)

func KeepHouse() {
	// do house keeping work
}

You can stop the timer by calling t.Stop, which is guaranteed to wait if KeepHouse is being executed.

You can create an untimely trigger by calling t.Trigger. You can also schedule an untimely trigger by calling t.TriggerAfter.

The timer interval can be changed on the fly by calling t.SetInterval. A zero value interval will cause the timer to wait indefinitely, and it will react only to an explicit Trigger or Stop.

func NewTimer

func NewTimer(interval time.Duration) *Timer

NewTimer creates a new Timer object

func (*Timer) Interval

func (tm *Timer) Interval() time.Duration

Interval returns the current interval.

func (*Timer) SetInterval

func (tm *Timer) SetInterval(ns time.Duration)

SetInterval changes the wait interval. It will cause the timer to restart the wait.

func (*Timer) Start

func (tm *Timer) Start(keephouse func())

Start starts the timer.

func (*Timer) Stop

func (tm *Timer) Stop()

Stop will stop the timer. It guarantees that the timer will not execute any more calls to keephouse once it has returned.

func (*Timer) Trigger

func (tm *Timer) Trigger()

Trigger will cause the timer to immediately execute the keephouse function. It will then cause the timer to restart the wait.

func (*Timer) TriggerAfter

func (tm *Timer) TriggerAfter(duration time.Duration)

TriggerAfter waits for the specified duration and triggers the next event.

Jump to

Keyboard shortcuts

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