mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
fix: time repr wrapper (#2255)
This commit is contained in:
parent
27e773fa1f
commit
1568c3be0e
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/mapping"
|
||||
@ -152,6 +153,14 @@ func writeValue(buf *strings.Builder, arg interface{}) {
|
||||
buf.WriteByte('\'')
|
||||
buf.WriteString(escape(v))
|
||||
buf.WriteByte('\'')
|
||||
case time.Time:
|
||||
buf.WriteByte('\'')
|
||||
buf.WriteString(v.String())
|
||||
buf.WriteByte('\'')
|
||||
case *time.Time:
|
||||
buf.WriteByte('\'')
|
||||
buf.WriteString(v.String())
|
||||
buf.WriteByte('\'')
|
||||
default:
|
||||
buf.WriteString(mapping.Repr(v))
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package sqlx
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@ -138,3 +139,14 @@ func TestFormat(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteValue(t *testing.T) {
|
||||
var buf strings.Builder
|
||||
tm := time.Now()
|
||||
writeValue(&buf, &tm)
|
||||
assert.Equal(t, "'"+tm.String()+"'", buf.String())
|
||||
|
||||
buf.Reset()
|
||||
writeValue(&buf, tm)
|
||||
assert.Equal(t, "'"+tm.String()+"'", buf.String())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user