util

package
v0.0.0-...-57c9f0f Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package color provides color utilities and conversions for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllDayEventOccursOnDay

func AllDayEventOccursOnDay(event *ical.Event, targetDate time.Time) (bool, error)

AllDayEventOccursOnDay checks if an all-day event occurs on a specific date. Much simpler implementation using existing utilities instead of manual parsing.

func ApplyBlueTint

func ApplyBlueTint(hexColor string, tintStrength float64) string

ApplyBlueTint shifts a hex color toward blue hue while preserving brightness

func BrightenColor

func BrightenColor(hexColor string, percentage float64) string

BrightenColor increases the brightness of a hex color by the given percentage For very dark colors or edge cases, this blends with white instead of pure brightening

func CellRangesOverlap

func CellRangesOverlap(startCellA, endCellA, startCellB, endCellB int) bool

CellRangesOverlap checks if two cell ranges overlap within a day This is the core collision detection for visual grid rendering

func CellToTime

func CellToTime(cell int, zoomLevel types.ZoomLevel, weekStart time.Time, day int) time.Time

CellToTime converts a cell index to the corresponding time

func CreateEndOfDayDate

func CreateEndOfDayDate(t time.Time) time.Time

CreateEndOfDayDate creates a time.Time at end of day (23:59:59) for the given date

func CreateMidnightDate

func CreateMidnightDate(t time.Time) time.Time

CreateMidnightDate creates a time.Time at midnight (00:00:00) for the given date

func DeepCopyComponent

func DeepCopyComponent(original *ical.Component) *ical.Component

DeepCopyComponent creates a complete standalone copy of an ical.Component

func DeepCopyEvent

func DeepCopyEvent(original *ical.Event) *ical.Event

DeepCopyEvent creates a complete standalone copy of an ical.Event This is used for undo functionality and event manipulation

func EventInstanceOverlapsTimeRange

func EventInstanceOverlapsTimeRange(instance *types.EventInstance, rangeStart, rangeEnd time.Time) bool

EventInstanceOverlapsTimeRange checks if an EventInstance overlaps with a specific time range

func ExpandRecurringEventIntoInstances

func ExpandRecurringEventIntoInstances(component *ical.Component, calendar *ical.Calendar, viewStart, viewEnd time.Time) []*types.EventInstance

ExpandRecurringEventIntoInstances expands a single recurring event into event instances within the time range

func ExtractRRuleStringFromRule

func ExtractRRuleStringFromRule(rule *rrule.RRule) string

ExtractRRuleStringFromRule gets just the RRULE part from a rule's string representation

func FindEventByUIDInCalendar

func FindEventByUIDInCalendar(calendar *ical.Calendar, uid string) (*ical.Component, int)

FindEventByUIDInCalendar finds an event by UID within a specific calendar

func ForEachEventInCalendar

func ForEachEventInCalendar(calendar *ical.Calendar, fn func(*ical.Component) bool)

ForEachEventInCalendar iterates over all VEVENT components in a calendar

func GenerateUUID

func GenerateUUID() (string, error)

GenerateUUID creates an RFC4122-compliant UUID v4 See: https://icalendar.org/New-Properties-for-iCalendar-RFC-7986/5-3-uid-property.html

func GetBackgroundColorHex

func GetBackgroundColorHex() string

func GetCalendarColor

func GetCalendarColor(cal *ical.Calendar) string

GetCalendarColor extracts the color from a calendar

func GetCalendarName

func GetCalendarName(cal *ical.Calendar) string

GetCalendarName extracts the display name from a calendar

func GetCellsPerDay

func GetCellsPerDay(zoom types.ZoomLevel) int

func GetComponentUID

func GetComponentUID(component *ical.Component) string

GetComponentUID gets the UID from an iCal component

func GetDayOfWeek

func GetDayOfWeek(eventTime time.Time, weekStart time.Time) time.Weekday

GetDayOfWeek calculates which day of the week (0-6) an event time falls on relative to week start

func GetDayOfWeekFromLocalTime

