From 34b5b6923119b8c70b1257cef4d45ab3a19aaefd Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 10 Apr 2018 12:42:28 -0700 Subject: [PATCH] Differentiate between right now Now() and today from midnight --- bamboohr/widget.go | 4 ++-- gcal/client.go | 8 ++++++-- wtf/utils.go | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bamboohr/widget.go b/bamboohr/widget.go index a7736fdd..f7006fc5 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -38,8 +38,8 @@ func (widget *Widget) Refresh() { client := NewClient(url) todayItems := client.Away( "timeOff", - wtf.Today().Format(wtf.DateFormat), - wtf.Today().Format(wtf.DateFormat), + wtf.Now().Format(wtf.DateFormat), + wtf.Now().Format(wtf.DateFormat), ) widget.View.SetTitle(fmt.Sprintf(" 👽 Away (%d) ", len(todayItems))) diff --git a/gcal/client.go b/gcal/client.go index 605cb9fc..7da0aa8e 100644 --- a/gcal/client.go +++ b/gcal/client.go @@ -18,7 +18,6 @@ import ( "time" "github.com/senorprogrammer/wtf/homedir" - "github.com/senorprogrammer/wtf/wtf" "golang.org/x/net/context" "golang.org/x/oauth2" "golang.org/x/oauth2/google" @@ -48,7 +47,7 @@ func Fetch() (*calendar.Events, error) { return nil, err } - t := wtf.Today().Format(time.RFC3339) + t := fromMidnight().Format(time.RFC3339) events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(t).MaxResults(int64(Config.UInt("wtf.mods.gcal.eventCount", 10))).OrderBy("startTime").Do() if err != nil { return nil, err @@ -93,6 +92,11 @@ func getTokenFromWeb(config *oauth2.Config) *oauth2.Token { return tok } +func fromMidnight() time.Time { + now := time.Now() + return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) +} + // tokenCacheFile generates credential file path/filename. // It returns the generated credential path/filename. func tokenCacheFile() (string, error) { diff --git a/wtf/utils.go b/wtf/utils.go index 1256ef69..89dd0440 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -72,12 +72,12 @@ func PrettyDate(dateStr string) string { return fmt.Sprint(newTime.Format("Jan 2, 2006")) } -func Today() time.Time { +func Now() time.Time { return time.Now().Local() } func Tomorrow() time.Time { - return Today().AddDate(0, 0, 1) + return Now().AddDate(0, 0, 1) } func ToInts(slice []interface{}) []int {