diff --git a/helpers.go b/helpers.go index 9e56ae4c..a0e894e0 100644 --- a/helpers.go +++ b/helpers.go @@ -286,7 +286,7 @@ func setColumnTime(bean interface{}, col *core.Column, t time.Time) { if v.CanSet() { switch v.Type().Kind() { case reflect.Struct: - v.Set(reflect.ValueOf(t)) + v.Set(reflect.ValueOf(t).Convert(v.Type())) case reflect.Int, reflect.Int64, reflect.Int32: v.SetInt(t.Unix()) case reflect.Uint, reflect.Uint64, reflect.Uint32: diff --git a/session.go b/session.go index 671d55fe..cf566902 100644 --- a/session.go +++ b/session.go @@ -1671,11 +1671,11 @@ func (session *Session) _row2Bean(rows *core.Rows, fields []string, fieldsCount fieldValue.SetUint(uint64(vv.Int())) } case reflect.Struct: - if fieldType == core.TimeType { + if fieldType.ConvertibleTo(core.TimeType) { if rawValueType == core.TimeType { hasAssigned = true - t := vv.Interface().(time.Time) + t := vv.Convert(core.TimeType).Interface().(time.Time) z, _ := t.Zone() if len(z) == 0 || t.Year() == 0 { // !nashtsai! HACK tmp work around for lib/pq doesn't properly time with location session.Engine.LogDebug("empty zone key[%v] : %v | zone: %v | location: %+v\n", key, t, z, *t.Location()) @@ -1684,7 +1684,7 @@ func (session *Session) _row2Bean(rows *core.Rows, fields []string, fieldsCount vv = reflect.ValueOf(tt) } // !nashtsai! convert to engine location - t = vv.Interface().(time.Time).In(session.Engine.TZLocation) + t = vv.Convert(core.TimeType).Interface().(time.Time).In(session.Engine.TZLocation) vv = reflect.ValueOf(t) fieldValue.Set(vv) @@ -2360,13 +2360,13 @@ func (session *Session) bytes2Value(col *core.Column, fieldValue *reflect.Value, fieldValue.SetUint(x) //Currently only support Time type case reflect.Struct: - if fieldType == core.TimeType { + if fieldType.ConvertibleTo(core.TimeType) { x, err := session.byte2Time(col, data) if err != nil { return err } v = x - fieldValue.Set(reflect.ValueOf(v)) + fieldValue.Set(reflect.ValueOf(v).Convert(fieldType)) } else if session.Statement.UseCascade { table := session.Engine.autoMapType(*fieldValue) if table != nil { diff --git a/statement.go b/statement.go index 75501f40..f645a1d3 100644 --- a/statement.go +++ b/statement.go @@ -583,8 +583,8 @@ func buildConditions(engine *Engine, table *core.Table, bean interface{}, t := int64(fieldValue.Uint()) val = reflect.ValueOf(&t).Interface() case reflect.Struct: - if fieldType == reflect.TypeOf(time.Now()) { - t := fieldValue.Interface().(time.Time) + if fieldType.ConvertibleTo(core.TimeType) { + t := fieldValue.Convert(core.TimeType).Interface().(time.Time) if !requiredField && (t.IsZero() || !fieldValue.IsValid()) { continue }