Преглед на файлове

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
 	case "week", "wk":
301
 	case "week", "wk":
302
 		output, toUnit = dd/float64(7*24*time.Hour), "wks"
302
 		output, toUnit = dd/float64(7*24*time.Hour), "wks"
303
 	case "year", "yr":
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
 	default:
305
 	default:
306
 		fallthrough
306
 		fallthrough
307
 	case "sec", "second", "s":
307
 	case "sec", "second", "s":

+ 1
- 0
internal/measurement/measurement_test.go Целия файл

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