timeassist

package
v0.0.0-...-7185cfb Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskIDPre  = "T"
	AlarmIDPre = "A"
)

Variables

This section is empty.

Functions

func DayAdd

func DayAdd(t time.Time, days int) time.Time

func DayEnd

func DayEnd(t time.Time) time.Time

func DayStart

func DayStart(t time.Time) time.Time

func FixAlarmID

func FixAlarmID(id string) string

func FixTaskID

func FixTaskID(id string) string

func GetDaysOfMonth

func GetDaysOfMonth(year int, month int) int

func HourAdd

func HourAdd(t time.Time, hours int) time.Time

func HourEnd

func HourEnd(t time.Time) time.Time

func HourStart

func HourStart(t time.Time) time.Time

func IsWorkDay

func IsWorkDay(t time.Time) bool

func LunarGetDaysOfMonth

func LunarGetDaysOfMonth(year int, month int) int

func LunarMonthAdd

func LunarMonthAdd(t time.Time, months int) time.Time

func LunarMonthEnd

func LunarMonthEnd(t time.Time) time.Time

func LunarMonthEndAdd

func LunarMonthEndAdd(t time.Time, months int) time.Time

func LunarMonthStart

func LunarMonthStart(t time.Time) time.Time

func LunarToDateTime

func LunarToDateTime(year, month, day, hour, minute, second int) time.Time

func LunarToDateTimeAndNextDay

func LunarToDateTimeAndNextDay(year, month, day, hour, minute, second int, days int) time.Time

func LunarToDateTimeAndNextMonth

func LunarToDateTimeAndNextMonth(lunarYear, lunarMonth, lunarDay, hour, minute, second int, months int) (t time.Time, err error)

func LunarToDateTimeAndNextYear

func LunarToDateTimeAndNextYear(lunarYear, lunarMonth, lunarDay, hour, minute, second int, years int) (t time.Time, err error)

func LunarYMD

func LunarYMD(t time.Time) (year, month, day int)

func LunarYearBeginAdd

func LunarYearBeginAdd(t time.Time, years int) time.Time

func LunarYearEnd

func LunarYearEnd(t time.Time) time.Time

func LunarYearEndAdd

func LunarYearEndAdd(t time.Time, years int) time.Time

func LunarYearStart

func LunarYearStart(t time.Time) time.Time

func MinuteAdd

func MinuteAdd(t time.Time, minutes int) time.Time

func MinuteEnd

func MinuteEnd(t time.Time) time.Time

func MinuteStart

func MinuteStart(t time.Time) time.Time

func MonthAdd

func MonthAdd(t time.Time, months int) time.Time

func MonthEnd

func MonthEnd(t time.Time) time.Time

func MonthStart

func MonthStart(t time.Time) time.Time

func ParsePreOnID

func ParsePreOnID(id string) string

func ToDateTime

func ToDateTime(year, month, day, hour, minute, second int, location *time.Location) time.Time

func WeekAdd

func WeekAdd(t time.Time, weeks int) time.Time

func WeekEnd

func WeekEnd(t time.Time) time.Time

func WeekIndexInMonth

func WeekIndexInMonth(t time.Time) int

func WeekStart

func WeekStart(t time.Time) time.Time

func YearAdd

func YearAdd(t time.Time, years int) time.Time

func YearEnd

func YearEnd(t time.Time) time.Time

func YearStart

func YearStart(t time.Time) time.Time

Types

type Alarm

type Alarm struct {
	ID    string   `yaml:"ID" json:"id,omitempty"`
	AType TimeType `yaml:"AType,omitempty" json:"a_type,omitempty"`

	Text string `yaml:"Text" json:"text,omitempty"`

	Value    string `yaml:"Value,omitempty" json:"value,omitempty"` // @see AlarmValue
	TimeZone int    `yaml:"TimeZone,omitempty" json:"timeZone,omitempty"`

	ValidTime *ValidTime `yaml:"ValidRanges,omitempty" json:"valid_time,omitempty"`

	EarlyShowMinute int `yaml:"EarlyShowMinute,omitempty" json:"early_show_minute,omitempty"`

	//
	//
	//
	TimeLastAt int64 `yaml:"TimeLastAt,omitempty" json:"time_last_at,omitempty"` // ?
}

