Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
8906f736
Commit
8906f736
authored
Jul 02, 2017
by
Marco Pivetta
Committed by
GitHub
Jul 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2316 from vbartusevicius/issue-2314
Fix date interval database value truncation (string overflow)
parents
93488498
9ca48dc3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
9 deletions
+7
-9
DateIntervalType.php
lib/Doctrine/DBAL/Types/DateIntervalType.php
+4
-6
DateIntervalTest.php
tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php
+3
-3
No files found.
lib/Doctrine/DBAL/Types/DateIntervalType.php
View file @
8906f736
...
...
@@ -22,7 +22,7 @@ class DateIntervalType extends Type
*/
public
function
getSQLDeclaration
(
array
$fieldDeclaration
,
AbstractPlatform
$platform
)
{
$fieldDeclaration
[
'length'
]
=
2
0
;
$fieldDeclaration
[
'length'
]
=
2
55
;
$fieldDeclaration
[
'fixed'
]
=
true
;
return
$platform
->
getVarcharTypeDeclarationSQL
(
$fieldDeclaration
);
...
...
@@ -38,9 +38,7 @@ class DateIntervalType extends Type
}
if
(
$value
instanceof
\DateInterval
)
{
return
'P'
.
str_pad
(
$value
->
y
,
4
,
'0'
,
STR_PAD_LEFT
)
.
'-'
.
$value
->
format
(
'%M-%DT%H:%I:%S'
);
return
$value
->
format
(
'P%YY%MM%DDT%HH%IM%SS'
);
}
throw
ConversionException
::
conversionFailedInvalidType
(
$value
,
$this
->
getName
(),
[
'null'
,
'DateInterval'
]);
...
...
@@ -58,7 +56,7 @@ class DateIntervalType extends Type
try
{
return
new
\DateInterval
(
$value
);
}
catch
(
\Exception
$exception
)
{
throw
ConversionException
::
conversionFailedFormat
(
$value
,
$this
->
getName
(),
'P
Y-m-dTH:i:s
'
,
$exception
);
throw
ConversionException
::
conversionFailedFormat
(
$value
,
$this
->
getName
(),
'P
%YY%MM%DDT%HH%IM%SS
'
,
$exception
);
}
}
...
...
tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php
View file @
8906f736
...
...
@@ -32,7 +32,7 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
{
$interval
=
new
\DateInterval
(
'P2Y1DT1H2M3S'
);
$expected
=
'P0
002-00-01T01:02:03
'
;
$expected
=
'P0
2Y00M01DT01H02M03S
'
;
$actual
=
$this
->
type
->
convertToDatabaseValue
(
$interval
,
$this
->
platform
);
$this
->
assertEquals
(
$expected
,
$actual
);
...
...
@@ -40,9 +40,9 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
public
function
testDateIntervalConvertsToPHPValue
()
{
$date
=
$this
->
type
->
convertToPHPValue
(
'P0
002-00-01T01:02:03
'
,
$this
->
platform
);
$date
=
$this
->
type
->
convertToPHPValue
(
'P0
2Y00M01DT01H02M03S
'
,
$this
->
platform
);
$this
->
assertInstanceOf
(
'DateInterval'
,
$date
);
$this
->
assertEquals
(
'P
2Y0M1DT1H2M3S'
,
$date
->
format
(
'P%yY%mM%dDT%hH%iM%s
S'
));
$this
->
assertEquals
(
'P
02Y00M01DT01H02M03S'
,
$date
->
format
(
'P%YY%MM%DDT%HH%IM%S
S'
));
}
public
function
testInvalidDateIntervalFormatConversion
()
...
...
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