-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
41 lines (32 loc) · 879 Bytes
/
utils.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
package main
import (
"regexp"
"strings"
"time"
)
type void struct{}
var dateRegexp = regexp.MustCompile(`\d{4}-\d{2}-\d{2}`)
func ConvertRelativeToAbsoluteTime(relativeTime string, date time.Time) string {
nowDate := date.Format("2006-01-02")
nextDate := date.AddDate(0, 0, 1).Format("2006-01-02")
dayAfterNextDate := date.AddDate(0, 0, 2).Format("2006-01-02")
replacer := strings.NewReplacer(
"今天", nowDate,
"明天", nextDate,
"後天", dayAfterNextDate,
)
return replacer.Replace(relativeTime)
}
func HasStatusIsOld(status string, referenceDate time.Time) bool {
referenceDate = referenceDate.Truncate(24 * time.Hour)
for _, match := range dateRegexp.FindAllString(status, -1) {
parsedDate, err := time.Parse("2006-01-02", match)
if err != nil {
continue
}
if !parsedDate.Before(referenceDate) {
return false
}
}
return true
}