From 08deecf1954f6cf748812057ba5cdd9a0425bfc9 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Tue, 3 Oct 2017 07:20:02 -0400 Subject: 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. --- todolist/util.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'todolist/util.go') 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) +} -- cgit v1.3