浏览代码

fixed year unit conversion (#212)

* fixed year unit conversion

* added test for conversion to year
Margaret Nolan 7 年前
父节点
当前提交
cc3455886f
共有 2 个文件被更改,包括 2 次插入1 次删除
  1. 1
    1
      internal/measurement/measurement.go
  2. 1
    0
      internal/measurement/measurement_test.go

+ 1
- 1
internal/measurement/measurement.go 查看文件

@@ -301,7 +301,7 @@ func timeLabel(value int64, fromUnit, toUnit string) (v float64, u string, ok bo
301 301
 	case "week", "wk":
302 302
 		output, toUnit = dd/float64(7*24*time.Hour), "wks"
303 303
 	case "year", "yr":
304
-		output, toUnit = dd/float64(365*7*24*time.Hour), "yrs"
304
+		output, toUnit = dd/float64(365*24*time.Hour), "yrs"
305 305
 	default:
306 306
 		fallthrough
307 307
 	case "sec", "second", "s":

+ 1
- 0
internal/measurement/measurement_test.go 查看文件

@@ -34,6 +34,7 @@ func TestScale(t *testing.T) {
34 34
 		{1024, "gb", "tb", 1, "TB"},
35 35
 		{1024, "tb", "pb", 1, "PB"},
36 36
 		{2048, "mb", "auto", 2, "GB"},
37
+		{3.1536e7, "s", "auto", 1, "yrs"},
37 38
 	} {
38 39
 		if gotValue, gotUnit := Scale(tc.value, tc.fromUnit, tc.toUnit); gotValue != tc.wantValue || gotUnit != tc.wantUnit {
39 40
 			t.Errorf("Scale(%d, %q, %q) = (%f, %q), want (%f, %q)",