Help us shape the future of Go! Take the 2026 Go Developer Survey

activity

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package activity is what was done over a period, read back from the places the work left a trace — git, Taskwarrior, Jira and the forge — and grouped by year, month, day and hour. It holds no clock and does no I/O: a caller says what today is, and hands it what each source read.

Index

Constants

View Source
const MaxDays = 366

MaxDays is the longest period read at once: a year, leap day included.

Variables

View Source
var (
	// ErrBackwards is a period that ends before it starts.
	ErrBackwards = errors.New("the period ends before it starts")
	// ErrTooLong is a period longer than MaxDays.
	ErrTooLong = errors.New("the period is longer than a year and a day")
	// ErrNotADate is text that is not a date written year-month-day.
	ErrNotADate = errors.New("not a date written as YYYY-MM-DD")
)

Functions

This section is empty.

Types

type Date

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

Date is a day on the calendar, wherever it is: no time and no zone, so a period means the same days whichever clock reads it.

func DateOf

func DateOf(instant time.Time) Date

DateOf is the calendar day an instant falls on, in its own location.

func ParseDate

func ParseDate(text string) (Date, error)

ParseDate reads a date written year-month-day, refusing a day the month does not have.

func (Date) AddDays

func (d Date) AddDays(days int) Date

AddDays is the date days later, or earlier when days is negative.

func (Date) AddMonths

func (d Date) AddMonths(months int) Date

AddMonths is the date months later, or earlier when months is negative, on the same day of the month, or the month's last where it has no such day.

func (Date) Before

func (d Date) Before(other Date) bool

Before reports d earlier on the calendar than other.

func (Date) Day

func (d Date) Day() int

Day is the date's day of the month.

func (Date) Month

func (d Date) Month() time.Month

Month is the date's month.

func (Date) Start

func (d Date) Start(loc *time.Location) time.Time

Start is the date's first instant in loc: its midnight, or the first hour the clocks show when they skip midnight. Go places a midnight that never happened an hour before it, on the day before, so it is stepped forward.

func (Date) String

func (d Date) String() string

String is the date written year-month-day.

func (Date) Weekday

func (d Date) Weekday() time.Weekday

Weekday is the day of the week the date falls on.

func (Date) Year

func (d Date) Year() int

Year is the date's year.

type Day

type Day struct {
	Date  Date
	Hours []Hour
}

Day is a day's hours that hold items.

type Hour

type Hour struct {
	Label string
	Items []Item
	// contains filtered or unexported fields
}

Hour is an hour on the clock and its items. Label is the hour as the clock showed it; on a day the clocks are turned back, the hour shown twice is two hours, each labeled with its zone so they read apart.

type Item

type Item struct {
	At         time.Time
	Kind       Kind
	Ref        string
	Title      string
	URL        string
	Repository string
}

Item is one thing done: when, what, and what it was done to — a commit's hash, a task's id, an issue's key or a pull request's number — with a link to it where there is one, and the repository it was in when the summary reads more than one.

func Merge

func Merge(lists ...[]Item) []Item

Merge is the items of every list, oldest first, items at the same moment in the order they were listed. It keeps every item: a commit two repositories share is read once by the read that lists them (loop.CommitsRead), by its full hash, where an item's abbreviated Ref could not tell it apart.

type Kind

type Kind int

Kind is what was done.

const (
	// Committed is a commit you wrote, at its author date.
	Committed Kind = iota + 1
	// TaskAdded is a task added.
	TaskAdded
	// TaskStarted is a task started.
	TaskStarted
	// TaskAnnotated is a note added to a task.
	TaskAnnotated
	// TaskCompleted is a task done.
	TaskCompleted
	// IssueCreated is an issue you reported.
	IssueCreated
	// IssueMoved is an issue you moved to another status.
	IssueMoved
	// IssueWorked is work you logged on an issue.
	IssueWorked
	// IssueCommented is a comment you wrote on an issue.
	IssueCommented
	// PullOpened is a pull or merge request you opened.
	PullOpened
	// PullMerged is a pull or merge request of yours that was merged.
	PullMerged
	// PullReviewed is a pull or merge request you reviewed.
	PullReviewed
)

