commit
41e3d14f20
22
engine.go
22
engine.go
|
@ -1086,13 +1086,25 @@ func (engine *Engine) TZTime(t time.Time) (r time.Time) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) NowTime(SQLTypeName string) interface{} {
|
func (engine *Engine) TZLocation() (r *time.Location) {
|
||||||
t := time.Now()
|
switch engine.TimeZone {
|
||||||
return engine.FormatTime(SQLTypeName, t)
|
case "Local", "L":
|
||||||
|
r = time.Local
|
||||||
|
case "UTC", "U":
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
|
r = time.UTC
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (engine *Engine) FormatTime(SQLTypeName string, t time.Time) (v interface{}) {
|
func (engine *Engine) NowTime(sqlTypeName string) interface{} {
|
||||||
switch SQLTypeName {
|
t := time.Now()
|
||||||
|
return engine.FormatTime(sqlTypeName, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (engine *Engine) FormatTime(sqlTypeName string, t time.Time) (v interface{}) {
|
||||||
|
switch sqlTypeName {
|
||||||
case Time:
|
case Time:
|
||||||
s := engine.TZTime(t).Format("2006-01-02 15:04:05") //time.RFC3339
|
s := engine.TZTime(t).Format("2006-01-02 15:04:05") //time.RFC3339
|
||||||
v = s[11:19]
|
v = s[11:19]
|
||||||
|
|
18
session.go
18
session.go
|
@ -1930,17 +1930,17 @@ func (session *Session) byte2Time(col *Column, data []byte) (outTime time.Time,
|
||||||
x = time.Unix(0, sd)
|
x = time.Unix(0, sd)
|
||||||
}
|
}
|
||||||
} else if len(sdata) > 19 {
|
} else if len(sdata) > 19 {
|
||||||
x, err = time.Parse(time.RFC3339Nano, sdata)
|
x, err = time.ParseInLocation(time.RFC3339Nano, sdata, session.Engine.TZLocation())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
x, err = time.Parse("2006-01-02 15:04:05.999999999", sdata)
|
x, err = time.ParseInLocation("2006-01-02 15:04:05.999999999", sdata, session.Engine.TZLocation())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
x, err = time.Parse("2006-01-02 15:04:05.9999999 Z07:00", sdata)
|
x, err = time.ParseInLocation("2006-01-02 15:04:05.9999999 Z07:00", sdata, session.Engine.TZLocation())
|
||||||
}
|
}
|
||||||
} else if len(sdata) == 19 {
|
} else if len(sdata) == 19 {
|
||||||
x, err = time.Parse("2006-01-02 15:04:05", sdata)
|
x, err = time.ParseInLocation("2006-01-02 15:04:05", sdata, session.Engine.TZLocation())
|
||||||
} else if len(sdata) == 10 && sdata[4] == '-' && sdata[7] == '-' {
|
} else if len(sdata) == 10 && sdata[4] == '-' && sdata[7] == '-' {
|
||||||
x, err = time.Parse("2006-01-02", sdata)
|
x, err = time.ParseInLocation("2006-01-02", sdata, session.Engine.TZLocation())
|
||||||
} else if col.SQLType.Name == Time {
|
} else if col.SQLType.Name == Time {
|
||||||
if strings.Contains(sdata, " ") {
|
if strings.Contains(sdata, " ") {
|
||||||
ssd := strings.Split(sdata, " ")
|
ssd := strings.Split(sdata, " ")
|
||||||
|
@ -1955,7 +1955,7 @@ func (session *Session) byte2Time(col *Column, data []byte) (outTime time.Time,
|
||||||
//fmt.Println(sdata)
|
//fmt.Println(sdata)
|
||||||
|
|
||||||
st := fmt.Sprintf("2006-01-02 %v", sdata)
|
st := fmt.Sprintf("2006-01-02 %v", sdata)
|
||||||
x, err = time.Parse("2006-01-02 15:04:05", st)
|
x, err = time.ParseInLocation("2006-01-02 15:04:05", st, session.Engine.TZLocation())
|
||||||
} else {
|
} else {
|
||||||
outErr = errors.New(fmt.Sprintf("unsupported time format %v", sdata))
|
outErr = errors.New(fmt.Sprintf("unsupported time format %v", sdata))
|
||||||
return
|
return
|
||||||
|
@ -2402,10 +2402,10 @@ func (session *Session) value2Interface(col *Column, fieldValue reflect.Value) (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch fieldValue.Interface().(type) {
|
switch fieldValue.Interface().(type) {
|
||||||
case time.Time:
|
case time.Time:
|
||||||
tf := session.Engine.FormatTime(col.SQLType.Name,fieldValue.Interface().(time.Time))
|
tf := session.Engine.FormatTime(col.SQLType.Name, fieldValue.Interface().(time.Time))
|
||||||
return tf, nil
|
return tf, nil
|
||||||
default:
|
default:
|
||||||
return fieldValue.Interface(), nil
|
return fieldValue.Interface(), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
xorm.go
2
xorm.go
|
@ -24,7 +24,7 @@ func NewEngine(driverName string, dataSourceName string) (*Engine, error) {
|
||||||
DriverName: driverName,
|
DriverName: driverName,
|
||||||
DataSourceName: dataSourceName,
|
DataSourceName: dataSourceName,
|
||||||
Filters: make([]Filter, 0),
|
Filters: make([]Filter, 0),
|
||||||
TimeZone: "UTC",
|
TimeZone: "Local",
|
||||||
}
|
}
|
||||||
engine.SetMapper(SnakeMapper{})
|
engine.SetMapper(SnakeMapper{})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue