Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
94b85828
Commit
94b85828
authored
Apr 10, 2012
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add DateTime support to database binding layer.
Signed-off-by:
Taylor Otwell
<
taylorotwell@gmail.com
>
parent
7d5b6b37
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
15 deletions
+32
-15
connection.php
laravel/database/connection.php
+13
-0
model.php
laravel/database/eloquent/model.php
+2
-12
has_many_and_belongs_to.php
...tabase/eloquent/relationships/has_many_and_belongs_to.php
+1
-1
has_one_or_many.php
laravel/database/eloquent/relationships/has_one_or_many.php
+1
-1
grammar.php
laravel/database/query/grammars/grammar.php
+7
-0
sqlserver.php
laravel/database/query/grammars/sqlserver.php
+7
-0
postgres.php
laravel/database/schema/grammars/postgres.php
+1
-1
No files found.
laravel/database/connection.php
View file @
94b85828
...
...
@@ -209,6 +209,19 @@ class Connection {
$sql
=
$this
->
grammar
()
->
shortcut
(
$sql
,
$bindings
);
// Next we need to translate all DateTime bindings to their date-time
// strings that are compatible with the database. Each grammar may
// define it's own date-time format according to its needs.
$datetime
=
$this
->
grammar
()
->
datetime
;
for
(
$i
=
0
;
$i
<
count
(
$bindings
);
$i
++
)
{
if
(
$bindings
[
$i
]
instanceof
\DateTime
)
{
$bindings
[
$i
]
=
$bindings
[
$i
]
->
format
(
$datetime
);
}
}
// Each database operation is wrapped in a try / catch so we can wrap
// any database exceptions in our custom exception class, which will
// set the message to include the SQL and query bindings.
...
...
laravel/database/eloquent/model.php
View file @
94b85828
...
...
@@ -193,7 +193,7 @@ abstract class Model {
{
$model
=
new
static
(
array
(),
true
);
if
(
static
::
$timestamps
)
$attributes
[
'updated_at'
]
=
$model
->
get_timestamp
()
;
if
(
static
::
$timestamps
)
$attributes
[
'updated_at'
]
=
new
\DateTime
;
return
$model
->
query
()
->
where
(
$model
->
key
(),
'='
,
$id
)
->
update
(
$attributes
);
}
...
...
@@ -405,21 +405,11 @@ abstract class Model {
*/
protected
function
timestamp
()
{
$this
->
updated_at
=
static
::
get_timestamp
()
;
$this
->
updated_at
=
new
\DateTime
;
if
(
!
$this
->
exists
)
$this
->
created_at
=
$this
->
updated_at
;
}
/**
* Get the current timestamp in its storable form.
*
* @return mixed
*/
public
static
function
get_timestamp
()
{
return
date
(
'Y-m-d H:i:s'
);
}
/**
* Get a new fluent query builder instance for the model.
*
...
...
laravel/database/eloquent/relationships/has_many_and_belongs_to.php
View file @
94b85828
...
...
@@ -204,7 +204,7 @@ class Has_Many_And_Belongs_To extends Relationship {
{
if
(
Pivot
::
$timestamps
)
{
$attributes
[
'created_at'
]
=
$this
->
model
->
get_timestamp
()
;
$attributes
[
'created_at'
]
=
new
\DateTime
;
$attributes
[
'updated_at'
]
=
$attributes
[
'created_at'
];
}
...
...
laravel/database/eloquent/relationships/has_one_or_many.php
View file @
94b85828
...
...
@@ -29,7 +29,7 @@ class Has_One_Or_Many extends Relationship {
{
if
(
$this
->
model
->
timestamps
())
{
$attributes
[
'updated_at'
]
=
$this
->
model
->
get_timestamp
()
;
$attributes
[
'updated_at'
]
=
new
\DateTime
;
}
return
$this
->
table
->
update
(
$attributes
);
...
...
laravel/database/query/grammars/grammar.php
View file @
94b85828
...
...
@@ -5,6 +5,13 @@ use Laravel\Database\Expression;
class
Grammar
extends
\Laravel\Database\Grammar
{
/**
* The format for properly saving a DateTime.
*
* @var string
*/
public
$datetime
=
'Y-m-d H:i:s'
;
/**
* All of the query componenets in the order they should be built.
*
...
...
laravel/database/query/grammars/sqlserver.php
View file @
94b85828
...
...
@@ -11,6 +11,13 @@ class SQLServer extends Grammar {
*/
protected
$wrapper
=
'[%s]'
;
/**
* The format for properly saving a DateTime.
*
* @var string
*/
public
$datetime
=
'Y-m-d H:i:s.000'
;
/**
* Compile a SQL SELECT statement from a Query instance.
*
...
...
laravel/database/schema/grammars/postgres.php
View file @
94b85828
...
...
@@ -368,7 +368,7 @@ class Postgres extends Grammar {
*/
protected
function
type_date
(
Fluent
$column
)
{
return
'TIMESTAMP'
;
return
'TIMESTAMP
(0) WITHOUT TIME ZONE
'
;
}
/**
...
...
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