timer

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration in a human-readable way

func FormatDurationShort

func FormatDurationShort(d time.Duration) string

FormatDurationShort formats a duration in a compact way

Types

type Manager

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

Manager manages multiple timers

func NewManager

func NewManager() *Manager

NewManager creates a new timer manager

func (*Manager) ActiveCount

func (m *Manager) ActiveCount() int

ActiveCount returns the number of active (non-expired) timers

func (*Manager) Add

func (m *Manager) Add(timer *Timer)

Add adds a new timer to the manager

func (*Manager) Clear

func (m *Manager) Clear()

Clear removes all timers

func (*Manager) Count

func (m *Manager) Count() int

Count returns the total number of timers (including expired)

func (*Manager) GetActive

func (m *Manager) GetActive() []*Timer

GetActive returns all active (non-expired) timers sorted by remaining time (ascending)

func (*Manager) GetExpired

func (m *Manager) GetExpired() []*Timer

GetExpired returns all expired timers and removes them from the manager

func (*Manager) Remove

func (m *Manager) Remove(id string)

Remove removes a timer by ID

type Timer

type Timer struct {
	ID        string
	StartTime time.Time
	Duration  time.Duration
	Label     string // optional label for the timer
}

Timer represents a countdown timer

func NewTimer

func NewTimer(duration time.Duration, label string) *Timer

NewTimer creates a new timer with the specified duration

func (*Timer) Elapsed

func (t *Timer) Elapsed() time.Duration

Elapsed returns the time elapsed since the timer started

func (*Timer) IsExpired

func (t *Timer) IsExpired() bool

IsExpired returns true if the timer has expired

func (*Timer) PercentComplete

func (t *Timer) PercentComplete() float64

PercentComplete returns the percentage of time elapsed (0-100)

func (*Timer) Remaining

func (t *Timer) Remaining() time.Duration

Remaining returns the time remaining on the timer

Jump to

Keyboard shortcuts

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