Commit 7dba26ee authored by gwenn's avatar gwenn

Fix time formats such as the result text length is constant.

parent c1a7a38c
...@@ -84,7 +84,7 @@ func (t JulianTime) Value() (driver.Value, error) { ...@@ -84,7 +84,7 @@ func (t JulianTime) Value() (driver.Value, error) {
return JulianDay((time.Time)(t)), nil return JulianDay((time.Time)(t)), nil
} }
// TimeStamp is an alias used to persist time as '2006-01-02T15:04:05.999Z07:00' string // TimeStamp is an alias used to persist time as '2006-01-02T15:04:05.000Z07:00' string
type TimeStamp time.Time type TimeStamp time.Time
// Scan implements the database/sql/Scanner interface. // Scan implements the database/sql/Scanner interface.
...@@ -93,7 +93,7 @@ func (t *TimeStamp) Scan(src interface{}) error { ...@@ -93,7 +93,7 @@ func (t *TimeStamp) Scan(src interface{}) error {
//t = nil //t = nil
return nil return nil
} else if txt, ok := src.(string); ok { } else if txt, ok := src.(string); ok {
v, err := time.Parse("2006-01-02T15:04:05.999Z07:00", txt) v, err := time.Parse("2006-01-02T15:04:05.000Z07:00", txt)
if err != nil { if err != nil {
return err return err
} }
...@@ -108,5 +108,5 @@ func (t TimeStamp) Value() (driver.Value, error) { ...@@ -108,5 +108,5 @@ func (t TimeStamp) Value() (driver.Value, error) {
if (time.Time)(t).IsZero() { if (time.Time)(t).IsZero() {
return nil, nil return nil, nil
} }
return (time.Time)(t).Format("2006-01-02T15:04:05.999Z07:00"), nil return (time.Time)(t).Format("2006-01-02T15:04:05.000Z07:00"), nil
} }
...@@ -156,7 +156,7 @@ type Conn struct { ...@@ -156,7 +156,7 @@ type Conn struct {
modules map[string]*sqliteModule modules map[string]*sqliteModule
timeUsed time.Time timeUsed time.Time
nTransaction uint8 nTransaction uint8
// DefaultTimeLayout specifies the layout used to persist time ("2006-01-02 15:04:05.999Z07:00" by default). // DefaultTimeLayout specifies the layout used to persist time ("2006-01-02 15:04:05.000Z07:00" by default).
// Using type alias implementing the Scanner/Valuer interfaces is suggested... // Using type alias implementing the Scanner/Valuer interfaces is suggested...
DefaultTimeLayout string DefaultTimeLayout string
// ScanNumericalAsTime tells the driver to try to parse column with NUMERIC affinity as time.Time (using the DefaultTimeLayout) // ScanNumericalAsTime tells the driver to try to parse column with NUMERIC affinity as time.Time (using the DefaultTimeLayout)
...@@ -225,7 +225,7 @@ func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error) ...@@ -225,7 +225,7 @@ func OpenVfs(filename string, vfsname string, flags ...OpenFlag) (*Conn, error)
if db == nil { if db == nil {
return nil, errors.New("sqlite succeeded without returning a database") return nil, errors.New("sqlite succeeded without returning a database")
} }
c := &Conn{db: db, stmtCache: newCache(), DefaultTimeLayout: "2006-01-02 15:04:05.999Z07:00"} c := &Conn{db: db, stmtCache: newCache(), DefaultTimeLayout: "2006-01-02 15:04:05.000Z07:00"}
if os.Getenv("SQLITE_DEBUG") != "" { if os.Getenv("SQLITE_DEBUG") != "" {
c.SetAuthorizer(authorizer, c.db) c.SetAuthorizer(authorizer, c.db)
c.SetCacheSize(0) c.SetCacheSize(0)
......
...@@ -1073,15 +1073,15 @@ func (s *Stmt) ScanTime(index int) (value time.Time, isNull bool, err error) { ...@@ -1073,15 +1073,15 @@ func (s *Stmt) ScanTime(index int) (value time.Time, isNull bool, err error) {
} }
case 23: // YYYY-MM-DDTHH:MM:SS.SSS case 23: // YYYY-MM-DDTHH:MM:SS.SSS
if txt[10] == 'T' { if txt[10] == 'T' {
layout = "2006-01-02T15:04:05.999" layout = "2006-01-02T15:04:05.000"
} else { } else {
layout = "2006-01-02 15:04:05.999" layout = "2006-01-02 15:04:05.000"
} }
default: // YYYY-MM-DDTHH:MM:SS.SSSZhh:mm or parse error default: // YYYY-MM-DDTHH:MM:SS.SSSZhh:mm or parse error
if len(txt) > 10 && txt[10] == 'T' { if len(txt) > 10 && txt[10] == 'T' {
layout = "2006-01-02T15:04:05.999Z07:00" layout = "2006-01-02T15:04:05.000Z07:00"
} else { } else {
layout = "2006-01-02 15:04:05.999Z07:00" layout = "2006-01-02 15:04:05.000Z07:00"
} }
} }
value, err = time.Parse(layout, txt) // UTC except when timezone is specified value, err = time.Parse(layout, txt) // UTC except when timezone is specified
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment