89c03870 by slene

orm fix sqlite3 time convert

1 parent 1d440181
...@@ -97,11 +97,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val ...@@ -97,11 +97,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
97 case TypeDateField, TypeDateTimeField: 97 case TypeDateField, TypeDateTimeField:
98 value = field.Interface() 98 value = field.Interface()
99 if t, ok := value.(time.Time); ok { 99 if t, ok := value.(time.Time); ok {
100 if fi.fieldType == TypeDateField {
101 d.ins.TimeToDB(&t, DefaultTimeLoc)
102 } else {
103 d.ins.TimeToDB(&t, tz) 100 d.ins.TimeToDB(&t, tz)
104 }
105 value = t 101 value = t
106 } 102 }
107 default: 103 default:
...@@ -130,11 +126,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val ...@@ -130,11 +126,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
130 case TypeDateField, TypeDateTimeField: 126 case TypeDateField, TypeDateTimeField:
131 if fi.auto_now || fi.auto_now_add && insert { 127 if fi.auto_now || fi.auto_now_add && insert {
132 tnow := time.Now() 128 tnow := time.Now()
133 if fi.fieldType == TypeDateField {
134 d.ins.TimeToDB(&tnow, DefaultTimeLoc)
135 } else {
136 d.ins.TimeToDB(&tnow, tz) 129 d.ins.TimeToDB(&tnow, tz)
137 }
138 value = tnow 130 value = tnow
139 if fi.isFielder { 131 if fi.isFielder {
140 f := field.Addr().Interface().(Fielder) 132 f := field.Addr().Interface().(Fielder)
...@@ -895,18 +887,17 @@ setValue: ...@@ -895,18 +887,17 @@ setValue:
895 t time.Time 887 t time.Time
896 err error 888 err error
897 ) 889 )
898 if fi.fieldType == TypeDateField { 890 if len(s) >= 19 {
891 s = s[:19]
892 t, err = time.ParseInLocation(format_DateTime, s, tz)
893 } else {
899 if len(s) > 10 { 894 if len(s) > 10 {
900 s = s[:10] 895 s = s[:10]
901 } 896 }
902 t, err = time.ParseInLocation(format_Date, s, DefaultTimeLoc) 897 t, err = time.ParseInLocation(format_Date, s, tz)
903 } else {
904 if len(s) > 19 {
905 s = s[:19]
906 } 898 }
907 t, err = time.ParseInLocation(format_DateTime, s, tz)
908 t = t.In(DefaultTimeLoc) 899 t = t.In(DefaultTimeLoc)
909 } 900
910 if err != nil && s != "0000-00-00" && s != "0000-00-00 00:00:00" { 901 if err != nil && s != "0000-00-00" && s != "0000-00-00 00:00:00" {
911 tErr = err 902 tErr = err
912 goto end 903 goto end
......
...@@ -50,9 +50,34 @@ outFor: ...@@ -50,9 +50,34 @@ outFor:
50 50
51 switch v := arg.(type) { 51 switch v := arg.(type) {
52 case []byte: 52 case []byte:
53 case string:
54 if fi != nil {
55 if fi.fieldType == TypeDateField || fi.fieldType == TypeDateTimeField {
56 var t time.Time
57 var err error
58 if len(v) >= 19 {
59 s := v[:19]
60 t, err = time.ParseInLocation(format_DateTime, s, DefaultTimeLoc)
61 } else {
62 s := v
63 if len(v) > 10 {
64 s = v[:10]
65 }
66 t, err = time.ParseInLocation(format_Date, s, DefaultTimeLoc)
67 }
68 if err == nil {
69 if fi.fieldType == TypeDateField {
70 v = t.In(tz).Format(format_Date)
71 } else {
72 v = t.In(tz).Format(format_DateTime)
73 }
74 }
75 }
76 }
77 arg = v
53 case time.Time: 78 case time.Time:
54 if fi != nil && fi.fieldType == TypeDateField { 79 if fi != nil && fi.fieldType == TypeDateField {
55 arg = v.In(DefaultTimeLoc).Format(format_Date) 80 arg = v.In(tz).Format(format_Date)
56 } else { 81 } else {
57 arg = v.In(tz).Format(format_DateTime) 82 arg = v.In(tz).Format(format_DateTime)
58 } 83 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!