func GetDayOfWeekFromLocalTime(eventTime timezone.LocalTime, weekStart time.Time) time.Weekday

GetDayOfWeekFromLocalTime calculates which day of the week a LocalTime falls on relative to week start

func GetEventColor

func GetEventColor(event *ical.Event, calendarColor string) string

GetEventColor determines the color for an event with fallback hierarchy:

func GetEventDescription

func GetEventDescription(event *ical.Event) string

func GetEventDuration

func GetEventDuration(event *ical.Event, defaultLocation *time.Location) time.Duration

GetEventDuration calculates the duration of an event using timezone-safe methods

func GetEventLink(event *ical.Event) string

func GetEventLocation

func GetEventLocation(event *ical.Event) string

func GetEventTitle

func GetEventTitle(event *ical.Event) string

func GetEventUID

func GetEventUID(event *ical.Event) string

func GetWeekStartingOn

func GetWeekStartingOn(t time.Time, startDay time.Weekday) time.Time

GetWeekStartingOn calculates the start of the week containing the given time

func IsAllDayEvent

func IsAllDayEvent(event *ical.Event) bool

func IsRecurring

func IsRecurring(event *ical.Event) bool

func IsValidEndTime

func IsValidEndTime(dtend string) bool

IsValidEndTime validates a DTEND time string (supports both timed and all-day formats)

func IsValidStartTime

func IsValidStartTime(dtstart string) bool

IsValidStartTime validates a DTSTART time string (supports both timed and all-day formats)

func IsValidTimeRange

func IsValidTimeRange(dtstart, dtend string) bool

IsValidTimeRange validates that start time is before end time

func IsValidUID

func IsValidUID(uid string) bool

IsValidUID validates a UID string (non-empty)

func NewEventInstanceFromRegular

func NewEventInstanceFromRegular(event *ical.Event, calendar *ical.Calendar) (*types.EventInstance, error)

NewEventInstanceFromRegular creates an EventInstance from a regular (non-recurring) event

func ParseColor

func ParseColor(input string) string

ParseColor converts color input (hex, name, or letter) to hex value Returns empty string if input is invalid

func ParseExistingExdates

func ParseExistingExdates(exdateStr string, timezone *time.Location) ([]time.Time, error)

ParseExistingExdates parses a comma-separated EXDATE string into time slice

func ParseRRuleFromComponent

func ParseRRuleFromComponent(component *ical.Component) (*rrule.RRule, error)

ParseRRuleFromComponent extracts and parses RRULE from an iCal component

func ParseRRuleString

func ParseRRuleString(rruleStr string) (*rrule.RRule, error)

ParseRRuleString parses an RRULE string with proper unescaping

func RemoveEventFromCalendar

func RemoveEventFromCalendar(calendar *ical.Calendar, index int) bool

RemoveEventFromCalendar removes an event by index from calendar.Children

func RewriteRRuleUntilToFloating

func RewriteRRuleUntilToFloating(rruleValue string) string

RewriteRRuleUntilToFloating converts a UTC UNTIL token inside an RRULE value ("UNTIL=YYYYMMDDTHHMMSSZ") into floating local time ("UNTIL=YYYYMMDDTHHMMSS"), leaving every other token untouched. Values that aren't UTC datetimes (already floating, VALUE=DATE, etc.) pass through unchanged.

func ShowIfError

func ShowIfError(weekModel *types.WeekModel, seconds int, err error, errorMessage string)

ShowIfError displays an error message in the status bar if err is not nil seconds: how long to show the error (in seconds) err: the potential error to check errorMessage: the message to display (err.Error() will be appended) weekModel: the model to update with error information

func SortEventInstancesChronologically

func SortEventInstancesChronologically(allInstances []*types.EventInstance)

SortEventInstancesChronologically sorts event instances in canonical chronological order This ensures every consumer gets consistently sorted events, eliminating picker ordering bugs

func StandardizeHex

func StandardizeHex(hexColor string) string

StandardizeHex ensures a hex color always has exactly one # prefix Handles cases: "FF0000", "#FF0000", "##FF0000" -> "#FF0000"

