Fix duration saying never when it's unlimited
This commit is contained in:
@@ -78,6 +78,14 @@ func TestFormatRoundTrips(t *testing.T) {
|
||||
if got, err := ParseDuration(FormatDuration(d)); err != nil || got != d {
|
||||
t.Errorf("FormatDuration(%s) = %q, which parses back to %s (%v)", d, FormatDuration(d), got, err)
|
||||
}
|
||||
// FormatLifetime reaches the upload form as the expiry placeholder, so
|
||||
// what it prints has to be something a caller could type back.
|
||||
if got, err := ParseDuration(FormatLifetime(d)); err != nil || got != d {
|
||||
t.Errorf("FormatLifetime(%s) = %q, which parses back to %s (%v)", d, FormatLifetime(d), got, err)
|
||||
}
|
||||
}
|
||||
if got := FormatLifetime(Unlimited); got != "unlimited" {
|
||||
t.Errorf("FormatLifetime(Unlimited) = %q, want %q", got, "unlimited")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,16 @@ func ParseDuration(s string) (time.Duration, error) {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// FormatLifetime renders a lifetime *limit*, where FormatDuration's "never"
|
||||
// would describe the wrong thing: a ceiling of Unlimited is not a file that
|
||||
// never expires, it is the absence of a ceiling.
|
||||
func FormatLifetime(d time.Duration) string {
|
||||
if d == Unlimited {
|
||||
return "unlimited"
|
||||
}
|
||||
return FormatDuration(d)
|
||||
}
|
||||
|
||||
// FormatDuration is the human-facing inverse of ParseDuration.
|
||||
func FormatDuration(d time.Duration) string {
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user