mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:30:56 +00:00
Merge pull request #4190 from flycash/ftr/time-precision
Support precision
This commit is contained in:
commit
14c911e9d7
@ -1355,7 +1355,14 @@ setValue:
|
|||||||
t time.Time
|
t time.Time
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
if len(s) >= 19 {
|
|
||||||
|
if fi.timePrecision != nil && len(s) >= (20+*fi.timePrecision) {
|
||||||
|
layout := formatDateTime + "."
|
||||||
|
for i := 0; i < *fi.timePrecision; i++ {
|
||||||
|
layout += "0"
|
||||||
|
}
|
||||||
|
t, err = time.ParseInLocation(layout, s[:20+*fi.timePrecision], tz)
|
||||||
|
} else if len(s) >= 19 {
|
||||||
s = s[:19]
|
s = s[:19]
|
||||||
t, err = time.ParseInLocation(formatDateTime, s, tz)
|
t, err = time.ParseInLocation(formatDateTime, s, tz)
|
||||||
} else if len(s) >= 10 {
|
} else if len(s) >= 10 {
|
||||||
|
@ -52,6 +52,7 @@ var sqliteTypes = map[string]string{
|
|||||||
"string-text": "text",
|
"string-text": "text",
|
||||||
"time.Time-date": "date",
|
"time.Time-date": "date",
|
||||||
"time.Time": "datetime",
|
"time.Time": "datetime",
|
||||||
|
"time.Time-precision": "datetime(%d)",
|
||||||
"int8": "tinyint",
|
"int8": "tinyint",
|
||||||
"int16": "smallint",
|
"int16": "smallint",
|
||||||
"int32": "integer",
|
"int32": "integer",
|
||||||
|
@ -154,6 +154,7 @@ type DataNull struct {
|
|||||||
Time time.Time `orm:"null;type(time)"`
|
Time time.Time `orm:"null;type(time)"`
|
||||||
Date time.Time `orm:"null;type(date)"`
|
Date time.Time `orm:"null;type(date)"`
|
||||||
DateTime time.Time `orm:"null;column(datetime)"`
|
DateTime time.Time `orm:"null;column(datetime)"`
|
||||||
|
DateTimePrecision time.Time `orm:"null;type(datetime);precision(4)"`
|
||||||
Byte byte `orm:"null"`
|
Byte byte `orm:"null"`
|
||||||
Rune rune `orm:"null"`
|
Rune rune `orm:"null"`
|
||||||
Int int `orm:"null"`
|
Int int `orm:"null"`
|
||||||
@ -303,6 +304,7 @@ type Post struct {
|
|||||||
Content string `orm:"type(text)"`
|
Content string `orm:"type(text)"`
|
||||||
Created time.Time `orm:"auto_now_add"`
|
Created time.Time `orm:"auto_now_add"`
|
||||||
Updated time.Time `orm:"auto_now"`
|
Updated time.Time `orm:"auto_now"`
|
||||||
|
UpdatedPrecision time.Time `orm:"auto_now;type(datetime);precision(4)"`
|
||||||
Tags []*Tag `orm:"rel(m2m);rel_through(github.com/astaxie/beego/pkg/client/orm.PostTags)"`
|
Tags []*Tag `orm:"rel(m2m);rel_through(github.com/astaxie/beego/pkg/client/orm.PostTags)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +506,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Debug, _ = StrTo(DBARGS.Debug).Bool()
|
// Debug, _ = StrTo(DBARGS.Debug).Bool()
|
||||||
|
Debug = true
|
||||||
|
|
||||||
if DBARGS.Driver == "" || DBARGS.Source == "" {
|
if DBARGS.Driver == "" || DBARGS.Source == "" {
|
||||||
fmt.Println(helpinfo)
|
fmt.Println(helpinfo)
|
||||||
|
Loading…
Reference in New Issue
Block a user