Documentation ¶
Index ¶
- Constants
- Variables
- func CalcNextSec(sec int) int
- func CalcNextSecWithTime(t time.Time, sec int) int
- func CalcNextTimeWithRefer(now time.Time, refer time.Duration) time.Time
- func Date(year int, month time.Month, day int) time.Time
- func DateWithHMS(year int, month time.Month, day, hour, min, sec int) time.Time
- func GetDayLast(t time.Time) time.Time
- func GetDayZero(t time.Time, day int) time.Time
- func GetDeltaDay(t1, t2 time.Time) int
- func GetDeltaWeek(t1, t2 time.Time) int
- func GetGlobalTimeOffset() time.Duration
- func GetHSMFromString(timeStr, layout string) (hour, min, sec int)
- func GetHourEnd(t time.Time) time.Time
- func GetHourStart(t time.Time) time.Time
- func GetMinuteEnd(t time.Time) time.Time
- func GetMinuteStart(t time.Time) time.Time
- func GetMondayZero(t time.Time) time.Time
- func GetMonthDays(t time.Time) int
- func GetMonthEnd(t time.Time) time.Time
- func GetMonthStart(t time.Time) time.Time
- func GetNextDayInterval(t time.Time) time.Duration
- func GetSecond(d time.Duration) int
- func GetTimeFromString(timeStr, layout string) time.Time
- func GetToday(t time.Time) time.Time
- func GetYearEnd(t time.Time) time.Time
- func GetYearStart(t time.Time) time.Time
- func GetYesterday(t time.Time) time.Time
- func GetYesterdayLast(t time.Time) time.Time
- func IntervalFormat(time1, time2 time.Time) string
- func IntervalFormatSet(intervalType int, str string)
- func IsSameDay(t1, t2 time.Time) bool
- func IsSameHour(t1, t2 time.Time) bool
- func NowByNotOffset() time.Time
- func ResetGlobalTimeOffset()
- func SetGlobalTimeOffset(offset time.Duration)
- func WeekDay(t time.Time) int
- type Period
- func NewPeriod(start, end time.Time) Period
- func NewPeriodWindow(t time.Time, size time.Duration) Period
- func NewPeriodWindowWeek(t time.Time) Period
- func NewPeriodWithDay(t time.Time, day int) Period
- func NewPeriodWithDayZero(t time.Time, day int) Period
- func NewPeriodWithHour(t time.Time, hour int) Period
- func NewPeriodWithMicrosecond(t time.Time, microsecond int) Period
- func NewPeriodWithMillisecond(t time.Time, millisecond int) Period
- func NewPeriodWithMinute(t time.Time, minute int) Period
- func NewPeriodWithNanosecond(t time.Time, nanosecond int) Period
- func NewPeriodWithSecond(t time.Time, second int) Period
- func NewPeriodWithTimeArray(times [2]time.Time) Period
- func (slf Period) Day() int
- func (slf Period) Duration() time.Duration
- func (slf Period) End() time.Time
- func (slf Period) Hour() int
- func (slf Period) IsAfter(t time.Time) bool
- func (slf Period) IsBefore(t time.Time) bool
- func (slf Period) IsBetween(t time.Time) bool
- func (slf Period) IsBetweenOrEqual(t time.Time) bool
- func (slf Period) IsBetweenOrEqualPeriod(t Period) bool
- func (slf Period) IsInvalid() bool
- func (slf Period) IsOngoing(t time.Time) bool
- func (slf Period) IsOverlap(t Period) bool
- func (slf Period) IsZero() bool
- func (slf Period) Microseconds() int
- func (slf Period) Milliseconds() int
- func (slf Period) Minute() int
- func (slf Period) Nanoseconds() int
- func (slf Period) Seconds() int
- func (slf Period) Start() time.Time
- type StateLine
- func (slf *StateLine[State]) AddState(state State, t time.Time, onTrigger ...func()) *StateLine[State]
- func (slf *StateLine[State]) AddTriggerToState(state State, onTrigger ...func()) *StateLine[State]
- func (slf *StateLine[State]) Check(missingAllowed bool, states ...State) bool
- func (slf *StateLine[State]) GetIndexByState(state State) int
- func (slf *StateLine[State]) GetLastState() State
- func (slf *StateLine[State]) GetMissingStates(states ...State) []State
- func (slf *StateLine[State]) GetNextStateTimeByIndex(index int) time.Time
- func (slf *StateLine[State]) GetNextTimeByState(state State) time.Time
- func (slf *StateLine[State]) GetPrevStateTimeByIndex(index int) time.Time
- func (slf *StateLine[State]) GetPrevTimeByState(state State) time.Time
- func (slf *StateLine[State]) GetStateByIndex(index int) State
- func (slf *StateLine[State]) GetStateByTime(t time.Time) State
- func (slf *StateLine[State]) GetStateCount() int
- func (slf *StateLine[State]) GetStateIndexByTime(t time.Time) int
- func (slf *StateLine[State]) GetTimeByIndex(index int) time.Time
- func (slf *StateLine[State]) GetTimeByState(state State) time.Time
- func (slf *StateLine[State]) GetTriggerByIndex(index int) []func()
- func (slf *StateLine[State]) GetTriggerByState(state State) []func()
- func (slf *StateLine[State]) GetTriggerByTime(t time.Time) []func()
- func (slf *StateLine[State]) HasState(state State) bool
- func (slf *StateLine[State]) Move(d time.Duration) *StateLine[State]
- func (slf *StateLine[State]) Range(handler func(index int, state State, t time.Time) bool)
- func (slf *StateLine[State]) RangeReverse(handler func(index int, state State, t time.Time) bool)
- func (slf *StateLine[State]) String() string
Examples ¶
Constants ¶
const ( IntervalYear = iota IntervalDay IntervalHour IntervalMinute IntervalSecond IntervalNow )
const ( Nanosecond = time.Nanosecond Microsecond = time.Microsecond Millisecond = time.Millisecond Second = time.Second Minute = time.Minute Hour = time.Hour Day = time.Hour * 24 Week = Day * 7 )
Variables ¶
var (
Zero time.Time // 零值时间
)
Functions ¶
func CalcNextSecWithTime ¶
CalcNextSecWithTime 计算下一个N秒在多少秒之后
Example ¶
package main import ( "fmt" "github.com/kercylan98/minotaur/utils/times" "time" ) func main() { now := time.Date(2023, 9, 20, 0, 0, 3, 0, time.Local) fmt.Println(times.CalcNextSecWithTime(now, 10)) }
Output: 7
func CalcNextTimeWithRefer ¶ added in v0.0.18
CalcNextTimeWithRefer 根据参考时间计算下一个整点时间
- 假设当 now 为 14:15:16 , 参考时间为 10 分钟, 则返回 14:20:00
- 假设当 now 为 14:15:16 , 参考时间为 20 分钟, 则返回 14:20:00
当 refer 小于 1 分钟时,将会返回当前时间
func DateWithHMS ¶ added in v0.0.2
DateWithHMS 返回一个精确到秒的时间
func GetDayZero ¶ added in v0.0.3
GetDayZero 获取 t 增加 day 天后的零点时间
func GetDeltaWeek ¶ added in v0.0.2
GetDeltaWeek 获取两个时间需要加减的周数
func GetGlobalTimeOffset ¶ added in v0.3.0
GetGlobalTimeOffset 获取全局时间偏移量
func GetHSMFromString ¶ added in v0.0.2
GetHSMFromString 从时间字符串中获取时分秒
func GetHourEnd ¶ added in v0.2.3
GetHourEnd 获取一个时间的 59 分 59 秒
func GetHourStart ¶ added in v0.2.3
GetHourStart 获取一个时间的 0 分 0 秒
func GetMinuteEnd ¶ added in v0.2.3
GetMinuteEnd 获取一个时间的 59 秒
func GetMinuteStart ¶ added in v0.2.3
GetMinuteStart 获取一个时间的 0 秒
func GetMonthStart ¶ added in v0.2.3
GetMonthStart 获取一个时间的月初
func GetNextDayInterval ¶
GetNextDayInterval 获取一个时间到下一天间隔多少秒
func GetTimeFromString ¶ added in v0.0.2
GetTimeFromString 将时间字符串转化为时间
func GetYesterdayLast ¶ added in v0.0.28
GetYesterdayLast 获取昨天最后一刻
func IntervalFormatSet ¶
IntervalFormatSet 针对 IntervalFormat 函数设置格式化内容
func ResetGlobalTimeOffset ¶ added in v0.3.0
func ResetGlobalTimeOffset()
ResetGlobalTimeOffset 重置全局时间偏移量
func SetGlobalTimeOffset ¶ added in v0.3.0
SetGlobalTimeOffset 设置全局时间偏移量
Types ¶
type Period ¶ added in v0.0.3
Period 表示一个时间段
func NewPeriodWindow ¶ added in v0.2.3
NewPeriodWindow 创建一个特定长度的时间窗口
func NewPeriodWindowWeek ¶ added in v0.2.3
NewPeriodWindowWeek 创建一周长度的时间窗口,从周一零点开始至周日 23:59:59 结束
func NewPeriodWithDay ¶ added in v0.0.3
NewPeriodWithDay 创建一个时间段,从 t 开始,持续 day 天
func NewPeriodWithDayZero ¶ added in v0.0.3
NewPeriodWithDayZero 创建一个时间段,从 t 开始,持续到 day 天后的 0 点
func NewPeriodWithHour ¶ added in v0.0.3
NewPeriodWithHour 创建一个时间段,从 t 开始,持续 hour 小时
func NewPeriodWithMicrosecond ¶ added in v0.0.3
NewPeriodWithMicrosecond 创建一个时间段,从 t 开始,持续 microsecond 微秒
func NewPeriodWithMillisecond ¶ added in v0.0.3
NewPeriodWithMillisecond 创建一个时间段,从 t 开始,持续 millisecond 毫秒
func NewPeriodWithMinute ¶ added in v0.0.3
NewPeriodWithMinute 创建一个时间段,从 t 开始,持续 minute 分钟
func NewPeriodWithNanosecond ¶ added in v0.0.3
NewPeriodWithNanosecond 创建一个时间段,从 t 开始,持续 nanosecond 纳秒
func NewPeriodWithSecond ¶ added in v0.0.3
NewPeriodWithSecond 创建一个时间段,从 t 开始,持续 second 秒
func NewPeriodWithTimeArray ¶ added in v0.0.3
NewPeriodWithTimeArray 创建一个时间段
func (Period) IsBetweenOrEqual ¶ added in v0.0.3
IsBetweenOrEqual 判断指定时间是否在时间段之间或者等于时间段的开始或结束时间
func (Period) IsBetweenOrEqualPeriod ¶ added in v0.0.3
IsBetweenOrEqualPeriod 判断指定时间是否在时间段之间或者等于时间段的开始或结束时间
func (Period) IsOngoing ¶ added in v0.0.3
IsOngoing 判断指定时间是否正在进行时
- 如果时间段的开始时间在指定时间之前或者等于指定时间,且时间段的结束时间在指定时间之后,则返回 true
func (Period) Microseconds ¶ added in v0.0.3
Microseconds 返回时间段的持续微秒数
func (Period) Milliseconds ¶ added in v0.0.3
Milliseconds 返回时间段的持续毫秒数
func (Period) Nanoseconds ¶ added in v0.0.3
Nanoseconds 返回时间段的持续纳秒数
type StateLine ¶ added in v0.3.2
StateLine 状态时间线
func NewStateLine ¶ added in v0.3.2
NewStateLine 创建一个从左向右由早到晚的状态时间线
func (*StateLine[State]) AddState ¶ added in v0.3.2
func (slf *StateLine[State]) AddState(state State, t time.Time, onTrigger ...func()) *StateLine[State]
AddState 添加一个状态到时间线中,状态不能与任一时间点重合,否则将被忽略
- onTrigger: 该状态绑定的触发器,该触发器不会被主动执行,需要主动获取触发器执行
func (*StateLine[State]) AddTriggerToState ¶ added in v0.3.2
AddTriggerToState 给指定状态添加触发器
func (*StateLine[State]) Check ¶ added in v0.3.2
Check 根据状态顺序检查时间线是否合法
- missingAllowed: 是否允许状态缺失,如果为 true,则状态可以不连续,如果为 false,则状态必须连续
状态不连续表示时间线中存在状态缺失,例如:
- 状态为 [1, 2, 3, 4, 5] 的时间线,如果 missingAllowed 为 true,则状态为 [1, 3, 5] 也是合法的
- 状态为 [1, 2, 3, 4, 5] 的时间线,如果 missingAllowed 为 false,则状态为 [1, 3, 5] 是不合法的
func (*StateLine[State]) GetIndexByState ¶ added in v0.3.2
GetIndexByState 获取指定状态的索引
func (*StateLine[State]) GetLastState ¶ added in v0.3.2
func (slf *StateLine[State]) GetLastState() State
GetLastState 获取最后一个状态
func (*StateLine[State]) GetMissingStates ¶ added in v0.3.2
func (slf *StateLine[State]) GetMissingStates(states ...State) []State
GetMissingStates 获取缺失的状态
func (*StateLine[State]) GetNextStateTimeByIndex ¶ added in v0.3.2
GetNextStateTimeByIndex 获取指定索引的下一个时间点
func (*StateLine[State]) GetNextTimeByState ¶ added in v0.3.2
GetNextTimeByState 获取指定状态的下一个时间点
func (*StateLine[State]) GetPrevStateTimeByIndex ¶ added in v0.3.2
GetPrevStateTimeByIndex 获取指定索引的上一个时间点
func (*StateLine[State]) GetPrevTimeByState ¶ added in v0.3.2
GetPrevTimeByState 获取指定状态的上一个时间点
func (*StateLine[State]) GetStateByIndex ¶ added in v0.3.2
GetStateByIndex 获取指定索引的状态
func (*StateLine[State]) GetStateByTime ¶ added in v0.3.2
GetStateByTime 获取指定时间点的状态
func (*StateLine[State]) GetStateCount ¶ added in v0.3.2
GetStateCount 获取状态数量
func (*StateLine[State]) GetStateIndexByTime ¶ added in v0.3.2
GetStateIndexByTime 获取指定时间点的索引
func (*StateLine[State]) GetTimeByIndex ¶ added in v0.3.2
GetTimeByIndex 获取指定索引的时间点
func (*StateLine[State]) GetTimeByState ¶ added in v0.3.2
GetTimeByState 获取指定状态的时间点
func (*StateLine[State]) GetTriggerByIndex ¶ added in v0.3.2
GetTriggerByIndex 获取指定索引的触发器
func (*StateLine[State]) GetTriggerByState ¶ added in v0.3.2
func (slf *StateLine[State]) GetTriggerByState(state State) []func()
GetTriggerByState 获取指定状态的触发器
func (*StateLine[State]) GetTriggerByTime ¶ added in v0.3.2
GetTriggerByTime 获取指定时间点的触发器
func (*StateLine[State]) RangeReverse ¶ added in v0.3.2
RangeReverse 按照时间逆序遍历时间线