Skip to content

Commit

Permalink
✨ feat: dump - special handle for time.Time type display
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Dec 13, 2023
1 parent 71e9b89 commit 1d0e7a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"reflect"
"time"

"github.com/gookit/color"
)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion dump/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"
"sync"
"time"

"github.com/gookit/color"
"github.com/gookit/goutil/strutil"
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion timex/conv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func TestTryToTime(t *testing.T) {
} else {
assert.Err(t, err)
}

assert.Eq(t, item.out, timex.Format(tt))
}

Expand Down

0 comments on commit 1d0e7a0

Please sign in to comment.