Documentation
¶
Index ¶
- Constants
- Variables
- func FormatDuration(d time.Duration) string
- func FormatDurationCustom(d time.Duration, precision time.Duration) string
- func IsWorkDay(d time.Time) bool
- func LoadConfig() error
- func ParseDate(in string) (time.Time, error)
- func ParseDayString(dayStr string) (time.Time, error)
- func ParseTime(in string) (time.Time, error)
- func PlannedTime(date time.Time) (time.Duration, error)
- type Config
- type DB
- type DatabaseFilter
- type Day
- type Filter
- type GroupByOption
- type Month
- type Order
- type OrderBy
- type Timer
- type Timers
- type VacationDay
- type VacationFilter
- type Year
Constants ¶
const ( FieldStart = "start" FieldProject = "project" FieldTask = "task" FieldDay = "day" OrderAsc Order = "ASC" OrderDsc Order = "DESC" )
const (
DateFormat = "2006-01-02"
)
const ( // HomeDirEnv stores the name of the environment variable that contains the // path to the home directory of this cli. HomeDirEnv = "TT_HOME_DIR" )
const TimeFormat = "2006-01-02 15:04"
Variables ¶
var ( ErrInvalidData = fmt.Errorf("invalid data") // ErrInternal indicates an error with the database ErrInternal = fmt.Errorf("internal error") ErrNotFound = fmt.Errorf("not found") ErrInvalidFormat = fmt.Errorf("invalid format") ErrNotImplemented = fmt.Errorf("not implemented") ErrInvalidTimer = fmt.Errorf("invalid timer") ErrInvalidParameter = fmt.Errorf("invalid parameter supplied") ErrInvalidParameters = fmt.Errorf("invalid parameters supplied") ErrOperationNotPermitted = fmt.Errorf("operation not permitted") )
var EmptyDbFilter emptyDbFilter
var EmptyFilter *filter
Functions ¶
func FormatDuration ¶
FormatDuration formats a duration in the given precision specified by the config.
func FormatDurationCustom ¶
func IsWorkDay ¶
IsWorkDay checks if the day should have been worked on. It does not take into account vacation days, but only the configured weekdays.
func LoadConfig ¶
func LoadConfig() error
LoadConfig allows to manually load the configuration file.
func ParseDayString ¶
ParseDayString parses the given day string and expects the format YYYY-MM-DD. The returned time is always in timezone UTC to avoid daylight-saving-time issues when adding/subtracting days.
func ParseTime ¶
ParseTime will take in a string that contains a time in some format and try to guess the missing parts. Currently, the following cases are supported: - 15:04 - 15:04:05 - 2006/01/02 15:04 - 2006/01/02 15:04:05 valid date separators: dash, dot, slash valid time separators: colon valid separators between date and time: space, upper-case t
more general information will be taken from time.Now() (e.g. day or year) and more specific information (e.g. seconds) will be set to zero.
Types ¶
type Config ¶
type Config struct {
// Precision sets how precise the stats should be evaluated. Available
// values are: [s second m minute h hour]
// Default: second
Precision string `json:"precision"`
AutoStop bool `json:"autoStop"`
// RoundStartTime will take the start time and round by the factor given.
// Example:
// 60s: 13:45:23 -> 13:45:00
// 60s: 09:01:59 -> 09:02:00
// 5m : 23:32:29 -> 23:30:00
// Refer to time.Time.Round on how it works
RoundStartTime string `json:"roundStartTime"`
Timeclock struct {
HoursPerDay int `json:"hoursPerDay"`
DaysPerWeek struct {
Monday bool `json:"monday"`
Tuesday bool `json:"tuesday"`
Wednesday bool `json:"wednesday"`
Thursday bool `json:"thursday"`
Friday bool `json:"friday"`
Saturday bool `json:"saturday"`
Sunday bool `json:"sunday"`
} `json:"daysPerWeek"`
} `json:"timeclock"`
}
Config holds all available configuration values.
func GetConfig ¶
func GetConfig() Config
GetConfig returns the current Config and lazy loads it if necessary.
func (Config) GetPrecision ¶
GetPrecision returns the precision as a duration.
func (Config) GetRoundStartTime ¶
type DB ¶
type DB interface {
// SaveTimer will write a single timer to the database.
SaveTimer(Timer) error
// GetTimer reads a single timer from the database by appending `LIMIT 1` to
// the query. Will return ErrNotFound if no timer matching the filter exists.
GetTimer(Filter, OrderBy, *Timer) error
GetTimerById(string, *Timer) error
// GetTimers returns multiple timers from the database that match the filter.
// Will never return ErrNotFound but rather just an empty list.
GetTimers(Filter, OrderBy, *Timers) error
// UpdateTimer updates existing timers in the db based on the id. If the timer
// does not exist an ErrNotFound is returned.
UpdateTimer(Timer) error
// RemoveTimer removes the timer from the database.
RemoveTimer(string) error
SaveVacationDay(VacationDay) error
GetVacationDay(VacationFilter, *VacationDay) error
GetVacationDays(OrderBy, *[]VacationDay) error
RemoveVacationDay(string) error
}
type DatabaseFilter ¶
type DatabaseFilter interface {
SQL() string
}
type Filter ¶
type Filter interface {
DatabaseFilter
Match(Timer) bool
Timers(Timers) Timers
}
func ParseFilterString ¶
ParseFilterString takes a string and creates a filter from it. The filter string has to be in the following format:
filterName=values;filterName=values;...
each filterName consists of a string, values contains the filter value. Some filters only accept a single value, others accept multiple values separated by commas.
Example:
project=work,school;since=2020-01-01;until=2020-02-01
Available filters are:
project: accepts multiple string values task : accepts multiple string values since : accepts a single string int the format of yyyy-MM-dd until : accepts a single string int the format of yyyy-MM-dd tags : accepts multiple string values
since and until are inclusive, both dates will be included in filtered data.
type GroupByOption ¶
type GroupByOption string
type Month ¶
type Month struct {
// Days contains the days of the month but starts at 0
Days []Day
}
type Timer ¶
type Timer struct {
ID string `json:"id" validate:"required,uuid4"`
Start time.Time `json:"start" validate:"required"`
Stop *time.Time `json:"stop,omitempty" validate:"omitempty,gtfield=Start"`
Project string `json:"project" validate:"required"`
Task string `json:"task,omitempty"`
Tags []string `json:"tags,omitempty"`
}
Timer is the central type that stores a timer and all its relevant values.
func (Timer) Duration ¶
Duration returns the duration that the timer has been running. If the timer is still running it will return the time it has run until now.
type Timers ¶
type Timers []Timer
Timers stores a list of timers to attach functions to it.
func (Timers) GroupByDay ¶
func (Timers) GroupByProject ¶
type VacationDay ¶
type VacationDay struct {
ID string `json:"id"`
Day time.Time `json:"day"`
Half bool `json:"half"`
}
func (VacationDay) String ¶
func (v VacationDay) String() string
type VacationFilter ¶
func (VacationFilter) SQL ¶
func (f VacationFilter) SQL() string