func (*Alarm) GenRecycleData

func (a *Alarm) GenRecycleData() (av *AlarmValue, timeAt time.Time, rd *ShowItem, show, alarm bool, err error)

func (*Alarm) GenRecycleDataEx

func (a *Alarm) GenRecycleDataEx(timeNow, timeLastAt time.Time) (av *AlarmValue, timeAt time.Time, rd *ShowItem, show, alarm bool, err error)

GenRecycleDataEx nolint: gocyclo

func (*Alarm) Validate

func (a *Alarm) Validate() (av *AlarmValue, err error)

type AlarmManager

type AlarmManager interface {
	Add(alarm *Alarm) error
	Remove(id string) error
	Done(id string) error
}

func NewAlarmManager

func NewAlarmManager(storage kv.Storage, timer BizTaskTimer, taskList ShowList, logger l.Wrapper) AlarmManager

type AlarmValue

type AlarmValue struct {
	Lunar  bool
	Year   int
	Month  int
	Day    int
	Week   int
	Hour   int
	Minute int
	Second int
}

func ParseAlarmValue

func ParseAlarmValue(value string, aType TimeType) (av *AlarmValue, err error)

func (*AlarmValue) String

func (av *AlarmValue) String(aType TimeType, timeAt time.Time) string

func (*AlarmValue) StringNoNowTime

func (av *AlarmValue) StringNoNowTime(aType TimeType) (bool, string)

func (*AlarmValue) Valid

func (av *AlarmValue) Valid(aType TimeType) bool

type BizTaskTimer

type BizTaskTimer interface {
	AddTimer(at time.Time, data *ShowItem) error
	SetCallback(idPre string, cb Callback)
}

BizTaskTimer 危险 确保 idPre 不重复 且 ShowItem 的 ID 符合规则

func NewBizTimer

func NewBizTimer(timer TaskTimer) BizTaskTimer

type Callback

type Callback func(dRemoved *ShowItem) (at time.Time, data *ShowItem, err error)

Callback 如果data存在, 则其ID必须为dRemoved的ID

type D

type D struct {
	Data *ShowItem
	At   time.Time
}

type ShowInfo

type ShowInfo struct {
	ID    string `json:"id"`
	Value string `json:"value"`

	/*
		once task:
		recycle task: start - end
		alarm: future/outdate
	*/
	SubTitle string `json:"sub_title"`

	AlarmFlag bool      `json:"alarm_flag,omitempty"`
	AlarmAt   time.Time `json:"alarm_at,omitempty"`

	//
	//
	//
	VOTaskType VOTaskType `json:"vo_task_type"`

	//
	//
	//
	NotifyID string `json:"notify_id,omitempty"`

	//
	LeftTimeS string `json:"left_time_s"`
}

func (*ShowInfo) AutoFill

func (showInfo *ShowInfo) AutoFill()

type ShowInfoListChangeObserver

type ShowInfoListChangeObserver func(task *ShowInfo, visible bool)

type ShowItem

type ShowItem struct {
	ID       string `yaml:"ID"`
	StartUTC int64  `yaml:"StartUTC"`
	EndUTC   int64  `yaml:"EndUTC"`
}

type ShowList

type ShowList interface {
	SetOb(ob ShowInfoListChangeObserver) error
	Add(taskInfo *ShowInfo) error // 如果存在,也不要返回错误
	Get(taskID string) (taskInfo *ShowInfo, err error)
	Remove(taskID string) error // 如果不存在,也不要返回错误
	GetList() ([]*ShowInfo, error)
}

