config.go   A
last analyzed

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
cc 3
eloc 26
dl 0
loc 62
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A timeago.Config.isLocationProvided 0 2 2
A timeago.NewConfig 0 7 1
1
package timeago
2
3
const (
4
	LangEn string = "en" // English
5
	LangRu string = "ru" // Russian
6
	LangUk string = "uk" // Ukrainian
7
	LangNl string = "nl" // Dutch
8
	LangDe string = "de" // German
9
	LangZh string = "zh" // Chinese
10
	LangBe string = "be" // Belarusian
11
	LangEs string = "es" // Spanish
12
	LangJa string = "ja" // Japanese
13
	LangFr string = "fr" // French
14
)
15
16
type Config struct {
17
	// Language is an ISO 639 language code like en, ru, de, nl, etc.
18
	// Default: LangEn ("en").
19
	Language string
20
21 1
	// Location is the timezone location needed for parsing
22 1
	// string date like "2019-01-01 00:00:00" to time.Time.
23
	// If Location is not set it will default to the server's.
24
	// Example: "America/New_York", "Europe/Moscow".
25 1
	// Default: "UTC".
26
	Location string
27
28
	// Translations is a slice of language sets that can be used to
29 1
	// overwrite the default translations. Read more about it in the docs
30
	// https://time-ago.github.io/configurations.html#overwrite-translations
31
	// Default: []LangSet{}
32
	Translations []LangSet
33
34
	// OnlineThreshold is the threshold in seconds to determine when
35
	// Timeago should show "Online" instead of "X seconds ago". If the
36
	// time difference is less than the threshold, it will show "Online".
37 1
	// Minimum value: "1"
38
	// Default: "60"
39
	OnlineThreshold int
40
41
	// JustNowThreshold is the threshold in seconds to determine when
42
	// Timeago should show "Just now" instead of "X seconds ago". If the
43
	// time difference is less than the threshold, it will show "Just now".
44
	// Minimum value: "1"
45
	// Default: "60"
46
	JustNowThreshold int
47
}
48
49
// NewConfig creates a new Config instance with the given language, location
50
// and language sets to overwrite the default translations.
51
func NewConfig(lang, loc string, langSets []LangSet, online, justNow int) *Config {
52
	return &Config{
53
		Language:         lang,
54
		Location:         loc,
55
		Translations:     langSets,
56
		OnlineThreshold:  online,
57
		JustNowThreshold: justNow,
58
	}
59
}
60
61
func (c Config) isLocationProvided() bool {
62
	return c.Location != "UTC" && c.Location != ""
63
}
64