Skip to content

Instantly share code, notes, and snippets.

@pumatertion
Created March 24, 2014 14:42
Show Gist options
  • Save pumatertion/9741434 to your computer and use it in GitHub Desktop.
Save pumatertion/9741434 to your computer and use it in GitHub Desktop.
<?php
namespace BLEICKER\ArtManager\Structure\Property\TypeConverter;
/* *
* This script belongs to the TYPO3 Flow framework. *
* *
* It is free software; you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License, either version 3 *
* of the License, or (at your option) any later version. *
* *
* The TYPO3 project - inspiring people to share! *
* */
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Property\TypeConverter\DateTimeConverter as OriginDateTimeConverter;
/**
* @Flow\Scope("singleton")
*/
class DateTimeConverter extends OriginDateTimeConverter {
/**
* @var integer
*/
protected $priority = 100;
/**
* Converts $source to a \DateTime using the configured dateFormat
* Proves that any DateTime receives the phps ini default timezone to work internaly allways with the same timezone
* because persistence does not have any TimeZone informations
*
* @param string|integer|array $source the string to be converted to a \DateTime object
* @param string $targetType must be "DateTime"
* @param array $convertedChildProperties not used currently
* @param \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration
* @return \DateTime
* @throws \TYPO3\Flow\Property\Exception\TypeConverterException
*/
public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = NULL) {
$dateTime = parent::convertFrom($source, $targetType, $convertedChildProperties, $configuration);
if ($dateTime instanceof \DateTime) {
$dateTime->setTimezone(new \DateTimeZone(ini_get('date.timezone')));
}
return $dateTime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment