Skip to content
Permalink
Browse files

Merge branch '2018.09'

  • Loading branch information...
andrerom committed Mar 11, 2019
2 parents d436540 + b14a7da commit b5de72e23d8ff39e52e1a83430b386cff18d411d
Showing with 57 additions and 5 deletions.
  1. +1 −0 autoload/ezp_kernel.php
  2. +15 −5 kernel/classes/datatypes/ezdate/ezdatetype.php
  3. +41 −0 lib/ezutils/classes/eztimestamp.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',
@@ -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 );
}
}
@@ -0,0 +1,41 @@
<?php
/**
* File containing the eZTimestamp class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
* @package lib
*/
class eZTimestamp
{
/*!
\return a timestamp in UTC
*/
public static function getUtcTimestampFromLocalTimestamp( $localTimestamp ) {
$utcTimezone = new \DateTimeZone( 'UTC' );
$localTimezone = new \DateTimeZone( date_default_timezone_get() );
$localDate = new \DateTime( null, $localTimezone );
$localDate->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();
}
}
?>

0 comments on commit b5de72e

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.