Skip to content

Commit e30fc76

Browse files
committed
fix: 更新 GTime 和 Time 函数以支持 map[string]any 类型
1 parent aa48e7b commit e30fc76

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

util/gconv/internal/converter/converter_builtin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (c *Converter) builtInAnyConvertFuncForGTime(from any, to reflect.Value) er
161161
// CONVERSION PATH 2: Structured Data Value Extraction
162162
// Theoretical basis: Extract semantic content from containers rather than
163163
// serializing containers themselves, which loses semantic context
164-
case map[string]interface{}:
164+
case map[string]any:
165165
// Common in ORM scenarios: {"column_name": gtime_value}
166166
// Instead of converting entire map to string (lossy), extract the gtime value
167167
if len(v) > 0 {

util/gconv/internal/converter/converter_time.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ func (c *Converter) Time(anyInput any, format ...string) (time.Time, error) {
3434
// Handle map inputs by extracting the first value
3535
// This is optimized for ORM scenarios where maps like {"now": gtimeVal}
3636
// need to be converted to a single time.Time value
37-
if mapData, ok := anyInput.(map[string]interface{}); ok {
37+
// If anyInput is a map with string keys, this block accesses its data directly.
38+
// Timezone preservation is ensured by accessing the v.Time field directly,
39+
// rather than converting time values to strings, which could lose timezone information.
40+
if mapData, ok := anyInput.(map[string]any); ok {
3841
if len(mapData) == 0 {
3942
return time.Time{}, nil
4043
}

0 commit comments

Comments
 (0)