util

package
v0.0.0-...-9dc31f9 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorDurationHours    = "#FF0087"
	ColorDurationMinutes  = "#00D7FF"
	ColorDurationSeconds  = "#FFFF5F"
	ColorPeriodForeground = "#BAEBDA"
	ColorPeriodHighlight  = "#DE3E93"
)

Variables

View Source
var CurrentPeriodStyle = lipgloss.NewStyle().
	Foreground(lipgloss.Color(ColorPeriodForeground)).
	Background(lipgloss.Color(ColorPeriodHighlight)).
	Padding(0, 1)
View Source
var DurationHourStyle = lipgloss.NewStyle().
	Foreground(lipgloss.Color(ColorDurationHours)).
	Render
View Source
var DurationMinuteStyle = lipgloss.NewStyle().
	Foreground(lipgloss.Color(ColorDurationMinutes)).
	Render
View Source
var DurationSecondStyle = lipgloss.NewStyle().
	Foreground(lipgloss.Color(ColorDurationSeconds)).
	Render
View Source
var PeriodPickerStyle = lipgloss.NewStyle().
	PaddingRight(1).
	Align(lipgloss.Right)
View Source
var PeriodStyle = lipgloss.NewStyle().
	Foreground(lipgloss.Color(ColorPeriodForeground)).
	Padding(0, 1)
View Source
var TypicalBoxSpecs = map[string]BoxSpec{
	"Work": {
		Name:        "Work",
		Min:         time.Hour * 35,
		Max:         time.Hour * 50,
		SpanMin:     time.Hour * 6,
		SpanMax:     time.Hour * 9,
		HourMin:     8,
		HourMax:     18,
		AllowedDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday},
	},
	"Exercise": {
		Name:        "Exercise",
		Min:         time.Hour * 2,
		Max:         time.Hour * 8,
		SpanMin:     time.Minute * 30,
		SpanMax:     time.Hour * 2,
		HourMin:     5,
		HourMax:     8,
		AllowedDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday, time.Sunday},
	},
	"Piano": {
		Name:        "Piano",
		Min:         time.Hour * 1,
		Max:         time.Hour * 10,
		SpanMin:     time.Minute * 30,
		SpanMax:     time.Minute * 60,
		HourMin:     17,
		HourMax:     22,
		AllowedDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday, time.Sunday},
	},
	"Reading": {
		Name:        "Reading",
		Min:         time.Hour * 1,
		Max:         time.Hour * 10,
		SpanMin:     time.Minute * 15,
		SpanMax:     time.Minute * 90,
		HourMin:     17,
		HourMax:     22,
		AllowedDays: []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday, time.Sunday},
	},
	"Hiking": {
		Name:        "Hiking",
		Min:         time.Hour * 1,
		Max:         time.Hour * 5,
		SpanMin:     time.Hour * 1,
		SpanMax:     time.Hour * 5,
		HourMin:     5,
		HourMax:     12,
		AllowedDays: []time.Weekday{time.Saturday, time.Sunday},
	},
}

Functions

func AfterOrEqual

func AfterOrEqual(t1, t2 time.Time) bool

func AllBoxesFromDB

func AllBoxesFromDB(tbdb db.TBDB) ([]string, map[string]Box)

func AllSpansFromDB

func AllSpansFromDB(tbdb db.TBDB) (map[string]SpanSet, map[int64]Span)

func BeforeOrEqual

func BeforeOrEqual(t1, t2 time.Time) bool

func DurationParser

func DurationParser(d time.Duration) string

func Earlier

func Earlier(t1, t2 time.Time) time.Time

func FiscalQuarter

func FiscalQuarter(fiscalYearStart, calendarMonth time.Month) int

func Later

func Later(t1, t2 time.Time) time.Time

func MonthStart

func MonthStart(t time.Time) time.Time

MonthStart calculates the time at the beginning of the month for a given time

func ParseDurationOrTime

func ParseDurationOrTime(s string) (time.Time, error)

func ParseTime

func ParseTime(s string) (time.Time, error)

func QuarterStart

func QuarterStart(t time.Time, fys time.Month) time.Time

func ThisMonthStart

func ThisMonthStart() time.Time

ThisMonthStart calculates the time at the beginning of the current month

func ThisQuarterStart

func ThisQuarterStart(fys time.Month) time.Time

func ThisWeekStart

func ThisWeekStart() time.Time

ThisWeekStart calculates the time at the beginning of the current week

func ThisYearStart

func ThisYearStart() time.Time

ThisYearStart calculates the time at the beginning of the current year

func WeekStart

func WeekStart(t time.Time) time.Time

WeekStart calculates the time at the beginning of the week for a given time

func YearStart

func YearStart(t time.Time) time.Time

YearStart calculates the time at the beginning of the month for a given time

Types

type Box

type Box struct {
	Name    string
	MinTime time.Duration
	MaxTime time.Duration
}

func (Box) ScaledTimes

func (b Box) ScaledTimes(p Period) (time.Duration, time.Duration)

