timer

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 37 Imported by: 0

Documentation

Overview

Package timer operates the Focus countdown timer and handles the recovery of interrupted timers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete added in v1.4.0

func Delete(db store.DB) error

Delete permanently removes one or more paused timers.

func Recover

func Recover(
	db store.DB,
	ctx *cli.Context,
) (*Timer, *Session, error)

Recover attempts to recover an interrupted timer.

Types

type Remainder added in v1.4.0

type Remainder struct {
	T int // total
	M int // minutes
	S int // seconds
}

Remainder is the time remaining in an active session.

type Session added in v1.4.0

type Session struct {
	StartTime time.Time       `json:"start_time"`
	EndTime   time.Time       `json:"end_time"`
	Name      config.SessType `json:"name"`
	Tags      []string        `json:"tags"`
	Timeline  []Timeline      `json:"timeline"`
	Duration  time.Duration   `json:"duration"`
	Completed bool            `json:"completed"`
}

Session represents an active work or break session.

func (*Session) ElapsedTimeInSeconds added in v1.4.0

func (s *Session) ElapsedTimeInSeconds() float64

ElapsedTimeInSeconds returns the time elapsed for the current session in seconds using monotonic timings.

func (*Session) IsResuming added in v1.4.0

func (s *Session) IsResuming() bool

IsResuming determines if a session is being resumed or not.

func (*Session) Normalise added in v1.4.0

func (s *Session) Normalise(c context.Context)

Normalise ensures that the end time for the current session perfectly correlates with what is required to complete the session. It mostly helps with normalising the end time when the system is suspended with a session in progress, and resumed at a later time in the future that surpasses the normal end time.

func (*Session) RealElapsedTimeInSeconds added in v1.4.1

func (s *Session) RealElapsedTimeInSeconds() float64

RealElapsedTimeInSeconds returns the time elapsed for the current session in seconds using real timings.

func (*Session) Remaining added in v1.4.0

func (s *Session) Remaining() Remainder

Remaining calculates the time remaining for the session to end.

func (*Session) SetEndTime added in v1.4.0

func (s *Session) SetEndTime()

SetEndTime calculates the end time for the current session.

func (*Session) ToDBModel added in v1.4.0

func (s *Session) ToDBModel() *models.Session

ToDBModel converts an active session to a database model.

func (*Session) UpdateEndTime added in v1.4.0

func (s *Session) UpdateEndTime()

UpdateEndTime sets the session end time to the current time.

type Settled

type Settled struct{}

Settled fulfills the os.Signal interface.

func (Settled) Signal

func (s Settled) Signal()

func (Settled) String

func (s Settled) String() string

type Status added in v1.4.0

type Status struct {
	EndTime           time.Time       `json:"end_date"`
	Name              config.SessType `json:"name"`
	Tags              []string        `json:"tags"`
	WorkCycle         int             `json:"work_cycle"`
	LongBreakInterval int             `json:"long_break_interval"`
}

Status represents the status of a running timer.

type Timeline added in v1.4.0

type Timeline struct {
	// StartTime is the start of the session including
	// the start of a paused session
	StartTime time.Time `json:"start_time"`
	// EndTime is the end of a session including
	// when a session is paused or stopped prematurely
	EndTime time.Time `json:"end_time"`
}

type Timer added in v1.4.0

type Timer struct {
	Opts        *config.TimerConfig `json:"opts"`
	SoundStream beep.Streamer       `json:"-"`
	PausedTime  time.Time           `json:"paused_time"`
	StartTime   time.Time           `json:"start_time"`
	SessionKey  time.Time           `json:"session_key"`
	WorkCycle   int                 `json:"work_cycle"`
	// contains filtered or unexported fields
}

Timer represents a running timer.

func New added in v1.4.0

func New(dbClient store.DB, cfg *config.TimerConfig) (*Timer, error)

New creates a new timer.

func (*Timer) LogValue added in v1.4.1

func (t *Timer) LogValue() slog.Value

func (*Timer) NewSession added in v1.4.0

func (t *Timer) NewSession(
	c context.Context,
	name config.SessType,
	startTime time.Time,
) *Session

NewSession initialises a new session.

func (*Timer) Persist added in v1.4.0

func (t *Timer) Persist(c context.Context, sess *Session) error

Persist saves the current timer and session to the database.

func (*Timer) ReportStatus added in v1.4.0

func (t *Timer) ReportStatus() error

ReportStatus reports the status of the currently running timer.

func (*Timer) Run added in v1.4.0

func (t *Timer) Run(c context.Context, sess *Session) error

Run begins the timer and loops forever, alternating between work and break sessions until it is terminated with Ctrl-C or a maximum number of work sessions is reached.

Jump to

Keyboard shortcuts

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