model

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

TODO: find a home for this

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DateAndTimestampToGotime added in v0.10.0

func DateAndTimestampToGotime(date Date, ts Timestamp, timezone *time.Location) time.Time

DateAndTimestampToGotime returns a time.Time object from a given date and a given timestamp.

func GoalForRange

func GoalForRange(goal Goal, start, end time.Time) time.Duration

GoalForRange is a helper to sum up the duration for the given range expected by the given Goal.

Types

type ByName

type ByName []*Category

func (ByName) Len

func (a ByName) Len() int

func (ByName) Less

func (a ByName) Less(i, j int) bool

func (ByName) Swap

func (a ByName) Swap(i, j int)

type ByStartConsideringDuration

type ByStartConsideringDuration []*Event

...

func (ByStartConsideringDuration) Len

func (ByStartConsideringDuration) Less

func (a ByStartConsideringDuration) Less(i, j int) bool

func (ByStartConsideringDuration) Swap

func (a ByStartConsideringDuration) Swap(i, j int)

type Category

type Category struct {
	Name       CategoryName   `dpedit:"name"`
	Priority   int            `dpedit:"priority"`
	Goal       Goal           `dpedit:",ignore"`
	Deprecated bool           `dpedit:",ignore"`
	Color      colorful.Color `dpedit:",ignore"`
}

type CategoryName added in v0.10.0

type CategoryName string

type Date

type Date struct {
	Year  int
	Month int
	Day   int
}

Date represents a date, i.e. a year, month and day.

func DateFromGotime added in v0.10.0

func DateFromGotime(t time.Time, loc *time.Location) Date

func DateFromString added in v0.10.0

func DateFromString(s string) (Date, error)

DateFromString creates a date from a string in the format "YYYY-MM-DD".

func (Date) Backward

func (d Date) Backward(by int) Date

Backward returns a date that is `by`-many days before the receiver.

func (Date) DaysUntil

func (d Date) DaysUntil(other Date) int

DaysUntil returns the number of days from a date A until a date B is reached. (e.g. from 2021-12-14 until 2021-12-19 -> 5 days) expects `other` not to be before `d`

func (Date) Forward

func (d Date) Forward(by int) Date

Forward returns a date that is `by`-many days after the receiver.

func (Date) GetDayInMonth

func (d Date) GetDayInMonth(index int) Date

GetDayInMonth returns the indexed day in the month of the receiver.

Note that indexing 0 will return the first of the month.

func (Date) GetDayInWeek

func (d Date) GetDayInWeek(index int) Date

GetDayInWeek returns the date that is on the weekday for the given index in the week the receiver is in.

Index here means that 0 is Monday, 6 is Sunday.

func (Date) GetLastOfMonth

func (d Date) GetLastOfMonth() Date

GetLastOfMonth returns the last date of the month of the receiver.

func (Date) Is

func (d Date) Is(t time.Time, timezone *time.Location) bool

Is returns whether the receiver is the same date as the given time.

func (Date) IsAfter

func (d Date) IsAfter(other Date) bool

IsAfter returns whether a date A is after a date B.

func (Date) IsBefore

func (d Date) IsBefore(other Date) bool

IsBefore returns whether a date A is before a date B.

func (Date) MonthBounds

func (d Date) MonthBounds() (first Date, last Date)

MonthBounds returns the first and last date of the month the receiver is in.

func (Date) Next

func (d Date) Next() Date

Next returns the next date.

func (Date) Prev

func (d Date) Prev() Date

Prev returns the previous date.

func (Date) String added in v0.10.0

func (d Date) String() string

String returns the date as a string in the format "YYYY-MM-DD".

func (Date) ToGotime

func (d Date) ToGotime(timezone *time.Location) time.Time

ToGotime returns the date as a time.Time with the time set to midnight (at the start of the day).

func (Date) ToWeekday

func (d Date) ToWeekday(timezone *time.Location) time.Weekday

ToWeekday returns the weekday of the receiver.

