Documentation
¶
Index ¶
- func DayBegin(at time.Time) time.Time
- func DayDelta(at time.Time, n int) time.Time
- func DayDeltaBegin(at time.Time, n int) time.Time
- func DayDeltaBegins(at time.Time, diffs ...int) []time.Time
- func LocalDiff() time.Duration
- func LocalTime(c *cli.Context, name string) *time.Time
- func MillisToNanos(millis int64) int64
- func NanosToMillis(nanos int64) int64
- func Now() time.Time
- func StopGlobalQuickTime()
- func TodayBegin() time.Time
- func TodayDeltaBegin(n int) time.Time
- func TodayDeltaDayBegins(diffs ...int) []time.Time
- func UnixNano(nano int64) time.Time
- type Duration
- type QuickTime
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DayDeltaBegin ¶
DayDeltaBegin : input a time to figure its delta day begin 指定一个时间和天数差异,获取早于此时间n天或晚于此时间n天的那天的起始时间 其中由n为正或负来决定 例如,比输入时间早一天的起始时间可以由DayDeltaBegin(t, -1)来获取, 比输入时间晚一天的起始时间可以由DayDeltaBegin(t, 1)来获取。
func DayDeltaBegins ¶
DayDeltaBegins : input a time to calculate a delta list day begins 与DayDeltaBegin类似,不同的是通过指定一系列的天数差异来获取不同差值天数的起始时间 例如,DayDeltaBegins(t, -2, -1, 1, 2)可以分别获取比t早2天/早1天/晚1天/晚2天的起始时间
func LocalTime ¶
LocalTime parse time from command line c -- cli context name -- cli field name github.com/urfave/cli/v2 use UTC as time parse zone. actually in most cases, use time.Local zone is good choice. 获取命令行参数中相关的时间,此时间以系统时区为基准,而不是UTC时区 例如当前时区为北京时区,假如命令行输入为"2021-11-01",此函数会将此输入解释成 "2021-11-01"对应的北京时间。 如果不用此函数,直接用*cli.Context的Timestamp来解析,就会解析成"2021-11-01"对应的UTC时间,实际上它比北京时间早8个小时。
func MillisToNanos ¶ added in v1.2.9
MillisToNanos : Helper functions for time conversion
func NanosToMillis ¶ added in v1.2.9
NanosToMillis : Helper functions for time conversion
func StopGlobalQuickTime ¶ added in v1.2.9
func StopGlobalQuickTime()
StopGlobalQuickTime stops the global QuickTime instance
func TodayDeltaBegin ¶
TodayDeltaBegin : one day begin with specific delta with today 指定天数差异,可以获取早于今天n天的一天起始时间或晚于今天n天的一天起始时间 其中由n为正或负来决定 例如,昨天的起始时间可以由TodayDeltaBegin(-1)来获取, 明天的起始时间可以由TodayDeltaBegin(1)来获取。
func TodayDeltaDayBegins ¶
TodayDeltaDayBegins : a series day begin list which have been specified delta day delta list 与TodayDeltaBegin类似,不同的是通过指定一系列的天数差异来获取不同差值天数的起始时间 例如,TodayDeltaDayBegins(-2, -1, 1, 2)可以分别获取前天/昨天/明天/后天各自的起始时间
Types ¶
type Duration ¶ added in v1.2.13
Duration is a wrapper of time.Duration, extend json marshal/unmarshal
func NewDuration ¶ added in v1.2.13
NewDuration creates a new Duration
func (Duration) MarshalJSON ¶ added in v1.2.13
MarshalJSON implements the json.Marshaler interface.
func (*Duration) UnmarshalJSON ¶ added in v1.2.13
UnmarshalJSON implements the json.Unmarshaler interface.
type QuickTime ¶ added in v1.2.9
type QuickTime struct {
// contains filtered or unexported fields
}
QuickTime provides a high-performance current time retrieval mechanism by updating the current time at regular intervals using a background goroutine. This approach minimizes the overhead of frequent system calls to get the current time, making it suitable for high-throughput applications where time retrieval is frequent.
func NewQuickTime ¶ added in v1.2.9
type Timer ¶ added in v1.1.2
func NewTimer ¶ added in v1.1.2
NewTimer creates a new Timer that will send the current time on its channel after at least duration d.
func (Timer) Reset ¶ added in v1.1.2
Reset changes the timer to expire after duration d. This function first call "Stop" to make sure t.C drained
func (Timer) Stop ¶ added in v1.1.2
func (x Timer) Stop()
Stop : stop timer In time.Timer, Stop can not ensure drain the timer channel. Caller should use external code.
if !t.Stop() {
<-t.C
}
Actually, it the t.C be read from others, the outside caller should avoid drain the timer channel again. For instance, time handler be called so that t.C is read then it's empty.
This code will be blocked here forever because t.C is empty now.
if !t.Stop() {
<-t.C
}
The function use "select with default" to avoid this case.