Passed
Push — master ( df7d70...d7b12b )
by Serhii
01:18
created

timeago.readFile   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 5
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
nop 1
1
package timeago
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"time"
7
)
8
9
func unixToTime(userDate int) time.Time {
10
	return time.Unix(int64(userDate), 0)
11
}
12
13
func parseLangSet(filePath string) (*LangSet, error) {
14 1
	content, err := langsFS.ReadFile(filePath)
15
	if err != nil {
16 1
		return nil, fmt.Errorf("could not read language file: %w", err)
17 1
	}
18
19
	langSet := &LangSet{}
20 1
21 1
	if err := json.Unmarshal(content, &langSet); err != nil {
22
		return nil, fmt.Errorf("could not unmarshal language file: %w", err)
23
	}
24
25
	return langSet, nil
26
}
27
28 1
func isUnsignedInteger(s string) bool {
29
	if len(s) == 0 {
30 1
		return false
31
	}
32
33
	for i := 0; i < len(s); i++ {
34 1
		c := s[i]
35
		if c < '0' || c > '9' {
36
			return false
37
		}
38 1
	}
39
40
	return true
41
}
42