diff --git a/autoload/ezp_kernel.php b/autoload/ezp_kernel.php index ed8ea90e524..b8ef66449c6 100755 --- a/autoload/ezp_kernel.php +++ b/autoload/ezp_kernel.php @@ -486,6 +486,7 @@ 'eZTextTool' => 'lib/ezutils/classes/eztexttool.php', 'eZTextType' => 'kernel/classes/datatypes/eztext/eztexttype.php', 'eZTime' => 'lib/ezlocale/classes/eztime.php', + 'eZTimestamp' => 'lib/ezutils/classes/eztimestamp.php', 'eZTimeType' => 'kernel/classes/datatypes/eztime/eztimetype.php', 'eZTipafriendCounter' => 'kernel/classes/eztipafriendcounter.php', 'eZTipafriendRequest' => 'kernel/classes/eztipafriendrequest.php', diff --git a/kernel/classes/datatypes/ezdate/ezdatetype.php b/kernel/classes/datatypes/ezdate/ezdatetype.php index c256446600e..6b80dc59426 100644 --- a/kernel/classes/datatypes/ezdate/ezdatetype.php +++ b/kernel/classes/datatypes/ezdate/ezdatetype.php @@ -110,7 +110,7 @@ function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) { $date = new eZDate(); $date->setMDY( $month, $day, $year ); - $stamp = $date->timeStamp(); + $stamp = eZTimestamp::getUtcTimestampFromLocalTimestamp( $date->timeStamp() ); } $contentObjectAttribute->setAttribute( 'data_int', $stamp ); @@ -175,7 +175,7 @@ function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $ { $date = new eZDate(); $date->setMDY( $month, $day, $year ); - $stamp = $date->timeStamp(); + $stamp = eZTimestamp::getUtcTimestampFromLocalTimestamp( $date->timeStamp() ); } $collectionAttribute->setAttribute( 'data_int', $stamp ); @@ -191,7 +191,9 @@ function objectAttributeContent( $contentObjectAttribute ) { $date = new eZDate( ); $stamp = $contentObjectAttribute->attribute( 'data_int' ); - $date->setTimeStamp( $stamp ); + $date->setTimeStamp( + eZTimestamp::getLocalTimestampFromUtcTimestamp( $stamp ) + ); return $date; } @@ -344,7 +346,13 @@ function serializeContentObjectAttribute( $package, $objectAttribute ) { $dom = $node->ownerDocument; $dateNode = $dom->createElement( 'date' ); - $dateNode->appendChild( $dom->createTextNode( eZDateUtils::rfc1123Date( $stamp ) ) ); + $dateNode->appendChild( + $dom->createTextNode( + eZDateUtils::rfc1123Date( + eZTimestamp::getLocalTimestampFromUtcTimestamp( $stamp ) + ) + ) + ); $node->appendChild( $dateNode ); } return $node; @@ -355,7 +363,9 @@ function unserializeContentObjectAttribute( $package, $objectAttribute, $attribu $dateNode = $attributeNode->getElementsByTagName( 'date' )->item( 0 ); if ( is_object( $dateNode ) ) { - $timestamp = eZDateUtils::textToDate( $dateNode->textContent ); + $timestamp = eZTimestamp::getUtcTimestampFromLocalTimestamp( + eZDateUtils::textToDate( $dateNode->textContent ) + ); $objectAttribute->setAttribute( 'data_int', $timestamp ); } } diff --git a/lib/ezutils/classes/eztimestamp.php b/lib/ezutils/classes/eztimestamp.php new file mode 100644 index 00000000000..fcbecd85b23 --- /dev/null +++ b/lib/ezutils/classes/eztimestamp.php @@ -0,0 +1,41 @@ +setTimestamp( $localTimestamp ); + $utcDate = new \DateTime( $localDate->format( 'Y-m-d H:i:s' ), $utcTimezone ); + + return $utcDate->getTimestamp(); + } + + /*! + \return a timestamp in timezone defined in php.ini + */ + public static function getLocalTimestampFromUtcTimestamp( $utcTimestamp ) { + $utcTimezone = new \DateTimeZone( 'UTC' ); + $localTimezone = new \DateTimeZone( date_default_timezone_get() ); + + $utcDate = new \DateTime( null, $utcTimezone ); + $utcDate->setTimestamp( $utcTimestamp ); + $localDate = new \DateTime( $utcDate->format( 'Y-m-d H:i:s' ), $localTimezone ); + + return $localDate->getTimestamp(); + } +} +?>