klog

package
v0.0.0-...-ac17267 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 8 Imported by: 0

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

View Source
const SPEC_VERSION = "1.4"

SPEC_VERSION contains the version number of the file format specification which this implementation is based on.

Variables

View Source
var HashTagPattern = regexp.MustCompile(`#([\p{L}\d_-]+)(=(("[^"]*")|('[^']*')|([\p{L}\d_-]*)))?`)

Functions

func Unbox

func Unbox[TargetT any](e *Entry, r func(Range) TargetT, d func(Duration) TargetT, o func(OpenRange) TargetT) TargetT

Unbox converts the underlying time value.

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 NewDate

func NewDate(year int, month int, day int) (Date, error)

func NewDateFromGo

func NewDateFromGo(t gotime.Time) Date

func NewDateFromString

func NewDateFromString(yyyymmdd string) (Date, error)

func Ɀ_Date_

func Ɀ_Date_(year int, month int, day int) Date

Deprecated

func Ɀ_Slashes_

func Ɀ_Slashes_(d Date) Date

Deprecated

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 NewDuration(amountHours int, amountMinutes int) Duration

func NewDurationFromString

func NewDurationFromString(hhmm string) (Duration, error)

func NewDurationWithFormat

func NewDurationWithFormat(amountHours int, amountMinutes int, format DurationFormat) Duration

func Ɀ_ForceSign_

func Ɀ_ForceSign_(d Duration) Duration

Deprecated

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) Duration

func (e *Entry) Duration() Duration

Duration returns the duration value of the underlying time value.

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_

func Ɀ_EntrySummary_(line ...string) EntrySummary

Deprecated

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 NewOpenRange(start Time) OpenRange

func NewOpenRangeWithFormat

func NewOpenRangeWithFormat(start Time, format OpenRangeFormat) OpenRange

func Ɀ_NoSpacesO_

func Ɀ_NoSpacesO_(r OpenRange) OpenRange

Deprecated

func Ɀ_QuestionMarks_

func Ɀ_QuestionMarks_(r OpenRange, additionalQuestionMarks int) OpenRange

Deprecated

type OpenRangeFormat

type OpenRangeFormat struct {
	UseSpacesAroundDash        bool
	AdditionalPlaceholderChars int
}

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 NewRange

func NewRange(start Time, end Time) (Range, error)

func NewRangeWithFormat

func NewRangeWithFormat(start Time, end Time, format RangeFormat) (Range, error)

func Ɀ_NoSpaces_

func Ɀ_NoSpaces_(r Range) Range

Deprecated

func Ɀ_Range_

func Ɀ_Range_(start Time, end Time) Range

Deprecated

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.

func NewRecord

func NewRecord(date Date) Record

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_

func Ɀ_RecordSummary_(line ...string) RecordSummary

Deprecated

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 NewTagFromString(tag string) (Tag, error)

func NewTagOrPanic

func NewTagOrPanic(name string, value string) Tag

NewTagOrPanic constructs a new tag but will panic if the parameters don’t yield a valid tag.

func (Tag) Name

func (t Tag) Name() string

func (Tag) ToString

func (t Tag) ToString() string

func (Tag) Value

func (t Tag) Value() string

type TagSet

type TagSet struct {
	// contains filtered or unexported fields
}

func Merge

func Merge(tagSets ...*TagSet) TagSet

Merge combines multiple tag sets into a new one.

func NewEmptyTagSet

func NewEmptyTagSet() TagSet

func (*TagSet) Contains

func (ts *TagSet) Contains(tag Tag) bool

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

func (ts *TagSet) ForLookup() map[Tag]bool

ForLookup returns a denormalised and unordered representation of the TagSet.

func (*TagSet) IsEmpty

func (ts *TagSet) IsEmpty() bool

IsEmpty checks whether the TagSet contains something or not.

func (*TagSet) Put

func (ts *TagSet) Put(tag Tag)

Put inserts the tag into the TagSet.

func (*TagSet) ToStrings

func (ts *TagSet) ToStrings() []string

ToStrings returns the tags as string, in their original order and without deduplication or normalisation.

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 NewTime

func NewTime(hour int, minute int) (Time, error)

func NewTimeFromGo

func NewTimeFromGo(t gotime.Time) Time

func NewTimeFromString

func NewTimeFromString(hhmm string) (Time, error)

func NewTimeTomorrow

func NewTimeTomorrow(hour int, minute int) (Time, error)

func NewTimeYesterday

func NewTimeYesterday(hour int, minute int) (Time, error)

func Ɀ_IsAmPm_

func Ɀ_IsAmPm_(t Time) Time

Deprecated

func Ɀ_TimeTomorrow_

func Ɀ_TimeTomorrow_(hour int, minute int) Time

Deprecated

func Ɀ_TimeYesterday_

func Ɀ_TimeYesterday_(hour int, minute int) Time

Deprecated

func Ɀ_Time_

func Ɀ_Time_(hour int, minute int) Time

Deprecated

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.

Directories

Path Synopsis
app
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.

Jump to

Keyboard shortcuts

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