Skip to content

Commit

Permalink
🚀 chore: ztype.ToMap adds support for time types
Browse files Browse the repository at this point in the history
  • Loading branch information
sohaha committed Jul 16, 2024
1 parent 97226bf commit caa5f76
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ztype/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"errors"
"reflect"
"strings"
"time"
"unsafe"

"github.com/sohaha/zlsgo/zreflect"
"github.com/sohaha/zlsgo/zstring"
"github.com/sohaha/zlsgo/ztime"
)

var (
Expand Down Expand Up @@ -266,6 +268,16 @@ func toMapStringReflect(m *map[string]interface{}, val interface{}) {
}
}
fv := reflect.Indirect(v)
if fv.IsValid() && isTime(fv.Type().String()) {
switch v := fv.Interface().(type) {
case time.Time:
(*m)[name] = ztime.FormatTime(v)
case ztime.LocalTime:
(*m)[name] = v.String()
}
continue
}

switch fv.Kind() {
case reflect.Struct:
(*m)[name] = toMapString(v.Interface())
Expand Down

0 comments on commit caa5f76

Please sign in to comment.