diff --git a/dump/dump.go b/dump/dump.go index 2c74462e6..0f6e1f5bc 100644 --- a/dump/dump.go +++ b/dump/dump.go @@ -7,6 +7,7 @@ import ( "io" "os" "reflect" + "time" "github.com/gookit/color" ) @@ -47,6 +48,8 @@ var ( // some type init stringerType = reflect.TypeOf((*fmt.Stringer)(nil)).Elem() + // time.Time type + timeType = reflect.TypeOf(time.Time{}) ) // Theme color code/tag map for dump diff --git a/dump/dumper.go b/dump/dumper.go index b0eb66a6e..bb2d69e02 100644 --- a/dump/dumper.go +++ b/dump/dumper.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" "sync" + "time" "github.com/gookit/color" "github.com/gookit/goutil/strutil" @@ -150,7 +151,7 @@ func (d *Dumper) printCaller(pc uintptr, file string, line int) { case Ffname: // only file name fName := path.Base(file) // file name nodes = append(nodes, fName) - case Fline: + default: // Fline nodes = append(nodes, ":", lineS) } } @@ -276,6 +277,13 @@ func (d *Dumper) printRValue(t reflect.Type, v reflect.Value) { break // don't print v again } + // up: special handel time.Time struct + if t == timeType { + timeStr := v.Interface().(time.Time).Format(time.RFC3339) + d.printf("time.Time(%s),\n", d.ColorTheme.string(timeStr)) + break + } + d.write(!isPtr, d.ColorTheme.msType(t.String()), " {\n") d.msValue = false diff --git a/timex/conv_test.go b/timex/conv_test.go index da5a6301c..1bae9d69c 100644 --- a/timex/conv_test.go +++ b/timex/conv_test.go @@ -76,7 +76,6 @@ func TestTryToTime(t *testing.T) { } else { assert.Err(t, err) } - assert.Eq(t, item.out, timex.Format(tt)) }