func (Date) Valid

func (d Date) Valid() bool

Valid returns whether the date is valid. A date such as the 31st of February is invalid, for example.

func (Date) WeekBounds added in v0.10.0

func (d Date) WeekBounds() (monday Date, sunday Date)

WeekBounds returns the monday and sunday of the week the receiver is in.

type DateAndTime added in v0.10.0

type DateAndTime struct {
	Date      Date
	Timestamp Timestamp
}

DateAndTime represents a date and a time, a datetime.

func FromTime

func FromTime(t time.Time, timezone *time.Location) *DateAndTime

FromTime creates a DateAndTime from a time.Time.

type DateSlice added in v0.10.0

type DateSlice []Date

func (DateSlice) Len added in v0.10.0

func (a DateSlice) Len() int

func (DateSlice) Less added in v0.10.0

func (a DateSlice) Less(i, j int) bool

func (DateSlice) Swap added in v0.10.0

func (a DateSlice) Swap(i, j int)

type Event

type Event struct {
	ID       EventID      `dpedit:",ignore"`
	Name     string       `dpedit:"name"`
	Category CategoryName `dpedit:"category"`
	Start    time.Time    `dpedit:",ignore"`
	End      time.Time    `dpedit:",ignore"`
}

...

func (Event) Clone

func (e Event) Clone() Event

func (*Event) Duration

func (e *Event) Duration() time.Duration

...

func (*Event) IsContainedIn

func (b *Event) IsContainedIn(a *Event) bool

Whether one event A contains another B, i.E. - B's start is _not before_ A's start and - B's end is _not after_ A's end

func (*Event) StartsDuring

func (b *Event) StartsDuring(a *Event) bool

Whether one event B starts during another A.

func (*Event) String added in v0.10.0

func (e *Event) String() string

type EventID added in v0.10.0

type EventID = string

type EventList added in v0.10.0

type EventList struct {
	Events []*Event
}

EventList is a list of events I suppose.

func (*EventList) AddEvent added in v0.10.0

func (l *EventList) AddEvent(e *Event) error

...

func (*EventList) Clone added in v0.10.0

func (l *EventList) Clone() EventList

func (*EventList) Flatten added in v0.10.0

func (l *EventList) Flatten(getCategoryPriority func(CategoryName) int)

Flatten "flattens" the events of a given day, i.E. ensures that no overlapping events exist. It does this by e.g. trimming one of two overlapping events or splitting a less prioritized event if it had a higher-priority event occur during it as shown here:

+-------+         +-------+
| a     |         | a     |    (`a` lower prio than `B`)
|   +-----+       +-------+
|   | B   |  ~~>  | B     |
|   +-----+       +-------+
|       |         | a     |
+-------+         +-------+

+-------+         +-------+
| a     |         | a     |    (`a` lower prio than `B`)
|   +-----+       +-------+
|   | B   |  ~~>  | B     |
+---|     |       |       |
    +-----+       +-------+

It modifies the input in-place.

func (*EventList) GetEventByID added in v0.10.0

func (l *EventList) GetEventByID(id EventID) *Event

func (*EventList) GetNextEventAfter added in v0.10.0

func (l *EventList) GetNextEventAfter(t time.Time) *Event

...

func (*EventList) GetPrevEventBefore added in v0.10.0

func (l *EventList) GetPrevEventBefore(t time.Time) *Event

...

func (*EventList) GetTimesheetEntry added in v0.10.0

func (l *EventList) GetTimesheetEntry(matcher func(CategoryName) bool, getCategoryPriority func(CategoryName) int, date Date, timezone *time.Location) (*TimesheetEntry, error)

GetTimesheetEntry returns the TimesheetEntry for this day for a given category (e.g. "work").

func (*EventList) MoveSingleEventBy added in v0.10.0

func (l *EventList) MoveSingleEventBy(event *Event, duration time.Duration, snapMod time.Duration)

...

func (*EventList) MoveSingleEventTo added in v0.10.0

