Passed
Push — master ( ad64d3...e465b8 )
by Serhii
01:08 queued 11s
created

tests.setup   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 1
cts 1
cp 1
crap 1
nop 0
1
package tests
2
3
import (
4
	"time"
5
)
6
7
const (
8
	second time.Duration = time.Second
9
	minute time.Duration = time.Minute
10
	hour   time.Duration = time.Hour
11
	day    time.Duration = hour * 24
12
	week   time.Duration = day * 7
13
	// we cannot add month and year because months and years cannot have static values
14
)
15
16
func subTime(duration time.Duration) time.Time {
17 1
	return time.Now().Add(-duration)
18
}
19
20
func subSeconds(duration time.Duration) time.Time {
21 1
	return subTime(second * duration)
22
}
23
24
func subMinutes(duration time.Duration) time.Time {
25 1
	return subTime(minute * duration)
26
}
27
28
func subHours(duration time.Duration) time.Time {
29 1
	return subTime(hour * duration)
30
}
31
32
func subDays(duration time.Duration) time.Time {
33 1
	return subTime(day * duration)
34
}
35
36
func subWeeks(duration time.Duration) time.Time {
37 1
	return subTime(week * duration)
38
}
39
40
func subMonths(duration time.Duration) time.Time {
41 1
	return subTime(duration * getDaysInMonth() * day)
42
}
43
44
func subYears(duration time.Duration) time.Time {
45 1
	return subTime(duration * getDaysInYear() * day)
46
}
47
48
func getDaysInYear() time.Duration {
49 1
	lastDayOfTheYear := time.Date(time.Now().Year(), 12, 31, 0, 0, 0, 0, time.UTC)
50 1
	return time.Duration(lastDayOfTheYear.YearDay())
51
}
52
53
func getDaysInMonth() time.Duration {
54 1
	return time.Duration(getLastDayOfMonth(time.Now()).Day())
55
}
56
57
func getLastDayOfMonth(date time.Time) time.Time {
58 1
	return date.AddDate(0, 1, -date.Day())
59
}
60