store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const IDLE_TITLE string = "<idle>"

Variables

View Source
var ErrDuplicateEntry = errors.New("entry already started")
View Source
var ErrOngoingExists = errors.New("ongoing entry exists")

Functions

func View

func View(entries []FinishedEntry, viewType string) (string, error)

Types

type DetailView

type DetailView map[string][]*FinishedEntry

func NewDetail

func NewDetail(entries []FinishedEntry) DetailView

func (DetailView) String

func (d DetailView) String() string

type DistView

type DistView map[string][]*FinishedEntry

func NewDist

func NewDist(entries []FinishedEntry) DistView

func (DistView) String

func (d DistView) String() string

type EffortsView

type EffortsView map[string]time.Duration

func NewEfforts

func NewEfforts(entries []FinishedEntry) EffortsView

func (EffortsView) String

func (eff EffortsView) String() string

type FinishedEntry

type FinishedEntry struct {
	*UnfinishedEntry
	End time.Time
}

func (*FinishedEntry) Format

func (entry *FinishedEntry) Format() string

type Store

type Store interface {
	// Start an entry.
	//  1. No new entry allowed if there is already an ongoing (unfinished) entry exists.
	//  2. Entry considered as duplicated and is not allowed to start,
	//     if there is already an entry with the same Title and Start.
	Start(*UnfinishedEntry) error

	// StartTitle starts an entry with given title and notes, and 'now' as Start.
	StartTitle(title, note string) error

	// Finish finishes the unfinished entry (if any).
	// If there was one, return it's title.
	// If no unfinished entry to finish, return empty string. This case is not treated as error.
	Finish(notes string) (string, error)

	// RecentTitles returns at most 'limit' number of distinct titles of recent finished entries.
	RecentTitles(limit uint8) ([]string, error)

	// Ongoing returns the ongoing entry (if any), otherwise return nil.
	Ongoing() (*UnfinishedEntry, error)

	// LastFinished returns the finished entry with the latest Start of given title, if any. Otherwise return nil.
	LastFinished(title string) (*FinishedEntry, error)

	// Finished queries entries with condition 'Start >= queryStart and Start <= queryEnd'.
	// Both queryStart and queryEnd must be UTC time
	// If 'titles' is not nil, only returns entries with 'title in titles'.
	Finished(queryStart, queryEnd time.Time, titles []string) ([]FinishedEntry, error)
}

func NewSqliteStore

func NewSqliteStore(db string) (Store, error)

type SummaryView

type SummaryView map[string]map[string]time.Duration

func NewSummary

func NewSummary(entries []FinishedEntry) SummaryView

func (SummaryView) String

func (s SummaryView) String() string

type UnfinishedEntry

type UnfinishedEntry struct {
	Title string
	Start time.Time
	Notes string
}

Jump to

Keyboard shortcuts

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