aboutsummaryrefslogtreecommitdiff
path: root/modules/base
diff options
context:
space:
mode:
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/template.go13
-rw-r--r--modules/base/tool.go22
2 files changed, 29 insertions, 6 deletions
diff --git a/modules/base/template.go b/modules/base/template.go
index 0d682545..7f575388 100644
--- a/modules/base/template.go
+++ b/modules/base/template.go
@@ -131,12 +131,13 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
"LoadTimes": func(startTime time.Time) string {
return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
},
- "AvatarLink": AvatarLink,
- "Safe": Safe,
- "Str2html": Str2html,
- "TimeSince": TimeSince,
- "FileSize": FileSize,
- "Subtract": Subtract,
+ "AvatarLink": AvatarLink,
+ "Safe": Safe,
+ "Str2html": Str2html,
+ "TimeSince": TimeSince,
+ "RawTimeSince": RawTimeSince,
+ "FileSize": FileSize,
+ "Subtract": Subtract,
"Add": func(a, b int) int {
return a + b
},
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 92f493af..16759f21 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -321,6 +321,10 @@ func timeSince(then time.Time, lang string) string {
}
}
+func RawTimeSince(t time.Time, lang string) string {
+ return timeSince(t, lang)
+}
+
// TimeSince calculates the time interval and generate user-friendly string.
func TimeSince(t time.Time, lang string) template.HTML {
return template.HTML(fmt.Sprintf(`<span class="time-since" title="%s">%s</span>`, t.Format(setting.TimeFormat), timeSince(t, lang)))
@@ -420,3 +424,21 @@ func Subtract(left interface{}, right interface{}) interface{} {
return fleft + float64(rleft) - (fright + float64(rright))
}
}
+
+// StringsToInt64s converts a slice of string to a slice of int64.
+func StringsToInt64s(strs []string) []int64 {
+ ints := make([]int64, len(strs))
+ for i := range strs {
+ ints[i] = com.StrTo(strs[i]).MustInt64()
+ }
+ return ints
+}
+
+// Int64sToMap converts a slice of int64 to a int64 map.
+func Int64sToMap(ints []int64) map[int64]bool {
+ m := make(map[int64]bool)
+ for _, i := range ints {
+ m[i] = true
+ }
+ return m
+}