aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/util.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2017-10-03 07:20:02 -0400
committerGrant Ammons <gammons@gmail.com>2017-10-03 07:20:41 -0400
commit08deecf1954f6cf748812057ba5cdd9a0425bfc9 (patch)
tree722ccf48c7a204af8d508c2f2757f673f771915b /todolist/util.go
parent0840e7a147d8594acec63fd1ce8aba9e15472839 (diff)
Refactor the formatter to an interface and rename it
This change refactors the formatter to be an interface called Printer. `NewApp` will use the functionality of `ScreenPrinter`, which is what I refactored the old `Formatter` class into. There is a new class the implements the `Printer` interface called `MemoryPrinter`, which will simply store the `groups` as they were passed to it. This will allow tests in `app_test.go` to become much more powerful, since `App` no longer needs to be tightly coupled to printing to the screen.
Diffstat (limited to 'todolist/util.go')
-rw-r--r--todolist/util.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/todolist/util.go b/todolist/util.go
index ff3dbba..6fa93f3 100644
--- a/todolist/util.go
+++ b/todolist/util.go
@@ -59,3 +59,23 @@ func pluralize(count int, singular, plural string) string {
}
return singular
}
+
+func isToday(t time.Time) bool {
+ nowYear, nowMonth, nowDay := time.Now().Date()
+ timeYear, timeMonth, timeDay := t.Date()
+ return nowYear == timeYear &&
+ nowMonth == timeMonth &&
+ nowDay == timeDay
+}
+
+func isTomorrow(t time.Time) bool {
+ nowYear, nowMonth, nowDay := time.Now().AddDate(0, 0, 1).Date()
+ timeYear, timeMonth, timeDay := t.Date()
+ return nowYear == timeYear &&
+ nowMonth == timeMonth &&
+ nowDay == timeDay
+}
+
+func isPastDue(t time.Time) bool {
+ return time.Now().After(t)
+}