-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathtemplate.go
More file actions
35 lines (28 loc) · 603 Bytes
/
template.go
File metadata and controls
35 lines (28 loc) · 603 Bytes
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
package main
import (
"fmt"
"reflect"
"time"
"github.com/dustin/go-humanize"
)
func humanized(t interface{}) string {
switch v := t.(type) {
case time.Time:
// flatten time to prevent updating README too often:
v = time.Date(v.Year(), v.Month(), v.Day(), 0, 0, 0, 0, v.Location())
if time.Since(v) <= time.Hour*24 {
return "today"
}
return humanize.Time(v)
default:
return fmt.Sprintf("%v", t)
}
}
func reverse(s interface{}) interface{} {
n := reflect.ValueOf(s).Len()
swap := reflect.Swapper(s)
for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
swap(i, j)
}
return s
}