func (l *EventList) MoveSingleEventTo(event *Event, newStart time.Time)

func (*EventList) RemoveEvent added in v0.10.0

func (l *EventList) RemoveEvent(event *Event) error

...

func (*EventList) ResizeBy added in v0.10.0

func (l *EventList) ResizeBy(event *Event, delta time.Duration) error

...

func (*EventList) ResizeTo added in v0.10.0

func (l *EventList) ResizeTo(event *Event, newEnd time.Time) error

...

func (*EventList) SplitEvent added in v0.10.0

func (l *EventList) SplitEvent(originalEvent *Event, timestamp time.Time) error

...

func (*EventList) SumUpByCategory added in v0.10.0

func (l *EventList) SumUpByCategory(getCategoryPriority func(CategoryName) int) map[CategoryName]time.Duration

Sum up the event durations of a given day per category. Time cannot be counted multiple times, so if multiple events overlap, only one of them can have the time of the overlap counted. The prioritization for this is according to category priority.

func (*EventList) UpdateEventOrder added in v0.10.0

func (l *EventList) UpdateEventOrder()

...

type Goal

type Goal interface {
	Requires(Date) time.Duration
}

Goal defines a time goal. It can be queried, for any given date, what duration the goal requires.

type RangedGoal

type RangedGoal struct {
	Entries []rangedGoalEntry
}

RangedGoal is a Goal that is defined by any number of ranges and the expected duration for each.

func NewRangedGoalFromConfig

func NewRangedGoalFromConfig(cfg []config.RangedGoal) (*RangedGoal, error)

NewRangedGoalFromConfig constructs a new RangedGoal from config data.

func (*RangedGoal) Requires

func (g *RangedGoal) Requires(date Date) time.Duration

Requires returns the duration required for the given date.

It is (Time/ DAYSINRANGE(Start, End)) for any day in range, 0 otherwise.

type ReadableTask added in v0.10.0

type ReadableTask interface {
	GetID() TaskID
	GetName() string
	GetCategory() CategoryName
	GetDuration() *time.Duration
	GetDeadline() *time.Time
	GetSubtasks() []ReadableTask

	ToEvent(startTime time.Time, namePrefix string) []*Event
}

type SunTimes

type SunTimes struct {
	Rise, Set Timestamp
}

SunTimes represents the sunrise and sunset times of a date.

type SuntimesProvider added in v0.10.0

type SuntimesProvider struct {
	Latitude  float64
	Longitude float64
}

func (*SuntimesProvider) Get added in v0.10.0

func (p *SuntimesProvider) Get(d Date) SunTimes

GetSunTimes returns the sunrise and sunset times for the receiver-date at the given location. Warning: slow (TODO)

type Task added in v0.8.0

type Task struct {
	ID       TaskID         `dpedit:",ignore"`
	Name     string         `dpedit:"name"`
	Category CategoryName   `dpedit:"category"`
	Duration *time.Duration `dpedit:"duration"`
	Deadline *time.Time     `dpedit:"deadline"`
	Subtasks []*Task        `dpedit:",ignore"`
}

A Task remains to be done (or dropped) but is not yet scheduled. It has a name and belongs to a category (by name); it can further have a duration (estimate), a deadline (due date) and subtasks.

func (*Task) Equal added in v0.10.0

func (t *Task) Equal(t2 ReadableTask) bool

func (*Task) GetCategory added in v0.10.0

func (t *Task) GetCategory() CategoryName

func (*Task) GetDeadline added in v0.10.0

func (t *Task) GetDeadline() *time.Time

func (*Task) GetDuration added in v0.10.0

func (t *Task) GetDuration() *time.Duration

func (*Task) GetID added in v0.10.0

func (t *Task) GetID() TaskID

func (*Task) GetName added in v0.10.0

func (t *Task) GetName() string

func (*Task) GetSubtasks added in v0.10.0

func (t *Task) GetSubtasks() []ReadableTask

