-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtemplatefunc.go
66 lines (58 loc) · 1.02 KB
/
templatefunc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"strings"
"time"
)
func monthBefore(queryMonth int) int {
switch queryMonth {
case 1:
return 12
default:
return queryMonth - 1
}
}
func monthAfter(queryMonth int) int {
switch queryMonth {
case 12:
return 1
default:
return queryMonth + 1
}
}
func yearBefore(queryYear, queryMonth int) int {
switch queryMonth {
case 1:
return queryYear - 1
default:
return queryYear
}
}
func yearAfter(queryYear, queryMonth int) int {
switch queryMonth {
case 12:
return queryYear + 1
default:
return queryYear
}
}
func offset(year, month int) int {
t := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC)
return int(t.Weekday())
}
func onlyDate(str string) string {
if regexWebdateTime.MatchString(str) {
if str[8] == '0' {
return string(str[9])
}
return str[len(str)-2 : len(str)]
}
return str
}
func checkFade(year, month int, date string) string {
prefix := fmt.Sprintf("%04d-%02d", year, month)
if strings.HasPrefix(date, prefix) {
return ""
}
return "fade"
}