1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Differentiate between right now Now() and today from midnight

This commit is contained in:
Chris Cummer 2018-04-10 12:42:28 -07:00 committed by Chris Cummer
parent 27a267b123
commit 34b5b69231
3 changed files with 10 additions and 6 deletions

View File

@ -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)))

View File

@ -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) {

View File

@ -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 {