eisenhower.go

 1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5package lunatask
 6
 7import "fmt"
 8
 9// Eisenhower represents a quadrant in the Eisenhower priority matrix, which
10// categorizes tasks by whether they are urgent (time-sensitive) and/or
11// important (valuable toward your goals).
12//
13// The four quadrants guide what action to take:
14//
15//	                  | Urgent        | Not Urgent
16//	------------------|---------------|-------------
17//	Important         | Do Now (1)    | Do Later (3)
18//	Not Important     | Delegate (2)  | Eliminate (4)
19//
20// Use [NewEisenhower] to compute the quadrant from boolean flags, or the
21// builder methods [TaskBuilder.Important] and [TaskBuilder.Urgent] for a
22// fluent API.
23type Eisenhower int
24
25// Eisenhower matrix quadrants. See [Eisenhower] for the full matrix.
26const (
27	EisenhowerUncategorized Eisenhower = 0 // not yet categorized
28	EisenhowerDoNow         Eisenhower = 1 // urgent + important
29	EisenhowerDelegate      Eisenhower = 2 // urgent, not important
30	EisenhowerDoLater       Eisenhower = 3 // important, not urgent
31	EisenhowerEliminate     Eisenhower = 4 // neither urgent nor important
32)
33
34// NewEisenhower returns the quadrant for the given flags:
35//
36//	NewEisenhower(true, true)   // DoNow
37//	NewEisenhower(true, false)  // DoLater
38//	NewEisenhower(false, true)  // Delegate
39//	NewEisenhower(false, false) // Eliminate
40func NewEisenhower(important, urgent bool) Eisenhower {
41	switch {
42	case important && urgent:
43		return EisenhowerDoNow
44	case urgent:
45		return EisenhowerDelegate
46	case important:
47		return EisenhowerDoLater
48	default:
49		return EisenhowerEliminate
50	}
51}
52
53// String returns a human-readable description of the Eisenhower quadrant.
54func (e Eisenhower) String() string {
55	switch e {
56	case EisenhowerUncategorized:
57		return "uncategorized"
58	case EisenhowerDoNow:
59		return "do now (important + urgent)"
60	case EisenhowerDelegate:
61		return "delegate (urgent)"
62	case EisenhowerDoLater:
63		return "do later (important)"
64	case EisenhowerEliminate:
65		return "eliminate"
66	default:
67		return fmt.Sprintf("Eisenhower(%d)", e)
68	}
69}
70
71// IsUrgent reports whether e is in an urgent quadrant ([EisenhowerDoNow] or [EisenhowerDelegate]).
72func (e Eisenhower) IsUrgent() bool {
73	return e == EisenhowerDoNow || e == EisenhowerDelegate
74}
75
76// IsImportant reports whether e is in an important quadrant ([EisenhowerDoNow] or [EisenhowerDoLater]).
77func (e Eisenhower) IsImportant() bool {
78	return e == EisenhowerDoNow || e == EisenhowerDoLater
79}