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:
parent
27a267b123
commit
34b5b69231
@ -38,8 +38,8 @@ func (widget *Widget) Refresh() {
|
|||||||
client := NewClient(url)
|
client := NewClient(url)
|
||||||
todayItems := client.Away(
|
todayItems := client.Away(
|
||||||
"timeOff",
|
"timeOff",
|
||||||
wtf.Today().Format(wtf.DateFormat),
|
wtf.Now().Format(wtf.DateFormat),
|
||||||
wtf.Today().Format(wtf.DateFormat),
|
wtf.Now().Format(wtf.DateFormat),
|
||||||
)
|
)
|
||||||
|
|
||||||
widget.View.SetTitle(fmt.Sprintf(" 👽 Away (%d) ", len(todayItems)))
|
widget.View.SetTitle(fmt.Sprintf(" 👽 Away (%d) ", len(todayItems)))
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/senorprogrammer/wtf/homedir"
|
"github.com/senorprogrammer/wtf/homedir"
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"golang.org/x/oauth2/google"
|
"golang.org/x/oauth2/google"
|
||||||
@ -48,7 +47,7 @@ func Fetch() (*calendar.Events, error) {
|
|||||||
return nil, err
|
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()
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -93,6 +92,11 @@ func getTokenFromWeb(config *oauth2.Config) *oauth2.Token {
|
|||||||
return tok
|
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.
|
// tokenCacheFile generates credential file path/filename.
|
||||||
// It returns the generated credential path/filename.
|
// It returns the generated credential path/filename.
|
||||||
func tokenCacheFile() (string, error) {
|
func tokenCacheFile() (string, error) {
|
||||||
|
@ -72,12 +72,12 @@ func PrettyDate(dateStr string) string {
|
|||||||
return fmt.Sprint(newTime.Format("Jan 2, 2006"))
|
return fmt.Sprint(newTime.Format("Jan 2, 2006"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func Today() time.Time {
|
func Now() time.Time {
|
||||||
return time.Now().Local()
|
return time.Now().Local()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Tomorrow() time.Time {
|
func Tomorrow() time.Time {
|
||||||
return Today().AddDate(0, 0, 1)
|
return Now().AddDate(0, 0, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToInts(slice []interface{}) []int {
|
func ToInts(slice []interface{}) []int {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user