Documentation ¶
Overview ¶
Package klog is the implementation of the domain logic of klog. It is essentially the code representation of the concepts as they are defined in the file format specification.
Index ¶
- Constants
- Variables
- func Unbox[TargetT any](e *Entry, r func(Range) TargetT, d func(Duration) TargetT, ...) TargetT
- type Date
- type DateFormat
- type Duration
- type DurationFormat
- type Entry
- type EntrySummary
- type OpenRange
- type OpenRangeFormat
- type Range
- type RangeFormat
- type Record
- type RecordSummary
- type ShouldTotal
- type Tag
- type TagSet
- type Time
- func NewTime(hour int, minute int) (Time, error)
- func NewTimeFromGo(t gotime.Time) Time
- func NewTimeFromString(hhmm string) (Time, error)
- func NewTimeTomorrow(hour int, minute int) (Time, error)
- func NewTimeYesterday(hour int, minute int) (Time, error)
- func Ɀ_IsAmPm_(t Time) Time
- func Ɀ_TimeTomorrow_(hour int, minute int) Time
- func Ɀ_TimeYesterday_(hour int, minute int) Time
- func Ɀ_Time_(hour int, minute int) Time
- type TimeFormat
Constants ¶
const SPEC_VERSION = "1.4"
SPEC_VERSION contains the version number of the file format specification which this implementation is based on.
Variables ¶
var HashTagPattern = regexp.MustCompile(`#([\p{L}\d_-]+)(=(("[^"]*")|('[^']*')|([\p{L}\d_-]*)))?`)
Functions ¶
Types ¶
type Date ¶
type Date interface { // Year returns the year as number, e.g. `2004`. Year() int // Month returns the month as number, e.g. `3` for March. Month() int // Day returns the day as number, e.g. `21`. Day() int // Weekday returns the day of the week, starting from Monday = 1. Weekday() int // Quarter returns the quarter that the date is in, e.g. `2` for `2010-04-15`. Quarter() int // WeekNumber returns the number of the week and the year that the number refers to. // Note: the year of the week number might be different from the year of the Date! WeekNumber() (int, int) // IsEqualTo checks whether two dates are the same. IsEqualTo(Date) bool // IsAfterOrEqual checks whether the given date occurs afterwards or at the same date. IsAfterOrEqual(Date) bool // PlusDays adds a number of days to the date. It doesn’t modify // the original object. PlusDays(int) Date // ToString serialises the date, e.g. `2017-04-23`. ToString() string // ToStringWithFormat serialises the date according to the given format. ToStringWithFormat(DateFormat) string // Format returns the current formatting. Format() DateFormat }
Date represents a day in the gregorian calendar.
func NewDateFromGo ¶
func NewDateFromString ¶
type DateFormat ¶
type DateFormat struct {
UseDashes bool
}
DateFormat contains the formatting options for the Date.
func DefaultDateFormat ¶
func DefaultDateFormat() DateFormat
DefaultDateFormat returns the canonical date format, as recommended by the spec.
type Duration ¶
type Duration interface { InMinutes() int // Plus adds up two durations and returns a new duration. // It doesn’t alter the original duration object. Plus(Duration) Duration // Minus subtracts the second from the first duration. // It doesn’t alter the original duration object. Minus(Duration) Duration // ToString serialises the duration. If the duration is negative, // the value is preceded by a `-`. E.g. `45m` or `-2h15m`. ToString() string // ToStringWithSign serialises the duration. In contrast to `ToString` // it also precedes positive values with a `+`. If the duration is `0`, // no sign will be added. E.g. `-45m` or `0` or `+6h`. ToStringWithSign() string }
Duration represents a time span.
func NewDuration ¶
func NewDurationFromString ¶
func NewDurationWithFormat ¶
func NewDurationWithFormat(amountHours int, amountMinutes int, format DurationFormat) Duration
type DurationFormat ¶
type DurationFormat struct { // ForcePlus indicates whether to enforce a `+` for positive values (including 0) ForcePlus bool // ZeroSign indicates what sign a value of `0` should have: // `0` means no sign (default), `1` means `+`, `-1` means `-`. ZeroSign int }
DurationFormat contains the formatting options for a Duration.
func DefaultDurationFormat ¶
func DefaultDurationFormat() DurationFormat
DefaultDurationFormat returns the canonical duration format, as recommended by the spec.
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry is a time value and an associated entry summary. A time value can be a Range, a Duration, or an OpenRange.
func NewEntryFromDuration ¶
func NewEntryFromDuration(value Duration, summary EntrySummary) Entry
func NewEntryFromOpenRange ¶
func NewEntryFromOpenRange(value OpenRange, summary EntrySummary) Entry
func NewEntryFromRange ¶
func NewEntryFromRange(value Range, summary EntrySummary) Entry
func (*Entry) Summary ¶
func (e *Entry) Summary() EntrySummary
type EntrySummary ¶
type EntrySummary []string
EntrySummary contains the summary line that appears behind the time value of an entry.
func NewEntrySummary ¶
func NewEntrySummary(line ...string) (EntrySummary, error)
NewEntrySummary creates an EntrySummary from individual lines of text. Except for the first line, none of the lines can be empty or blank.
func (EntrySummary) Append ¶
func (s EntrySummary) Append(appendableText string) EntrySummary
Append appends a text to an entry summary
func (EntrySummary) Equals ¶
func (s EntrySummary) Equals(summary EntrySummary) bool
func (EntrySummary) Lines ¶
func (s EntrySummary) Lines() []string
func (EntrySummary) Tags ¶
func (s EntrySummary) Tags() *TagSet
Tags returns the tags that the entry summary contains.
type OpenRange ¶
type OpenRange interface { Start() Time // ToString serialises the open range, e.g. `9:00 - ?`. ToString() string // Format returns the current formatting. Format() OpenRangeFormat }
OpenRange represents a range that has not ended yet.
func NewOpenRange ¶
func NewOpenRangeWithFormat ¶
func NewOpenRangeWithFormat(start Time, format OpenRangeFormat) OpenRange
func Ɀ_QuestionMarks_ ¶
Deprecated
type OpenRangeFormat ¶
OpenRangeFormat contains the formatting options for an OpenRange.
func DefaultOpenRangeFormat ¶
func DefaultOpenRangeFormat() OpenRangeFormat
DefaultOpenRangeFormat returns the canonical open range format, as recommended by the spec.
type Range ¶
type Range interface { Start() Time End() Time Duration() Duration // ToString serialises the range, e.g. `13:15 - 17:23`. ToString() string // Format returns the current formatting. Format() RangeFormat }
Range represents the period of time between two points of time.
func NewRangeWithFormat ¶
func NewRangeWithFormat(start Time, end Time, format RangeFormat) (Range, error)
type RangeFormat ¶
type RangeFormat struct {
UseSpacesAroundDash bool
}
RangeFormat contains the formatting options for a Range.
func DefaultRangeFormat ¶
func DefaultRangeFormat() RangeFormat
DefaultRangeFormat returns the canonical time range format, as recommended by the spec.
type Record ¶
type Record interface { Date() Date ShouldTotal() ShouldTotal SetShouldTotal(Duration) Summary() RecordSummary SetSummary(RecordSummary) // Entries returns a list of all entries that are associated with this record. Entries() []Entry // SetEntries associates new entries with the record. SetEntries([]Entry) AddDuration(Duration, EntrySummary) AddRange(Range, EntrySummary) // OpenRange returns the open time range, or `nil` if there is none. OpenRange() OpenRange // Start starts a new open time range. It returns an error if there is // already an open time range present. (There can only be one per record.) Start(OpenRange, EntrySummary) error // EndOpenRange ends the open time range. It returns an error if there is // no open time range present, or if start and end time cannot be converted // into a valid time range. EndOpenRange(Time) error }
Record is a self-contained data container that holds the time tracking information associated with a certain date.
type RecordSummary ¶
type RecordSummary []string
RecordSummary contains the summary lines of the overall summary that appears underneath the date of a record.
func NewRecordSummary ¶
func NewRecordSummary(line ...string) (RecordSummary, error)
NewRecordSummary creates a new RecordSummary from individual lines of text. None of the lines can start with blank characters, and none of the lines can be empty or blank.
func (RecordSummary) Equals ¶
func (s RecordSummary) Equals(summary RecordSummary) bool
func (RecordSummary) Lines ¶
func (s RecordSummary) Lines() []string
func (RecordSummary) Tags ¶
func (s RecordSummary) Tags() *TagSet
type ShouldTotal ¶
type ShouldTotal Duration
ShouldTotal represents the targeted total time of a Record.
func NewShouldTotal ¶
func NewShouldTotal(hours int, minutes int) ShouldTotal
type Tag ¶
type Tag struct {
// contains filtered or unexported fields
}
func NewTagFromString ¶
func NewTagOrPanic ¶
NewTagOrPanic constructs a new tag but will panic if the parameters don’t yield a valid tag.
type TagSet ¶
type TagSet struct {
// contains filtered or unexported fields
}
func NewEmptyTagSet ¶
func NewEmptyTagSet() TagSet
func (*TagSet) Contains ¶
Contains checks whether the TagSet contains the given tag. Note that if the TagSet contains a tag with value, then this will always yield a match against the base tag (without value).
func (*TagSet) ForLookup ¶
ForLookup returns a denormalised and unordered representation of the TagSet.
type Time ¶
type Time interface { Hour() int Minute() int // MidnightOffset returns the duration since (positive) or until (negative) midnight. MidnightOffset() Duration // IsYesterday checks whether the time is shifted to the previous day. IsYesterday() bool // IsTomorrow checks whether the time is shifted to the next day. IsTomorrow() bool // IsToday checks whether the time is not shifted. IsToday() bool IsEqualTo(Time) bool IsAfterOrEqual(Time) bool // Plus returns a time, where the specified duration was added. It doesn’t modify // the original object. If the resulting time would be shifted by more than one // day, it returns an error. Plus(Duration) (Time, error) // ToString serialises the time, e.g. `8:00` or `23:00>` ToString() string // ToStringWithFormat serialises the date according to the given format. ToStringWithFormat(TimeFormat) string // Format returns the current formatting. Format() TimeFormat }
Time represents a wall clock time. It can be shifted to the adjacent dates.
func NewTimeFromGo ¶
func NewTimeFromString ¶
type TimeFormat ¶
type TimeFormat struct {
Use24HourClock bool
}
TimeFormat contains the formatting options for the Time.
func DefaultTimeFormat ¶
func DefaultTimeFormat() TimeFormat
DefaultTimeFormat returns the canonical time format, as recommended by the spec.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package app contains the functionality that is related to the application layer.
|
Package app contains the functionality that is related to the application layer. |
cli
Package cli contains handlers for all available commands.
|
Package cli contains handlers for all available commands. |
cli/report
Package report is a utility for the report command.
|
Package report is a utility for the report command. |
main
Package klog is the entry point of the command line tool.
|
Package klog is the entry point of the command line tool. |
Package parser contains the logic how to convert Record objects from and to plain text.
|
Package parser contains the logic how to convert Record objects from and to plain text. |
json
Package json contains the logic of serialising Record’s as JSON.
|
Package json contains the logic of serialising Record’s as JSON. |
reconciling
Package reconciling contains logic to manipulate klog source text.
|
Package reconciling contains logic to manipulate klog source text. |
txt
Package txt is a generic utility for parsing and processing a text that is structured in individual lines.
|
Package txt is a generic utility for parsing and processing a text that is structured in individual lines. |
Package service contains utilities that address various common use-cases of processing records.
|
Package service contains utilities that address various common use-cases of processing records. |