File: render_time.go

package info (click to toggle)
golang-github-smartystreets-assertions 1.10.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 580 kB
  • sloc: python: 80; makefile: 41; sh: 15
file content (26 lines) | stat: -rw-r--r-- 484 bytes parent folder | download | duplicates (2)
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
package render

import (
	"reflect"
	"time"
)

func renderTime(value reflect.Value) (string, bool) {
	if instant, ok := convertTime(value); !ok {
		return "", false
	} else if instant.IsZero() {
		return "0", true
	} else {
		return instant.String(), true
	}
}

func convertTime(value reflect.Value) (t time.Time, ok bool) {
	if value.Type() == timeType {
		defer func() { recover() }()
		t, ok = value.Interface().(time.Time)
	}
	return
}

var timeType = reflect.TypeOf(time.Time{})