Documentation ¶
Overview ¶
Package core provides high-level functions for interacting with core entities like projects and records. This API can be used by the CLI and other clients.
Index ¶
- Constants
- Variables
- func FilterBillable(display bool) func(*Record) bool
- func FilterByProject(key string) func(*Record) bool
- func FilterByTimeRange(start, end time.Time) func(*Record) bool
- func FilterNoneNilEndTime(r *Record) bool
- type Filesystem
- type Formatter
- func (f *Formatter) CombineDateAndTime(d, t time.Time) time.Time
- func (f *Formatter) FormatDuration(duration time.Duration) string
- func (f *Formatter) FormatTags(tags []string) string
- func (f *Formatter) ParseDate(input string) (time.Time, error)
- func (f *Formatter) ParseRecordKey(key string) (time.Time, error)
- func (f *Formatter) ParseTime(input string) (time.Time, error)
- func (f *Formatter) PrettyDateString(input time.Time) string
- func (f *Formatter) RecordKey(record *Record) string
- func (f *Formatter) RecordKeyLayout() string
- func (f *Formatter) TimeString(input time.Time) string
- type Project
- type Record
- type Report
- type Reporter
- type Timetrace
- func (t *Timetrace) BackupProject(projectKey string) error
- func (t *Timetrace) BackupRecord(recordKey time.Time) error
- func (t *Timetrace) Config() *config.Config
- func (t *Timetrace) DeleteProject(project Project) error
- func (t *Timetrace) DeleteRecord(record Record) error
- func (t *Timetrace) DeleteRecordsByProject(key string) error
- func (t *Timetrace) EditProject(projectKey string) error
- func (t *Timetrace) EditRecord(recordTime time.Time, plus string, minus string) error
- func (t *Timetrace) EditRecordManual(recordTime time.Time) error
- func (t *Timetrace) EnsureDirectories() error
- func (t *Timetrace) Formatter() *Formatter
- func (t *Timetrace) ListProjectModules(project *Project) (string, error)
- func (t *Timetrace) ListProjects() ([]*Project, error)
- func (t *Timetrace) ListRecords(date time.Time) ([]*Record, error)
- func (t *Timetrace) LoadBackupProject(key string) (*Project, error)
- func (t *Timetrace) LoadBackupRecord(start time.Time) (*Record, error)
- func (t *Timetrace) LoadLatestRecord() (*Record, error)
- func (t *Timetrace) LoadProject(key string) (*Project, error)
- func (t *Timetrace) LoadRecord(start time.Time) (*Record, error)
- func (t *Timetrace) LoadRecordByID(ID int) (*Record, error)
- func (t *Timetrace) RecordCollides(toCheck Record) (bool, error)
- func (t *Timetrace) Report(filter ...func(*Record) bool) (*Reporter, error)
- func (t *Timetrace) RevertProject(projectKey string) error
- func (t *Timetrace) RevertRecord(recordKey time.Time) error
- func (t *Timetrace) RevertRecordsByProject(key string) error
- func (t *Timetrace) SaveProject(project Project, force bool) error
- func (t *Timetrace) SaveRecord(record Record, force bool) error
- func (t *Timetrace) Start(projectKey string, isBillable bool, tags []string) error
- func (t *Timetrace) Status() (*Report, error)
- func (t *Timetrace) Stop() error
- func (t *Timetrace) WriteReport(path string, data []byte) error
Constants ¶
const (
BakFileExt = ".bak"
)
Variables ¶
var ( ErrProjectNotFound = errors.New("project not found") ErrBackupProjectNotFound = errors.New("backup project not found") ErrProjectAlreadyExists = errors.New("project already exists") ErrParentlessModule = errors.New("no parent project for module exists, please create parent first") )
Functions ¶
func FilterBillable ¶ added in v0.11.0
FilterBillable returns a record filter for the billable flag that filters based on the passed display value
func FilterByProject ¶ added in v0.11.0
FilterByProject returns true if the record matches the given project keys if a module is given "mod@project" filter checks if module and project match
func FilterByTimeRange ¶ added in v0.11.0
FilterByTimeRange allows to determine whether a given records is in-between a time-range. If "to" is nil the upper boundary is ignored and vice versa with "from". If both are nil returns true start and end time are both inclusive. Explanition for the `to.AddDate(0,0,1)`: the "to" input will be YYYY-MM-DD 00:00:00, hence the actual tracked records of that date will be ignored as they are all bigger since their hh:mm:ss will be grather then 00:00:00 of the "to" time. Adding one day to the "to" time will include records tracked on that date thus will make the "to" time inclusive
func FilterNoneNilEndTime ¶ added in v0.11.0
Types ¶
type Filesystem ¶
type Filesystem interface { ProjectFilepath(key string) string ProjectBackupFilepath(key string) string ProjectFilepaths() ([]string, error) ProjectBackupFilepaths() ([]string, error) RecordFilepath(start time.Time) string RecordBackupFilepath(start time.Time) string RecordFilepaths(dir string, less func(a, b string) bool) ([]string, error) RecordDirs() ([]string, error) ReportDir() string RecordDirFromDate(date time.Time) string EnsureDirectories() error EnsureRecordDir(date time.Time) error WriteReport(path string, data []byte) error }
Filesystem represents a filesystem used for storing and loading resources.
type Formatter ¶ added in v0.4.0
type Formatter struct {
// contains filtered or unexported fields
}
Formatter represents a date- and time formatter. It provides all displayed date- and time layouts and is capable of parsing those layouts.
func (*Formatter) CombineDateAndTime ¶ added in v0.11.0
CombineDateAndTime takes a date and a time and combines them to the time struct that represents the given time on the given day
func (*Formatter) FormatDuration ¶ added in v0.9.0
formatDuration formats the passed duration into a string. The format is determined by value of UseDecimalHours in config file and will be "8h 24min", "8.4h, or "8h 24min 8.4h". seconds information is ignored.
func (*Formatter) FormatTags ¶ added in v0.14.0
func (*Formatter) ParseDate ¶ added in v0.6.0
ParseDate parses a date from an input string in the form YYYY-MM-DD. It also supports the `today` and `yesterday` aliases for convenience.
func (*Formatter) ParseRecordKey ¶ added in v0.6.0
ParseRecordKey parses an input string in the form 2006-01-02-15-04 or 2006-01-02-03-04PM depending on the use12hours setting.
func (*Formatter) ParseTime ¶ added in v0.11.0
ParseTime parses a time from an input string in the configured timeLayout
func (*Formatter) PrettyDateString ¶ added in v0.11.0
PrettyDateString returns a nice representation of a given time example: Mon 31. May 2021
func (*Formatter) RecordKeyLayout ¶ added in v0.6.0
type Record ¶
type Reporter ¶ added in v0.11.0
type Reporter struct {
// contains filtered or unexported fields
}
Reporter holds map of projects with slice of project records
func (Reporter) Json ¶ added in v0.11.0
Json prepares the r.report and r.totals data so that it can be written to a json file
type Timetrace ¶
type Timetrace struct {
// contains filtered or unexported fields
}
func (*Timetrace) BackupProject ¶ added in v0.8.0
BackupProject creates a backup of the given project file.
func (*Timetrace) BackupRecord ¶ added in v0.8.0
BackupRecord creates a backup of the given record file
func (*Timetrace) DeleteProject ¶
DeleteProject removes the given project and any associated submodules. Returns ErrProjectNotFound if the project doesn't exist.
func (*Timetrace) DeleteRecord ¶
DeleteRecord removes the given record. Returns ErrRecordNotFound if the project doesn't exist.
func (*Timetrace) DeleteRecordsByProject ¶ added in v0.13.0
func (*Timetrace) EditProject ¶
EditProject opens the project file in the preferred or default editor .
func (*Timetrace) EditRecord ¶ added in v0.6.0
EditRecord loads the record internally, applies the option values and saves the record
func (*Timetrace) EditRecordManual ¶ added in v0.6.0
EditRecordManual opens the record file in the preferred or default editor.
func (*Timetrace) EnsureDirectories ¶
func (*Timetrace) ListProjectModules ¶ added in v0.7.0
ListProjectModules loads all modules for a project and returns their keys as a concatenated string
func (*Timetrace) ListProjects ¶
ListProjects loads and returns all stored projects sorted by their filenames. If no projects are found, an empty slice and no error will be returned.
func (*Timetrace) ListRecords ¶ added in v0.2.0
ListRecords loads and returns all records from the given date. If no records are found, an empty slice and no error will be returned.
func (*Timetrace) LoadBackupProject ¶ added in v0.8.0
func (*Timetrace) LoadBackupRecord ¶ added in v0.8.0
func (*Timetrace) LoadLatestRecord ¶ added in v0.6.0
LoadLatestRecord loads the youngest record. This may also be a record from another day. If there is no latest record, nil and no error will be returned.
func (*Timetrace) LoadProject ¶
LoadProject loads the project with the given key. Returns ErrProjectNotFound if the project cannot be found.
func (*Timetrace) LoadRecord ¶
LoadRecord loads the record with the given start time. Returns ErrRecordNotFound if the record cannot be found.
func (*Timetrace) LoadRecordByID ¶ added in v0.14.0
LoadRecordByID loads a record of the current day by the ID provided in list records (starting with the oldest as #1)
func (*Timetrace) RecordCollides ¶ added in v0.11.0
RecordCollides checks if the time of a record collides with other records of the same day and returns a bool
func (*Timetrace) Report ¶ added in v0.11.0
Report generates a report of tracked times
The report can be filtered by the given Filter* funcs. By default all records of all projects will be collected. Interaction with the report can be done via the Reporter instance
func (*Timetrace) RevertProject ¶ added in v0.8.0
RevertProject reverts the given project to its latest backup
func (*Timetrace) RevertRecord ¶ added in v0.8.0
func (*Timetrace) RevertRecordsByProject ¶ added in v0.13.0
RevertRecordsByProject is a function called if user opts to also revert records when they revert a project.
func (*Timetrace) SaveProject ¶
SaveProject persists the given project. Returns ErrProjectAlreadyExists if the project already exists and saving isn't forced.
func (*Timetrace) SaveRecord ¶
SaveRecord persists the given record. Returns ErrRecordAlreadyExists if the record already exists and saving isn't forced.
func (*Timetrace) Start ¶
Start starts tracking time for the given project key. This will create a new record with the current time as start time.
Since parallel work isn't supported, the previous work must be stopped first.
func (*Timetrace) Status ¶
Status calculates and returns a status report.
If the user isn't tracking time at the moment of calling this function, the Report.Current and Report.TrackedTimeCurrent fields will be nil. If the user hasn't tracked time today, ErrTrackingNotStarted will be returned.
func (*Timetrace) WriteReport ¶ added in v0.11.0
WriteReport forwards the byte slice to the fs but checks in prior for the correct output path. If the user has not provided one the config.ReportPath will be used if not set path falls-back to $HOME/.timetrace/reports/report-<time.unix>