twindow

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package twindow provides enums and functions to operate with resources related to Time Windows

Index

Constants

View Source
const (
	HoursInDay uint32 = 24
)
View Source
const (
	// IsoDateTimeOnlyLayout is date and time only (without time zone) of iso layout
	IsoDateTimeOnlyLayout string = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func GetMinStartDate

func GetMinStartDate() time.Time

func IsTimeUnit

func IsTimeUnit(timeUnit string) bool

func ParseStartDate

func ParseStartDate(startDateStr string) (time.Time, error)

ParseStartDate parses passed string containing start date

func ValidateCalendarAlignedTimeUnit added in v0.60.0

func ValidateCalendarAlignedTimeUnit(timeUnit string) error

func ValidateRollingWindowTimeUnit added in v0.60.0

func ValidateRollingWindowTimeUnit(timeUnit string) error

func ValidationRuleTimeUnit added in v0.60.0

func ValidationRuleTimeUnit() validation.SingleRule[string]

Types

type CalendarTimeWindow

type CalendarTimeWindow struct {
	TimeZone     *time.Location
	DateWithTime DateWithTime
	// contains filtered or unexported fields
}

func (CalendarTimeWindow) GetStartTime

func (timeWindow CalendarTimeWindow) GetStartTime() time.Time

func (CalendarTimeWindow) GetTimePeriod

func (timeWindow CalendarTimeWindow) GetTimePeriod(timestamp time.Time) TimePeriod

func (CalendarTimeWindow) MarshalJSON

func (timeWindow CalendarTimeWindow) MarshalJSON() ([]byte, error)

func (CalendarTimeWindow) String

func (timeWindow CalendarTimeWindow) String() string

func (CalendarTimeWindow) Type

func (timeWindow CalendarTimeWindow) Type() TimeWindowTypeEnum

type Date

type Date interface {
	Date() (year int, month time.Month, day int)
}

Date represents day in calendar

type DateWithTime

type DateWithTime interface {
	Date
	TimeOfDay
}

DateWithTime represents day in calendar with time of day

type RollingTimeWindow

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

func (RollingTimeWindow) GetTimePeriod

func (r RollingTimeWindow) GetTimePeriod(timestamp time.Time) TimePeriod

func (RollingTimeWindow) MarshalJSON

func (r RollingTimeWindow) MarshalJSON() ([]byte, error)

func (RollingTimeWindow) String

func (r RollingTimeWindow) String() string

func (RollingTimeWindow) Type

type TimeOfDay

type TimeOfDay interface {
	Clock() (hour, min, sec int)
}

TimeOfDay represents valid time of day

type TimePeriod

type TimePeriod struct {
	Start time.Time
	End   time.Time
}

TimePeriod represents a period in time with fixed start and end

func (TimePeriod) Duration

func (tp TimePeriod) Duration() time.Duration

Duration returns duration from Start to End of TimePeriod

type TimeUnitEnum

type TimeUnitEnum int16

TimeUnitEnum represents enum for time unit types

const (
	Second TimeUnitEnum = iota + 1
	Minute
	Hour
	Day
	Week
	Month
	Quarter
	Year
)

Second is value of valid time units

func GetTimeUnitEnum

func GetTimeUnitEnum(typ TimeWindowTypeEnum, timeUnit string) (timeUnitEnum TimeUnitEnum)

func MustParseTimeUnit

func MustParseTimeUnit(timeUnit string) TimeUnitEnum

MustParseTimeUnit parses passed time unit

func (TimeUnitEnum) Duration

func (tu TimeUnitEnum) Duration() time.Duration

Duration returns time.Duration value of fixed duration TimeUnitEnum

func (TimeUnitEnum) String

func (tu TimeUnitEnum) String() string

type TimeWindow

type TimeWindow interface {
	GetTimePeriod(t time.Time) TimePeriod
	String() string
	Type() TimeWindowTypeEnum
	MarshalJSON() ([]byte, error)
}

TimeWindow is an algorithm that assigns a TimePeriod for every point in time

func NewCalendarTimeWindow

func NewCalendarTimeWindow(
	unit TimeUnitEnum,
	count uint32,
	timeZone *time.Location,
	dateWithTime DateWithTime,
) (TimeWindow, error)

NewCalendarTimeWindow creates new calendar time window

func NewRollingTimeWindow

func NewRollingTimeWindow(unit TimeUnitEnum, count uint32) (TimeWindow, error)

NewRollingTimeWindow creates new rolling time window

type TimeWindowTypeEnum

type TimeWindowTypeEnum int16

TimeWindowTypeEnum represents enum for time window types

const (
	Rolling TimeWindowTypeEnum = iota + 1
	Calendar
)

Rolling is value of valid time windows

func (TimeWindowTypeEnum) String

func (s TimeWindowTypeEnum) String() string

Jump to

Keyboard shortcuts

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