Passed
Push — master ( 506188...263cb0 )
by Serhii
03:10 queued 01:33
created

timeago.getTimeTranslations   A

Complexity

Conditions 1

Size

Total Lines 36
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 30
dl 0
loc 36
ccs 1
cts 1
cp 1
crap 1
rs 9.16
c 0
b 0
f 0
nop 0
1
package timeago
2
3
import (
4
	"fmt"
5
)
6
7
// getTimeTranslations returns array of translations for different
8
// cases. For example `1 second` must not have `s` at the end
9
// but `2 seconds` requires `s`. So this method keeps all
10
// possible options for the translated word.
11
func getTimeTranslations() map[string]map[string]string {
12 1
	return map[string]map[string]string{
13
		"seconds": {
14
			"single":  trans().Second,
15
			"plural":  trans().Seconds,
16
			"special": trans().SecondsSpecial,
17
		},
18
		"minutes": {
19
			"single":  trans().Minute,
20
			"plural":  trans().Minutes,
21
			"special": trans().MinutesSpecial,
22
		},
23
		"hours": {
24
			"single":  trans().Hour,
25
			"plural":  trans().Hours,
26
			"special": trans().HoursSpecial,
27
		},
28
		"days": {
29
			"single":  trans().Day,
30
			"plural":  trans().Days,
31
			"special": trans().DaysSpecial,
32
		},
33
		"weeks": {
34
			"single":  trans().Week,
35
			"plural":  trans().Weeks,
36
			"special": trans().WeeksSpecial,
37
		},
38
		"months": {
39
			"single":  trans().Month,
40
			"plural":  trans().Months,
41
			"special": trans().MonthsSpecial,
42
		},
43
		"years": {
44
			"single":  trans().Year,
45
			"plural":  trans().Years,
46
			"special": trans().YearsSpecial,
47
		},
48
	}
49
}
50
51
func getLanguageForm(num int) string {
52 1
	var form string
53 1
	lastDigit := getLastNumber(num)
54 1
	rule := getRules(num, lastDigit)[language]
55
56 1
	switch {
57
	case rule.Special:
58 1
		return "special"
59
	case rule.Single:
60 1
		return "single"
61
	case rule.Plural:
62 1
		return "plural"
63
	}
64
65
	fmt.Printf("Provided rules don't apply to a number %d", num)
66
67
	return form
68
}
69