func (*Task) ToEvent added in v0.8.0

func (t *Task) ToEvent(startTime time.Time, namePrefix string) []*Event

ToEvent convernts a task (including potential subtasks) to the corresponding set of events (subtasks becoming events during the main event, recursively).

type TaskID added in v0.10.0

type TaskID string

type TasksByDeadline added in v0.9.2

type TasksByDeadline []*Task

TasksByDeadline is a sort interface to stort tasks by their deadlines

func (TasksByDeadline) Len added in v0.9.2

func (a TasksByDeadline) Len() int

func (TasksByDeadline) Less added in v0.9.2

func (a TasksByDeadline) Less(i, j int) bool

func (TasksByDeadline) Swap added in v0.9.2

func (a TasksByDeadline) Swap(i, j int)

type TimeOffset

type TimeOffset struct {
	T   Timestamp
	Add bool
}

type TimesheetEntry added in v0.9.0

type TimesheetEntry struct {
	Start         Timestamp
	BreakDuration time.Duration
	End           Timestamp
}

A TimesheetEntry represents an entry in a common timesheet.

It defines a beginning (i.e. the time you clocked in), an end (i.e. the time you clocked out), and the total length of breaks taken between them.

func (*TimesheetEntry) IsEmpty added in v0.9.0

func (e *TimesheetEntry) IsEmpty() bool

IsEmpty is a helper to identify empty timesheet entries.

type Timestamp

type Timestamp struct {
	Hour, Minute int
}

func NewTimestamp

func NewTimestamp(s string) *Timestamp

func NewTimestampFromGotime

func NewTimestampFromGotime(t time.Time, timezone *time.Location) *Timestamp

func (Timestamp) DurationInMinutesUntil

func (t1 Timestamp) DurationInMinutesUntil(t2 Timestamp) int

Returns the duration in minutes between to a given timestamp t2. Does not check that t2 is in fact later!

func (Timestamp) DurationUntil added in v0.7.8

func (t1 Timestamp) DurationUntil(t2 Timestamp) time.Duration

Returns the duration (time.Duration) to a given timestamp t2. Does not check that t2 is in fact later!

func (Timestamp) IsAfter

func (a Timestamp) IsAfter(b Timestamp) bool

func (Timestamp) IsBefore

func (a Timestamp) IsBefore(b Timestamp) bool

func (Timestamp) Legal

func (t Timestamp) Legal() bool

func (Timestamp) Offset

func (t Timestamp) Offset(o TimeOffset) Timestamp

Returns a timestamp offset by a given offset, which can be additive or subtractive. "Loops around", meaning offsetting 0:10 by -1 hour results in 23:10, offsetting 23:10 by +1 hour results in 0:10.

func (Timestamp) OffsetMinutes

func (t Timestamp) OffsetMinutes(minutes int) Timestamp

func (Timestamp) Snap

func (t Timestamp) Snap(minutesModulus int) Timestamp

TODO: migrate to time.Duration-based

func (Timestamp) ToString

func (a Timestamp) ToString() string

TODO: make stringer

func (Timestamp) Truncate added in v0.10.0

func (t Timestamp) Truncate(durationMinutes uint) Timestamp

type WorkweekGoal

type WorkweekGoal struct {
	Monday    time.Duration
	Tuesday   time.Duration
	Wednesday time.Duration
	Thursday  time.Duration
	Friday    time.Duration
	Saturday  time.Duration
	Sunday    time.Duration
}

WorkweekGoal is a goal that defines the duration per day of the week.

func NewWorkweekGoalFromConfig

func NewWorkweekGoalFromConfig(cfg config.WorkweekGoal) (*WorkweekGoal, error)

NewWorkweekGoalFromConfig constructs a new WorkweekGoal from config data.

func (*WorkweekGoal) Requires

func (g *WorkweekGoal) Requires(date Date) time.Duration

Requires returns the duration required for the given date.

It is just the duration defined for the date's weekday.

Jump to

Keyboard shortcuts

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