diff --git a/internal/command/github/view/suggest.go b/internal/command/github/view/suggest.go index ad2c00f..4f6ea90 100644 --- a/internal/command/github/view/suggest.go +++ b/internal/command/github/view/suggest.go @@ -2,6 +2,7 @@ package view import ( "fmt" + "math/rand" "strconv" "time" @@ -21,6 +22,11 @@ type SuggestOption struct { // TODO:refactoring combine with Lookup, use HeatMap as input // TODO:refactoring extract "table builder", compare with others views +func jitter(duration time.Duration) time.Duration { + r := rand.New(rand.NewSource(time.Now().UnixNano())) + return time.Duration(r.Int63n(int64(duration))) +} + func Suggest( printer interface{ Println(...interface{}) }, @@ -29,23 +35,22 @@ func Suggest( option SuggestOption, ) error { - now := time.Now().UTC() + now := time.Now() + day := option.Suggest.Day.Add(jitter(time.Hour)).In(time.Local) var suggestion string if option.Delta { - suggestion = fmt.Sprintf("%dd", option.Suggest.Day.Sub(now)/xtime.Day) + days := day.Sub(now) / xtime.Day + tail := -day.Sub(now) % xtime.Day + suggestion = fmt.Sprintf("%dd%s", days, tail) } else { - day := xtime.CopyClock(now, option.Suggest.Day).In(time.Local) suggestion = day.Format(time.RFC3339) } if option.Short { printer.Println(suggestion) return nil } else if option.Delta { - suggestion = fmt.Sprintf("%s: %s", - option.Suggest.Day.Format(xtime.RFC3339Day), - suggestion, - ) + suggestion = fmt.Sprintf("%s: %s", day.Format(time.RFC3339), suggestion) } data := convert(scope, histogram)