func (Kind) Source

func (k Kind) Source() Source

Source is where a kind of thing done leaves its trace.

func (Kind) Verb

func (k Kind) Verb() string

Verb is what was done, as a line of the summary says it.

type Month

type Month struct {
	Month time.Month
	Days  []Day
}

Month is a month's days that hold items.

type Period

type Period struct {
	From Date
	To   Date
}

Period is the days from From through To, both included.

func MonthOf

func MonthOf(date Date) Period

MonthOf is the whole month a date falls in.

func NewPeriod

func NewPeriod(from, to Date) (Period, error)

NewPeriod is the days from through to, refusing one that runs backwards or is longer than MaxDays.

func PeriodAsked added in v0.7.0

func PeriodAsked(first, last string, today Date) (Period, error)

PeriodAsked is the period first and last name, each a date written year-month-day or empty when it is not given: both days, one day alone, or the previous working day before today when neither is. Every surface reads a period asked for this way, so each defaults to the same days.

func PreviousWorkingDay

func PreviousWorkingDay(today Date) Period

PreviousWorkingDay is the last working day before today through yesterday, so a Monday reads back Friday and the weekend after it.

func YearOf

func YearOf(date Date) Period

YearOf is the whole year a date falls in.

func (Period) Bounds

func (p Period) Bounds(loc *time.Location) (time.Time, time.Time)

Bounds are the period's first instant in loc and the first instant after it, so an instant is in the period when it is at or after the one and before the other.

func (Period) Days

func (p Period) Days() int

Days is how many days the period holds.

func (Period) Holds added in v0.12.0

func (p Period) Holds(date Date) bool

Holds reports date one of the period's days.

func (Period) Step

func (p Period) Step(steps int) Period

Step is the period moved on by steps of its own length, or back when steps is negative. A whole year steps a year, and a whole month a month, so a month stays a month whatever its days.

func (Period) String

func (p Period) String() string

String is the period named by its days: one, or its first and last.

func (Period) Weeks added in v0.12.0

func (p Period) Weeks() []Week

Weeks are the weeks, Monday to Sunday, the period's days fall in, as a calendar lays the period out a week to a row: the first and the last may hold days the period does not, which Holds tells apart.

type Read

type Read struct {
	Source    Source
	Items     []Item
	Truncated bool
	Failed    error
	NotSetUp  error
}

Read is what one source said for a period: its items, whether it had more than it gave, and why it could not be read when it could not — Failed, a source that is set up and refused, or NotSetUp, one with nothing set up to ask, which a summary leaves out rather than calls unread.

type Source

type Source int

Source is a place work leaves a trace.

const (
	// SourceGit is the commits in the repository.
	SourceGit Source = iota + 1
	// SourceTasks is Taskwarrior.
	SourceTasks
	// SourceJira is Jira.
	SourceJira
	// SourceForge is GitHub or GitLab.
	SourceForge
)

func (Source) Name

func (s Source) Name() string

Name is the source as a sentence names it.

func (Source) Title

func (s Source) Title() string

Title is the source as a sentence starts with it.

type Summary

type Summary struct {
	Period Period
	Reads  []Read
}

Summary is what every source read for a period.

func (Summary) Items

func (s Summary) Items() []Item

Items are every source's items, merged.

func (Summary) Text

func (s Summary) Text(loc *time.Location) string

Text is the summary as Markdown to copy: the period, then its items nested by year, month, day and hour in loc, then a line for each source that could not be read or had more than it gave.

type Week added in v0.12.0

type Week [daysInWeek]Date

Week is seven days, Monday to Sunday.

type Year

type Year struct {
	Year   int
	Months []Month
}

Year is a year's months that hold items. Year, Month, Day and Hour group items as the summary nests them, oldest first at every level, with no minutes.

func Group

func Group(items []Item, loc *time.Location) []Year

Group nests items, oldest first, by the year, month, day and hour each falls on in loc.

Jump to

Keyboard shortcuts

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