func NewShowList

func NewShowList(fileName string, ob ShowInfoListChangeObserver) ShowList

type Task

type Task struct {
	ID        string   `yaml:"ID" json:"id,omitempty"`
	TType     TimeType `yaml:"TType,omitempty" json:"t_type,omitempty"`
	LunarFlag bool     `yaml:"lunar_flag" json:"lunar_flag"`

	Text string `yaml:"Text" json:"text,omitempty"`

	Value int  `yaml:"Value,omitempty" json:"value,omitempty"`
	Auto  bool `yaml:"Auto,omitempty" json:"auto,omitempty"`

	TimeZone  int        `yaml:"TimeZone,omitempty" json:"time_zone,omitempty"`
	ValidTime *ValidTime `yaml:"ValidRanges,omitempty" json:"valid_time,omitempty"`
}

func (*Task) Desc

func (ct *Task) Desc() string

func (*Task) GenRecycleData

func (ct *Task) GenRecycleData() (rd *ShowItem, nowIsValid bool)

func (*Task) GenRecycleDataEx

func (ct *Task) GenRecycleDataEx(timeNow time.Time) (rd *ShowItem, nowIsValid bool)

func (*Task) Valid

func (ct *Task) Valid() (err error)

type TaskManager

type TaskManager interface {
	Add(task *Task) error
	Remove(taskID string) error
	Done(taskID string) error
	TaskDone(taskID string)
}

func NewTaskManager

func NewTaskManager(storage kv.Storage, timer BizTaskTimer, taskList ShowList, logger l.Wrapper) TaskManager

type TaskTimer

type TaskTimer interface {
	Start()
	AddTimer(at time.Time, data *ShowItem) error
	SetCallback(cb Callback)
	List() (items []D, err error)
}

func NewTaskTimer

func NewTaskTimer(fileName string) TaskTimer

type TimeType

type TimeType int
const (
	TimeTypeBegin TimeType = iota
	TimeTypeOnce
	RecycleTimeTypeYear
	RecycleTimeTypeMonth
	RecycleTimeTypeWeek
	RecycleTimeTypeDay
	RecycleTimeTypeHour
	RecycleTimeTypeMinute
	TimeTypeEnd
)

type VOTaskType

type VOTaskType int
const (
	VOTaskTypeUnknown VOTaskType = iota
	VOTaskTypeTask
	VOTaskTypeAlarm
)

type ValidRange

type ValidRange struct {
	Start int `yaml:"Start" json:"start"`
	End   int `yaml:"End" json:"end"`
}

type ValidRanges

type ValidRanges struct {
	ValidRanges []ValidRange `yaml:"ValidRanges" json:"valid_ranges,omitempty"`
}

func (*ValidRanges) IsValid

func (o *ValidRanges) IsValid(value int) bool

type ValidTime

type ValidTime struct {
	ValidMonthsInYear *ValidRanges `yaml:"ValidMonthsInYear,omitempty" json:"valid_months_in_year,omitempty"`
	ValidWeeksInMonth *ValidRanges `yaml:"ValidWeeksInMonth,omitempty" json:"valid_weeks_in_month,omitempty"`
	ValidDaysInMonth  *ValidRanges `yaml:"ValidDaysInMonth,omitempty" json:"valid_days_in_month,omitempty"`
	ValidDaysInWeek   *ValidRanges `yaml:"ValidDaysInWeek,omitempty" json:"valid_days_in_week,omitempty"`
	ValidHoursInDay   *ValidRanges `yaml:"ValidHoursInDay,omitempty" json:"valid_hours_in_day,omitempty"`
}

func (*ValidTime) FindAfterTime

func (vt *ValidTime) FindAfterTime(t time.Time) (tIsOk bool, nextT time.Time)

func (*ValidTime) Reset

func (vt *ValidTime) Reset()

Jump to

Keyboard shortcuts

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