diff options
| author | Přemysl Eric Janouch <p@janouch.name> | 2025-01-02 00:35:00 +0100 | 
|---|---|---|
| committer | Přemysl Eric Janouch <p@janouch.name> | 2025-01-02 00:36:03 +0100 | 
| commit | 6622ea0e1cb22687791c26b60381b138cbbb8098 (patch) | |
| tree | 7b6f626dc92fa91c46f9eb89f54fc464148301b7 /acid_test.go | |
| parent | a492b3b668c1c9be410a7b126550129fba67025a (diff) | |
| download | acid-6622ea0e1cb22687791c26b60381b138cbbb8098.tar.gz acid-6622ea0e1cb22687791c26b60381b138cbbb8098.tar.xz acid-6622ea0e1cb22687791c26b60381b138cbbb8098.zip  | |
Improve formatting of durations
Since "m" could stand for both "minute" and "month",
and months vary in length, let's stop at days.
Diffstat (limited to 'acid_test.go')
| -rw-r--r-- | acid_test.go | 17 | 
1 files changed, 17 insertions, 0 deletions
diff --git a/acid_test.go b/acid_test.go index 614fd0a..e8bd5c2 100644 --- a/acid_test.go +++ b/acid_test.go @@ -4,6 +4,7 @@ import (  	"bytes"  	"testing"  	ttemplate "text/template" +	"time"  )  func TestTemplateQuote(t *testing.T) { @@ -30,3 +31,19 @@ func TestTemplateQuote(t *testing.T) {  		}  	}  } + +func TestShortDurationString(t *testing.T) { +	for _, test := range []struct { +		d      time.Duration +		expect string +	}{ +		{72 * time.Hour, "3d"}, +		{-3 * time.Hour, "-3h"}, +		{12 * time.Minute, "12m"}, +		{time.Millisecond, "0s"}, +	} { +		if sd := shortDurationString(test.d); sd != test.expect { +			t.Errorf("%s = %s; want %s\n", test.d, sd, test.expect) +		} +	} +}  | 
