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
835c9a03
Commit
835c9a03
authored
Jul 24, 2010
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DBAL-33'
parents
67947934
a1e4c86b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
1 deletion
+124
-1
PostgreSqlPlatform.php
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
+1
-1
VarDateTimeType.php
lib/Doctrine/DBAL/Types/VarDateTimeType.php
+60
-0
AllTests.php
tests/Doctrine/Tests/DBAL/AllTests.php
+1
-0
VarDateTimeTest.php
tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php
+62
-0
No files found.
lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
View file @
835c9a03
...
...
@@ -559,7 +559,7 @@ class PostgreSqlPlatform extends AbstractPlatform
*/
public
function
getTimeTypeDeclarationSQL
(
array
$fieldDeclaration
)
{
return
'TIME'
;
return
'TIME
(0) WITHOUT TIME ZONE
'
;
}
/**
...
...
lib/Doctrine/DBAL/Types/VarDateTimeType.php
0 → 100644
View file @
835c9a03
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace
Doctrine\DBAL\Types
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
/**
* Variable DateTime Type using date_create() instead of DateTime::createFromFormat()
*
* This type has performance implications as it runs twice as long as the regular
* {@see DateTimeType}, however in certain PostgreSQL configurations with
* TIMESTAMP(n) columns where n > 0 it is necessary to use this type.
*
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.doctrine-project.com
* @since 2.0
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
class
VarDateTimeType
extends
DateTimeType
{
/**
* @throws ConversionException
* @param string $value
* @param AbstractPlatform $platform
* @return DateTime
*/
public
function
convertToPHPValue
(
$value
,
AbstractPlatform
$platform
)
{
if
(
$value
===
null
)
{
return
null
;
}
$val
=
date_create
(
$value
);
if
(
!
$val
)
{
throw
ConversionException
::
conversionFailed
(
$value
,
$this
->
getName
());
}
return
$val
;
}
}
\ No newline at end of file
tests/Doctrine/Tests/DBAL/AllTests.php
View file @
835c9a03
...
...
@@ -35,6 +35,7 @@ class AllTests
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\ObjectTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\DateTimeTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\DateTimeTzTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\VarDateTimeTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\DateTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\TimeTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\DBAL\Types\BooleanTest'
);
...
...
tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php
0 → 100644
View file @
835c9a03
<?php
namespace
Doctrine\Tests\DBAL\Types
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DBAL\Mocks
;
require_once
__DIR__
.
'/../../TestInit.php'
;
class
VarDateTimeTest
extends
\Doctrine\Tests\DbalTestCase
{
protected
$_platform
,
$_type
;
protected
function
setUp
()
{
$this
->
_platform
=
new
\Doctrine\Tests\DBAL\Mocks\MockPlatform
();
if
(
!
Type
::
hasType
(
'vardatetime'
))
{
Type
::
addType
(
'vardatetime'
,
'Doctrine\DBAL\Types\VarDateTimeType'
);
}
$this
->
_type
=
Type
::
getType
(
'vardatetime'
);
}
public
function
testDateTimeConvertsToDatabaseValue
()
{
$date
=
new
\DateTime
(
'1985-09-01 10:10:10'
);
$expected
=
$date
->
format
(
$this
->
_platform
->
getDateTimeTzFormatString
());
$actual
=
is_string
(
$this
->
_type
->
convertToDatabaseValue
(
$date
,
$this
->
_platform
));
$this
->
assertEquals
(
$expected
,
$actual
);
}
public
function
testDateTimeConvertsToPHPValue
()
{
// Birthday of jwage and also birthday of Doctrine. Send him a present ;)
$date
=
$this
->
_type
->
convertToPHPValue
(
'1985-09-01 00:00:00'
,
$this
->
_platform
);
$this
->
assertType
(
'DateTime'
,
$date
);
$this
->
assertEquals
(
'1985-09-01 00:00:00'
,
$date
->
format
(
'Y-m-d H:i:s'
));
$this
->
assertEquals
(
'000000'
,
$date
->
format
(
'u'
));
}
public
function
testInvalidDateTimeFormatConversion
()
{
$this
->
setExpectedException
(
'Doctrine\DBAL\Types\ConversionException'
);
$this
->
_type
->
convertToPHPValue
(
'abcdefg'
,
$this
->
_platform
);
}
public
function
testConversionWithMicroseconds
()
{
$date
=
$this
->
_type
->
convertToPHPValue
(
'1985-09-01 00:00:00.123456'
,
$this
->
_platform
);
$this
->
assertType
(
'DateTime'
,
$date
);
$this
->
assertEquals
(
'1985-09-01 00:00:00'
,
$date
->
format
(
'Y-m-d H:i:s'
));
$this
->
assertEquals
(
'123456'
,
$date
->
format
(
'u'
));
}
public
function
testNullConversion
()
{
$this
->
assertNull
(
$this
->
_type
->
convertToPHPValue
(
null
,
$this
->
_platform
));
}
}
\ No newline at end of file
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