func TimeIsWithinRange

func TimeIsWithinRange(t, minTime, maxTime time.Time) bool

TimeIsWithinRange checks if a time falls within a given time range (inclusive)

func TimeRangesOverlapExclusive

func TimeRangesOverlapExclusive(start1, end1, start2, end2 time.Time) bool

TimeRangesOverlapExclusive checks if two time ranges overlap with exclusive end times This is useful for events where DTEND is non-inclusive (RFC 5545 standard)

func TimeToCell

func TimeToCell(currentTime time.Time, zoomLevel types.ZoomLevel) int

func ToHex

func ToHex(c color.Color) string

ToHex converts a color.Color to hex string using go-colorful

func TruncateContent

func TruncateContent(content string, maxWidth int) string

TruncateContent truncates content to fit within the specified maximum width

func UnescapeRRuleString

func UnescapeRRuleString(rruleStr string) string

UnescapeRRuleString handles iCal text unescaping

func ValidateRecurringOperation

func ValidateRecurringOperation(event *ical.Event, operation string) (bool, string)

ValidateRecurringOperation checks if an operation is allowed on a recurring event Returns (allowed=true, errorMsg="") for non-recurring events or allowed operations Returns (allowed=false, errorMsg="...") for blocked operations on recurring events

Types

type BatchChange

type BatchChange[T any] struct {
	Changes     []Change[T]
	Description string // Description of the batch operation (e.g., "Paste 3 events")
	Timestamp   time.Time
}

BatchChange represents a group of changes that should be undone/redone together

type Change

type Change[T any] struct {
	Type      ChangeType
	Data      T         // The data that was added/deleted/modified
	Context   T         // Additional context (e.g., which container it belongs to)
	Timestamp time.Time // When the change was made

	// For edit changes, store the before state
	PreviousData T // Only used for edits
}

Change represents a single change that can be undone/redone This is generic and can hold any type of data for any domain

type ChangeTracker

type ChangeTracker[T any] struct {
	// contains filtered or unexported fields
}

ChangeTracker manages undo/redo history for any type of data All operations are treated as batches internally for consistency

func NewChangeTracker

func NewChangeTracker[T any](maxHistory int) *ChangeTracker[T]

NewChangeTracker creates a new generic change tracker

func (*ChangeTracker[T]) CanRedo

func (ct *ChangeTracker[T]) CanRedo() bool

CanRedo returns true if there are changes to redo

func (*ChangeTracker[T]) CanUndo

func (ct *ChangeTracker[T]) CanUndo() bool

CanUndo returns true if there are changes to undo

func (*ChangeTracker[T]) CommitBatch

func (ct *ChangeTracker[T]) CommitBatch(description string)

CommitBatch completes the current batch and commits all changes as a single undo unit

func (*ChangeTracker[T]) RecordChange

func (ct *ChangeTracker[T]) RecordChange(change Change[T])

RecordChange adds a change to the current batch

func (*ChangeTracker[T]) Redo

func (ct *ChangeTracker[T]) Redo() *BatchChange[T]

Redo removes and returns the most recent batch change from redo stack

func (*ChangeTracker[T]) Undo

func (ct *ChangeTracker[T]) Undo() *BatchChange[T]

Undo removes and returns the most recent batch change from undo stack

type ChangeType

type ChangeType int

ChangeType represents the type of change made

const (
	ChangeTypeAdd ChangeType = iota
	ChangeTypeDelete
	ChangeTypeEdit
)

type RecurringEventExpander

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

RecurringEventExpander handles the expansion of recurring events into individual occurrences

func NewRecurringEventExpander

func NewRecurringEventExpander(eventComponent *ical.Component, viewStart, viewEnd time.Time) (*RecurringEventExpander, error)

NewRecurringEventExpander creates a new expander for a recurring event

func (*RecurringEventExpander) GenerateOccurrences

func (r *RecurringEventExpander) GenerateOccurrences() []*types.EventInstance

GenerateOccurrences returns all occurrences within the view timeframe

Jump to

Keyboard shortcuts

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