Skip to content

Commit

Permalink
fix #58: add jitter to suggested commiter date
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Jul 26, 2022
1 parent 7dff8db commit b6efbfc
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions internal/command/github/view/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@ package view

import (
"fmt"
"math/rand"
"strconv"
"time"

Expand All @@ -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{}) },

Expand All @@ -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("�", option.Suggest.Day.Sub(now)/xtime.Day)
days := day.Sub(now) / xtime.Day
tail := -day.Sub(now) % xtime.Day
suggestion = fmt.Sprintf("�%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)
Expand Down

0 comments on commit b6efbfc

Please sign in to comment.