Skip to content

Commit

Permalink
- Namespaces cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Feb 14, 2020
1 parent 07ed60d commit e7b1def
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace IPub\DoctrineTimestampable\Events;

use DateTime;
use DateTimeZone;
use Zend_Date;

use Nette;
Expand Down Expand Up @@ -345,8 +347,8 @@ private function getDateValue(ORM\Mapping\ClassMetadata $classMetadata, string $
return new Zend_Date();
}

return \DateTime::createFromFormat('U.u', number_format(microtime(TRUE), 6, '.', ''))
->setTimezone(new \DateTimeZone(date_default_timezone_get()));
return DateTime::createFromFormat('U.u', number_format(microtime(TRUE), 6, '.', ''))
->setTimezone(new DateTimeZone(date_default_timezone_get()));
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/IPub/DoctrineTimestampable/Types/UTCDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

namespace IPub\DoctrineTimestampable\Types;

use DateTime;
use DateTimeInterface;
use DateTimeZone;

use Doctrine\DBAL\Platforms;
use Doctrine\DBAL\Types;
Expand All @@ -29,15 +31,15 @@
*
* @author Adam Kadlec <adam.kadlec@ipublikuj.eu>
*/
class UTCDateTime extends Types\DateTimeType
class UTCDateTime extends TypesDateTimeType
{
/**
* Define datatype name
*/
public const UTC_DATETIME = 'utcdatetime';

/**
* @var \DateTimeZone|NULL
* @var DateTimeZone|NULL
*/
static private $utc = NULL;

Expand All @@ -64,10 +66,10 @@ public function convertToPHPValue($value, Platforms\AbstractPlatform $platform)
}

if (self::$utc === NULL) {
self::$utc = new \DateTimeZone('UTC');
self::$utc = new DateTimeZone('UTC');
}

$val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value, self::$utc);
$val = DateTime::createFromFormat($platform->getDateTimeFormatString(), $value, self::$utc);

if (!$val) {
throw Types\ConversionException::conversionFailed($value, $this->getName());
Expand All @@ -89,7 +91,7 @@ public function convertToDatabaseValue($value, Platforms\AbstractPlatform $platf
}

if (self::$utc === NULL) {
self::$utc = new \DateTimeZone('UTC');
self::$utc = new DateTimeZone('UTC');
}

$value->setTimeZone(self::$utc);
Expand Down

0 comments on commit e7b1def

Please sign in to comment.