Skip to content

Commit

Permalink
snappr: Tweak string format of Period
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin committed Nov 15, 2023
1 parent 41d8613 commit c5bfecb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions snappr.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,20 @@ func (p Period) String() string {
case Last:
return p.Unit.String()
case Secondly:
return "every " + (time.Second * time.Duration(p.Interval)).String()
s := (time.Second * time.Duration(p.Interval)).String()
if v, ok := strings.CutSuffix(s, "m0s"); ok {
s = v + "m"
}
if v, ok := strings.CutSuffix(s, "h0m"); ok {
s = v + "h"
}
return s + " time"
default:
k := strings.TrimSuffix(p.Unit.String(), "ly")
if k == "dai" {
k = "day"
}
if p.Interval == 1 {
return "every " + k
}
return "every " + strconv.Itoa(p.Interval) + " " + k + "s"
return strconv.Itoa(p.Interval) + " " + k
}
}

Expand Down
2 changes: 1 addition & 1 deletion snappr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestPrune(t *testing.T) {
policy.MustSet(Secondly, int(time.Hour/time.Second), 6)
policy.MustSet(Last, 1, 3)

return times, policy, "8e05fbf01879c23f1b0754562ff78c8274eeb5ef504c170c7821c54c82881d84"
return times, policy, "bf49acdf6f509786338a6646f7e17a4a4d7bdc987329c0b368f9c383dc56b0e3"
},
// TODO: more cases
} {
Expand Down

0 comments on commit c5bfecb

Please sign in to comment.