type BoxSpec

type BoxSpec struct {
	Name        string
	Min         time.Duration
	Max         time.Duration
	SpanMin     time.Duration
	SpanMax     time.Duration
	HourMin     int
	HourMax     int
	AllowedDays []time.Weekday
}

func (BoxSpec) IsDayAllowed

func (b BoxSpec) IsDayAllowed(day time.Weekday) bool

func (BoxSpec) RandomSpan

func (b BoxSpec) RandomSpan(day time.Time) Span

type InputResult

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

func NewInputResultBox

func NewInputResultBox(box Box) InputResult

func NewInputResultSpan

func NewInputResultSpan(span Span) InputResult

func (InputResult) Box

func (r InputResult) Box() Box

func (InputResult) IsBox

func (r InputResult) IsBox() bool

func (InputResult) Span

func (r InputResult) Span() Span

type Period

type Period int
const (
	Week Period = iota
	Month
	Quarter
	Year
)

type PromptState

type PromptState int
const (
	InUse PromptState = iota
	WasCancelled
	HasResult
)

type Span

type Span struct {
	ID    int64
	Start time.Time
	End   time.Time
	Box   string
}

func GenerateSpansFromBoxSpecs

func GenerateSpansFromBoxSpecs(startDay, endDay time.Time) []Span

func MonthSoFar

func MonthSoFar() Span

func PeriodSoFar

func PeriodSoFar(p Period, fys time.Month) Span

func QuarterSoFar

func QuarterSoFar(fys time.Month) Span

func WeekSoFar

func WeekSoFar() Span

func YearSoFar

func YearSoFar() Span

func (Span) Duration

func (s Span) Duration() time.Duration

func (Span) GetOverlap

func (s Span) GetOverlap(span Span) Span

func (Span) IsEqual

func (s Span) IsEqual(span Span) bool

func (Span) IsZero

func (s Span) IsZero() bool

func (Span) Overlaps

func (s Span) Overlaps(span Span) bool

func (Span) String

func (s Span) String() string

type SpanSet

type SpanSet struct {
	Spans []Span // list for table loads
	// contains filtered or unexported fields
}

func AllSpansFromDBForTimeRange

func AllSpansFromDBForTimeRange(tbdb db.TBDB, start, end time.Time) SpanSet

func NewSpanSet

func NewSpanSet() SpanSet

func (*SpanSet) Add

func (s *SpanSet) Add(span Span)

func (*SpanSet) Duration

func (s *SpanSet) Duration() time.Duration

func (*SpanSet) HasID

func (s *SpanSet) HasID(id int64) bool

func (*SpanSet) HasSpan

func (s *SpanSet) HasSpan(span Span) bool

func (*SpanSet) IsEmpty

func (s *SpanSet) IsEmpty() bool

func (*SpanSet) Remove

func (s *SpanSet) Remove(span Span)

func (*SpanSet) Size

func (s *SpanSet) Size() int

type TimeBox

type TimeBox struct {
	Fname     string
	Names     []string
	Boxes     map[string]Box
	SpansSets map[string]SpanSet
	Spans     map[int64]Span
	// contains filtered or unexported fields
}

func TimeBoxFromDB

func TimeBoxFromDB(dbname string) TimeBox

func (TimeBox) AddBox

func (tb TimeBox) AddBox(box Box) error

func (TimeBox) AddSpan

func (tb TimeBox) AddSpan(span Span, box string) error

func (TimeBox) DeleteBox

func (tb TimeBox) DeleteBox(box string) error

func (TimeBox) DeleteBoxAndSpans

func (tb TimeBox) DeleteBoxAndSpans(box string) error

func (TimeBox) DeleteSpan

func (tb TimeBox) DeleteSpan(span Span) error

func (TimeBox) DeleteSpanByID

func (tb TimeBox) DeleteSpanByID(id int64) error

func (TimeBox) GetSpans

func (tb TimeBox) GetSpans(span Span) map[string]SpanSet

func (TimeBox) GetSpansForBox

func (tb TimeBox) GetSpansForBox(box string, span Span) SpanSet

func (TimeBox) GetSpansForTimespan

func (tb TimeBox) GetSpansForTimespan(span Span) SpanSet

func (TimeBox) SyncFromDB

func (tb TimeBox) SyncFromDB()

func (TimeBox) UpdateBox

func (tb TimeBox) UpdateBox(box Box) error

func (TimeBox) UpdateSpan

func (tb TimeBox) UpdateSpan(span Span) error

type TimePeriod

type TimePeriod struct {
	Period
}

func (*TimePeriod) Current

func (t *TimePeriod) Current() int

func (*TimePeriod) Names

func (t *TimePeriod) Names() []string

func (*TimePeriod) Next

func (t *TimePeriod) Next()

func (*TimePeriod) Previous

func (t *TimePeriod) Previous()

func (*TimePeriod) String

func (t *TimePeriod) String() string

func (*TimePeriod) View

func (t *TimePeriod) View() string

Jump to

Keyboard shortcuts

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