diff --git a/kernel/classes/datatypes/ezdatetime/ezdatetimetype.php b/kernel/classes/datatypes/ezdatetime/ezdatetimetype.php index bdca7897681..dcda3b8e586 100644 --- a/kernel/classes/datatypes/ezdatetime/ezdatetimetype.php +++ b/kernel/classes/datatypes/ezdatetime/ezdatetimetype.php @@ -34,7 +34,7 @@ class eZDateTimeType extends eZDataType public function __construct() { parent::__construct( self::DATA_TYPE_STRING, ezpI18n::tr( 'kernel/classes/datatypes', "Date and time", 'Datatype name' ), - array( 'serialize_supported' => true ) ); + array( 'serialize_supported' => true ) ); } /*! @@ -46,7 +46,7 @@ function validateDateTimeHTTPInput( $day, $month, $year, $hour, $minute, $second if ( $state == eZInputValidator::STATE_INVALID ) { $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', - 'Date is not valid.' ) ); + 'Date is not valid.' ) ); return eZInputValidator::STATE_INVALID; } @@ -55,7 +55,7 @@ function validateDateTimeHTTPInput( $day, $month, $year, $hour, $minute, $second if ( $state == eZInputValidator::STATE_INVALID ) { $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', - 'Time is not valid.' ) ); + 'Time is not valid.' ) ); return eZInputValidator::STATE_INVALID; } return $state; @@ -71,11 +71,11 @@ function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute $useSeconds = ( $classAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ); if ( $http->hasPostVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and - ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) + $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and + ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) { $year = $http->postVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ); $month = $http->postVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ); @@ -85,11 +85,11 @@ function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute $second = $useSeconds ? $http->postVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) : 0; if ( $year == '' or - $month == '' or - $day == '' or - $hour == '' or - $minute == '' or - ( $useSeconds and $second == '' ) ) + $month == '' or + $day == '' or + $hour == '' or + $minute == '' or + ( $useSeconds and $second == '' ) ) { if ( !( $year == '' and $month == '' and @@ -97,11 +97,11 @@ function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute $hour == '' and $minute == '' and ( !$useSeconds or $second == '' ) ) or - ( !$classAttribute->attribute( 'is_information_collector' ) and - $contentObjectAttribute->validateIsRequired() ) ) + ( !$classAttribute->attribute( 'is_information_collector' ) and + $contentObjectAttribute->validateIsRequired() ) ) { $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', - 'Missing datetime input.' ) ); + 'Missing datetime input.' ) ); return eZInputValidator::STATE_INVALID; } else @@ -130,11 +130,11 @@ function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) $useSeconds = ( $contentClassAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ); if ( $http->hasPostVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and - ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) + $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and + ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) { $year = $http->postVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ); $month = $http->postVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ); @@ -144,16 +144,16 @@ function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) $second = $useSeconds ? $http->postVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) : 0; if ( ( $year == '' and $month == '' and $day == '' and - $hour == '' and $minute == '' and ( !$useSeconds or $second == '' ) ) or - !checkdate( $month, $day, $year ) ) + $hour == '' and $minute == '' and ( !$useSeconds or $second == '' ) ) or + !checkdate( $month, $day, $year ) ) { - $stamp = null; + $stamp = null; } else { $dateTime = new eZDateTime(); $dateTime->setMDYHMS( $month, $day, $year, $hour, $minute, $second ); - $stamp = $dateTime->timeStamp(); + $stamp = eZTimestamp::getUtcTimestampFromLocalTimestamp( $dateTime->timeStamp() ); } $contentObjectAttribute->setAttribute( 'data_int', $stamp ); @@ -168,11 +168,11 @@ function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttri $useSeconds = ( $contentClassAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ); if ( $http->hasPostVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and - ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) + $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and + ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) { $year = $http->postVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ); @@ -183,11 +183,11 @@ function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttri $second = $useSeconds ? $http->postVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) : 0; if ( $year == '' or - $month == '' or - $day == '' or - $hour == '' or - $minute == '' or - ( $useSeconds and $second == '' ) ) + $month == '' or + $day == '' or + $hour == '' or + $minute == '' or + ( $useSeconds and $second == '' ) ) { if ( !( $year == '' and $month == '' and @@ -195,10 +195,10 @@ function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttri $hour == '' and $minute == '' and ( !$useSeconds or $second == '' ) ) or - $contentObjectAttribute->validateIsRequired() ) + $contentObjectAttribute->validateIsRequired() ) { $contentObjectAttribute->setValidationError( ezpI18n::tr( 'kernel/classes/datatypes', - 'Missing datetime input.' ) ); + 'Missing datetime input.' ) ); return eZInputValidator::STATE_INVALID; } else @@ -213,20 +213,20 @@ function validateCollectionAttributeHTTPInput( $http, $base, $contentObjectAttri return eZInputValidator::STATE_INVALID; } - /*! - Fetches the http post variables for collected information - */ + /*! + Fetches the http post variables for collected information + */ function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $http, $base, $contentObjectAttribute ) { $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); $useSeconds = ( $contentClassAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ); if ( $http->hasPostVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and - $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and - ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) + $http->hasPostVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_day_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_hour_' . $contentObjectAttribute->attribute( 'id' ) ) and + $http->hasPostVariable( $base . '_datetime_minute_' . $contentObjectAttribute->attribute( 'id' ) ) and + ( !$useSeconds or $http->hasPostVariable( $base . '_datetime_second_' . $contentObjectAttribute->attribute( 'id' ) ) ) ) { $year = $http->postVariable( $base . '_datetime_year_' . $contentObjectAttribute->attribute( 'id' ) ); $month = $http->postVariable( $base . '_datetime_month_' . $contentObjectAttribute->attribute( 'id' ) ); @@ -237,16 +237,16 @@ function fetchCollectionAttributeHTTPInput( $collection, $collectionAttribute, $ $contentClassAttribute = $contentObjectAttribute->contentClassAttribute(); if ( ( $year == '' and $month == ''and $day == '' and - $hour == '' and $minute == '' and ( !$useSeconds or $second == '' ) ) or - !checkdate( $month, $day, $year ) ) + $hour == '' and $minute == '' and ( !$useSeconds or $second == '' ) ) or + !checkdate( $month, $day, $year ) ) { - $stamp = null; + $stamp = null; } else { $dateTime = new eZDateTime(); $dateTime->setMDYHMS( $month, $day, $year, $hour, $minute, $second ); - $stamp = $dateTime->timeStamp(); + $stamp = eZTimestamp::getUtcTimestampFromLocalTimestamp( $dateTime->timeStamp() ); } $collectionAttribute->setAttribute( 'data_int', $stamp ); @@ -262,7 +262,9 @@ function objectAttributeContent( $contentObjectAttribute ) { $dateTime = new eZDateTime(); $stamp = $contentObjectAttribute->attribute( 'data_int' ); - $dateTime->setTimeStamp( $stamp ); + $dateTime->setTimeStamp( + eZTimestamp::getLocalTimestampFromUtcTimestamp( $stamp ) + ); return $dateTime; } @@ -366,11 +368,11 @@ function classAttributeContent( $classAttribute ) function defaultClassAttributeContent() { return array( 'year' => '', - 'month' => '', - 'day' => '', - 'hour' => '', - 'minute' => '', - 'second' => '' ); + 'month' => '', + 'day' => '', + 'hour' => '', + 'minute' => '', + 'second' => '' ); } /*! @@ -439,11 +441,11 @@ function fetchClassAttributeHTTPInput( $http, $base, $classAttribute ) function contentObjectArrayXMLMap() { return array( 'year' => 'year', - 'month' => 'month', - 'day' => 'day', - 'hour' => 'hour', - 'minute' => 'minute', - 'second' => 'second' ); + 'month' => 'month', + 'day' => 'day', + 'hour' => 'hour', + 'minute' => 'minute', + 'second' => 'second' ); } @@ -481,37 +483,37 @@ function serializeContentClassAttribute( $classAttribute, $attributeNode, $attri switch ( $defaultValue ) { case self::DEFAULT_CURRENT_DATE: - { - $defaultValueNode->setAttribute( 'type', 'current-date' ); - } break; + { + $defaultValueNode->setAttribute( 'type', 'current-date' ); + } break; case self::DEFAULT_ADJUSTMENT: - { - $defaultValueNode->setAttribute( 'type', 'adjustment' ); - - $adjustDOMValue = new DOMDocument( '1.0', 'utf-8' ); - $adjustValue = $classAttribute->attribute( self::ADJUSTMENT_FIELD ); - $success = $adjustDOMValue->loadXML( $adjustValue ); - - if ( $success ) { - $adjustmentNode = $adjustDOMValue->getElementsByTagName( 'adjustment' )->item( 0 ); + $defaultValueNode->setAttribute( 'type', 'adjustment' ); - if ( $adjustmentNode ) + $adjustDOMValue = new DOMDocument( '1.0', 'utf-8' ); + $adjustValue = $classAttribute->attribute( self::ADJUSTMENT_FIELD ); + $success = $adjustDOMValue->loadXML( $adjustValue ); + + if ( $success ) { - $importedAdjustmentNode = $dom->importNode( $adjustmentNode, true ); - $defaultValueNode->appendChild( $importedAdjustmentNode ); + $adjustmentNode = $adjustDOMValue->getElementsByTagName( 'adjustment' )->item( 0 ); + + if ( $adjustmentNode ) + { + $importedAdjustmentNode = $dom->importNode( $adjustmentNode, true ); + $defaultValueNode->appendChild( $importedAdjustmentNode ); + } } - } - } break; + } break; case self::DEFAULT_EMTPY: - { - $defaultValueNode->setAttribute( 'type', 'empty' ); - } break; + { + $defaultValueNode->setAttribute( 'type', 'empty' ); + } break; default: - { - eZDebug::writeError( 'Unknown type of DateTime default value. Empty type used instead.', __METHOD__ ); - $defaultValueNode->setAttribute( 'type', 'empty' ); - } break; + { + eZDebug::writeError( 'Unknown type of DateTime default value. Empty type used instead.', __METHOD__ ); + $defaultValueNode->setAttribute( 'type', 'empty' ); + } break; } $attributeParametersNode->appendChild( $defaultValueNode ); @@ -532,33 +534,33 @@ function unserializeContentClassAttribute( $classAttribute, $attributeNode, $att switch ( $defaultValue ) { case 'current-date': - { - $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_CURRENT_DATE ); - } break; + { + $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_CURRENT_DATE ); + } break; case 'adjustment': - { - $adjustmentValue = ''; - $adjustmentNode = $defaultNode->getElementsByTagName( 'adjustment' )->item( 0 ); - if ( $adjustmentNode ) { - $adjustmentDOMValue = new DOMDocument( '1.0', 'utf-8' ); - $importedAdjustmentNode = $adjustmentDOMValue->importNode( $adjustmentNode, true ); - $adjustmentDOMValue->appendChild( $importedAdjustmentNode ); - $adjustmentValue = $adjustmentDOMValue->saveXML(); - } + $adjustmentValue = ''; + $adjustmentNode = $defaultNode->getElementsByTagName( 'adjustment' )->item( 0 ); + if ( $adjustmentNode ) + { + $adjustmentDOMValue = new DOMDocument( '1.0', 'utf-8' ); + $importedAdjustmentNode = $adjustmentDOMValue->importNode( $adjustmentNode, true ); + $adjustmentDOMValue->appendChild( $importedAdjustmentNode ); + $adjustmentValue = $adjustmentDOMValue->saveXML(); + } - $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_ADJUSTMENT ); - $classAttribute->setAttribute( self::ADJUSTMENT_FIELD, $adjustmentValue ); - } break; + $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_ADJUSTMENT ); + $classAttribute->setAttribute( self::ADJUSTMENT_FIELD, $adjustmentValue ); + } break; case 'empty': - { - $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_EMTPY ); - } break; + { + $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_EMTPY ); + } break; default: - { - eZDebug::writeError( 'Type of DateTime default value is not set. Empty type used as default.', __METHOD__ ); - $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_EMTPY ); - } break; + { + eZDebug::writeError( 'Type of DateTime default value is not set. Empty type used as default.', __METHOD__ ); + $classAttribute->setAttribute( self::DEFAULT_FIELD, self::DEFAULT_EMTPY ); + } break; } $useSecondsNode = $attributeParametersNode->getElementsByTagName( 'use-seconds' )->item( 0 ); @@ -581,7 +583,13 @@ function serializeContentObjectAttribute( $package, $objectAttribute ) { $dom = $node->ownerDocument; $dateTimeNode = $dom->createElement( 'date_time' ); - $dateTimeNode->appendChild( $dom->createTextNode( eZDateUtils::rfc1123Date( $stamp ) ) ); + $dateTimeNode->appendChild( + $dom->createTextNode( + eZDateUtils::rfc1123Date( + eZTimestamp::getLocalTimestampFromUtcTimestamp( $stamp ) + ) + ) + ); $node->appendChild( $dateTimeNode ); } return $node; @@ -592,7 +600,9 @@ function unserializeContentObjectAttribute( $package, $objectAttribute, $attribu $dateTimeNode = $attributeNode->getElementsByTagName( 'date_time' )->item( 0 ); if ( is_object( $dateTimeNode ) ) { - $timestamp = eZDateUtils::textToDate( $dateTimeNode->textContent ); + $timestamp = eZTimestamp::getUtcTimestampFromLocalTimestamp( + eZDateUtils::textToDate( $dateTimeNode->textContent ) + ); $objectAttribute->setAttribute( 'data_int', $timestamp ); } } @@ -609,24 +619,24 @@ function batchInitializeObjectAttributeData( $classAttribute ) switch( $defaultType ) { case self::DEFAULT_CURRENT_DATE: - { - $default = time(); - } break; + { + $default = time(); + } break; case self::DEFAULT_ADJUSTMENT: - { - $adjustments = $this->classAttributeContent( $classAttribute ); - $value = new eZDateTime(); - $secondAdjustment = $classAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ? $adjustments['second'] : 0; - $value->adjustDateTime( $adjustments['hour'], $adjustments['minute'], $secondAdjustment, $adjustments['month'], $adjustments['day'], $adjustments['year'] ); + { + $adjustments = $this->classAttributeContent( $classAttribute ); + $value = new eZDateTime(); + $secondAdjustment = $classAttribute->attribute( self::USE_SECONDS_FIELD ) == 1 ? $adjustments['second'] : 0; + $value->adjustDateTime( $adjustments['hour'], $adjustments['minute'], $secondAdjustment, $adjustments['month'], $adjustments['day'], $adjustments['year'] ); - $default = $value->timeStamp(); - } break; + $default = $value->timeStamp(); + } break; default: - { - return array(); - } + { + return array(); + } } return array( 'data_int' => $default, 'sort_key_int' => $default );