fix: 更新 GTime 和 Time 函数以支持 map[string]any 类型

This commit is contained in:
hailaz
2025-09-18 11:50:49 +08:00
parent aa48e7b829
commit e30fc761bf
2 changed files with 5 additions and 2 deletions

View File

@ -161,7 +161,7 @@ func (c *Converter) builtInAnyConvertFuncForGTime(from any, to reflect.Value) er
// CONVERSION PATH 2: Structured Data Value Extraction
// Theoretical basis: Extract semantic content from containers rather than
// serializing containers themselves, which loses semantic context
case map[string]interface{}:
case map[string]any:
// Common in ORM scenarios: {"column_name": gtime_value}
// Instead of converting entire map to string (lossy), extract the gtime value
if len(v) > 0 {

View File

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