Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
89c03870
Commit
89c03870
authored
Nov 01, 2013
by
slene
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
orm fix sqlite3 time convert
parent
1d440181
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
19 deletions
+35
-19
db.go
orm/db.go
+9
-18
db_utils.go
orm/db_utils.go
+26
-1
No files found.
orm/db.go
View file @
89c03870
...
...
@@ -97,11 +97,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
case
TypeDateField
,
TypeDateTimeField
:
value
=
field
.
Interface
()
if
t
,
ok
:=
value
.
(
time
.
Time
);
ok
{
if
fi
.
fieldType
==
TypeDateField
{
d
.
ins
.
TimeToDB
(
&
t
,
DefaultTimeLoc
)
}
else
{
d
.
ins
.
TimeToDB
(
&
t
,
tz
)
}
d
.
ins
.
TimeToDB
(
&
t
,
tz
)
value
=
t
}
default
:
...
...
@@ -130,11 +126,7 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
case
TypeDateField
,
TypeDateTimeField
:
if
fi
.
auto_now
||
fi
.
auto_now_add
&&
insert
{
tnow
:=
time
.
Now
()
if
fi
.
fieldType
==
TypeDateField
{
d
.
ins
.
TimeToDB
(
&
tnow
,
DefaultTimeLoc
)
}
else
{
d
.
ins
.
TimeToDB
(
&
tnow
,
tz
)
}
d
.
ins
.
TimeToDB
(
&
tnow
,
tz
)
value
=
tnow
if
fi
.
isFielder
{
f
:=
field
.
Addr
()
.
Interface
()
.
(
Fielder
)
...
...
@@ -895,18 +887,17 @@ setValue:
t
time
.
Time
err
error
)
if
fi
.
fieldType
==
TypeDateField
{
if
len
(
s
)
>=
19
{
s
=
s
[
:
19
]
t
,
err
=
time
.
ParseInLocation
(
format_DateTime
,
s
,
tz
)
}
else
{
if
len
(
s
)
>
10
{
s
=
s
[
:
10
]
}
t
,
err
=
time
.
ParseInLocation
(
format_Date
,
s
,
DefaultTimeLoc
)
}
else
{
if
len
(
s
)
>
19
{
s
=
s
[
:
19
]
}
t
,
err
=
time
.
ParseInLocation
(
format_DateTime
,
s
,
tz
)
t
=
t
.
In
(
DefaultTimeLoc
)
t
,
err
=
time
.
ParseInLocation
(
format_Date
,
s
,
tz
)
}
t
=
t
.
In
(
DefaultTimeLoc
)
if
err
!=
nil
&&
s
!=
"0000-00-00"
&&
s
!=
"0000-00-00 00:00:00"
{
tErr
=
err
goto
end
...
...
orm/db_utils.go
View file @
89c03870
...
...
@@ -50,9 +50,34 @@ outFor:
switch
v
:=
arg
.
(
type
)
{
case
[]
byte
:
case
string
:
if
fi
!=
nil
{
if
fi
.
fieldType
==
TypeDateField
||
fi
.
fieldType
==
TypeDateTimeField
{
var
t
time
.
Time
var
err
error
if
len
(
v
)
>=
19
{
s
:=
v
[
:
19
]
t
,
err
=
time
.
ParseInLocation
(
format_DateTime
,
s
,
DefaultTimeLoc
)
}
else
{
s
:=
v
if
len
(
v
)
>
10
{
s
=
v
[
:
10
]
}
t
,
err
=
time
.
ParseInLocation
(
format_Date
,
s
,
DefaultTimeLoc
)
}
if
err
==
nil
{
if
fi
.
fieldType
==
TypeDateField
{
v
=
t
.
In
(
tz
)
.
Format
(
format_Date
)
}
else
{
v
=
t
.
In
(
tz
)
.
Format
(
format_DateTime
)
}
}
}
}
arg
=
v
case
time
.
Time
:
if
fi
!=
nil
&&
fi
.
fieldType
==
TypeDateField
{
arg
=
v
.
In
(
DefaultTimeLoc
)
.
Format
(
format_Date
)
arg
=
v
.
In
(
tz
)
.
Format
(
format_Date
)
}
else
{
arg
=
v
.
In
(
tz
)
.
Format
(
format_DateTime
)
}
...
...
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