Remove unused second part of the expiry counter
This commit is contained in:
@@ -89,6 +89,29 @@ func TestFormatRoundTrips(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The spellings themselves, not just their round trip: Duration.String() pads
|
||||
// out the units below the largest one, and trimming that tail is easy to get
|
||||
// wrong in a way that eats a real digit ("1m30s" must not become "1m3").
|
||||
func TestFormatDurationSpelling(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
in time.Duration
|
||||
want string
|
||||
}{
|
||||
{Unlimited, "never"},
|
||||
{30 * time.Second, "30s"},
|
||||
{time.Minute, "1m"},
|
||||
{90 * time.Second, "1m30s"},
|
||||
{90 * time.Minute, "1h30m"},
|
||||
{2 * time.Hour, "2h"},
|
||||
{25 * time.Hour, "25h"},
|
||||
{72 * time.Hour, "3d"},
|
||||
} {
|
||||
if got := FormatDuration(c.in); got != c.want {
|
||||
t.Errorf("FormatDuration(%s) = %q, want %q", c.in, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The convention is: one hyphen for a letter, two for a word. It is enforced
|
||||
// here because the stdlib flag package treats both forms as the same.
|
||||
func TestHyphenConvention(t *testing.T) {
|
||||
|
||||
@@ -123,6 +123,13 @@ func FormatDuration(d time.Duration) string {
|
||||
case d%time.Hour == 0:
|
||||
return fmt.Sprintf("%dh", d/time.Hour)
|
||||
default:
|
||||
return d.String()
|
||||
// Duration.String() spells out every unit below the largest one, so a
|
||||
// whole number of minutes arrives as "1m0s". Drop that tail, but only
|
||||
// when the seconds really are zero: "1m30s" has to keep them.
|
||||
s := d.String()
|
||||
if strings.HasSuffix(s, "m0s") {
|
||||
s = strings.TrimSuffix(s, "0s")
|
||||
}
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user