Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gosqlite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gosqlite
Commits
7dba26ee
Commit
7dba26ee
authored
Feb 01, 2014
by
gwenn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix time formats such as the result text length is constant.
parent
c1a7a38c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
9 deletions
+9
-9
date.go
date.go
+3
-3
sqlite.go
sqlite.go
+2
-2
stmt.go
stmt.go
+4
-4
No files found.
date.go
View file @
7dba26ee
...
...
@@ -84,7 +84,7 @@ func (t JulianTime) Value() (driver.Value, error) {
return
JulianDay
((
time
.
Time
)(
t
)),
nil
}
// TimeStamp is an alias used to persist time as '2006-01-02T15:04:05.
999
Z07:00' string
// TimeStamp is an alias used to persist time as '2006-01-02T15:04:05.
000
Z07:00' string
type
TimeStamp
time
.
Time
// Scan implements the database/sql/Scanner interface.
...
...
@@ -93,7 +93,7 @@ func (t *TimeStamp) Scan(src interface{}) error {
//t = nil
return
nil
}
else
if
txt
,
ok
:=
src
.
(
string
);
ok
{
v
,
err
:=
time
.
Parse
(
"2006-01-02T15:04:05.
999
Z07:00"
,
txt
)
v
,
err
:=
time
.
Parse
(
"2006-01-02T15:04:05.
000
Z07:00"
,
txt
)
if
err
!=
nil
{
return
err
}
...
...
@@ -108,5 +108,5 @@ func (t TimeStamp) Value() (driver.Value, error) {
if
(
time
.
Time
)(
t
)
.
IsZero
()
{
return
nil
,
nil
}
return
(
time
.
Time
)(
t
)
.
Format
(
"2006-01-02T15:04:05.
999
Z07:00"
),
nil
return
(
time
.
Time
)(
t
)
.
Format
(
"2006-01-02T15:04:05.
000
Z07:00"
),
nil
}
sqlite.go
View file @
7dba26ee
...
...
@@ -156,7 +156,7 @@ type Conn struct {
modules
map
[
string
]
*
sqliteModule
timeUsed
time
.
Time
nTransaction
uint8
// DefaultTimeLayout specifies the layout used to persist time ("2006-01-02 15:04:05.
999
Z07:00" by default).
// DefaultTimeLayout specifies the layout used to persist time ("2006-01-02 15:04:05.
000
Z07:00" by default).
// Using type alias implementing the Scanner/Valuer interfaces is suggested...
DefaultTimeLayout
string
// 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)
if
db
==
nil
{
return
nil
,
errors
.
New
(
"sqlite succeeded without returning a database"
)
}
c
:=
&
Conn
{
db
:
db
,
stmtCache
:
newCache
(),
DefaultTimeLayout
:
"2006-01-02 15:04:05.
999
Z07:00"
}
c
:=
&
Conn
{
db
:
db
,
stmtCache
:
newCache
(),
DefaultTimeLayout
:
"2006-01-02 15:04:05.
000
Z07:00"
}
if
os
.
Getenv
(
"SQLITE_DEBUG"
)
!=
""
{
c
.
SetAuthorizer
(
authorizer
,
c
.
db
)
c
.
SetCacheSize
(
0
)
...
...
stmt.go
View file @
7dba26ee
...
...
@@ -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
if
txt
[
10
]
==
'T'
{
layout
=
"2006-01-02T15:04:05.
999
"
layout
=
"2006-01-02T15:04:05.
000
"
}
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
if
len
(
txt
)
>
10
&&
txt
[
10
]
==
'T'
{
layout
=
"2006-01-02T15:04:05.
999
Z07:00"
layout
=
"2006-01-02T15:04:05.
000
Z07:00"
}
else
{
layout
=
"2006-01-02 15:04:05.
999
Z07:00"
layout
=
"2006-01-02 15:04:05.
000
Z07:00"
}
}
value
,
err
=
time
.
Parse
(
layout
,
txt
)
// UTC except when timezone is specified
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment