diff -r 5e7a0fedabdf -r 877f952ae2bd web/lib/Zend/Service/WindowsAzure/Storage/TableEntity.php --- a/web/lib/Zend/Service/WindowsAzure/Storage/TableEntity.php Thu Mar 21 17:31:31 2013 +0100 +++ b/web/lib/Zend/Service/WindowsAzure/Storage/TableEntity.php Thu Mar 21 19:50:53 2013 +0100 @@ -15,28 +15,20 @@ * @category Zend * @package Zend_Service_WindowsAzure * @subpackage Storage - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License - * @version $Id: TableEntity.php 23167 2010-10-19 17:53:31Z mabe $ + * @version $Id: TableEntity.php 24593 2012-01-05 20:35:02Z matthew $ */ /** - * @see Zend_Service_WindowsAzure_Exception - */ -require_once 'Zend/Service/WindowsAzure/Exception.php'; - - -/** * @category Zend * @package Zend_Service_WindowsAzure * @subpackage Storage - * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ class Zend_Service_WindowsAzure_Storage_TableEntity { - const DEFAULT_TIMESTAMP = '1900-01-01T00:00:00'; - /** * Partition key * @@ -129,8 +121,8 @@ */ public function getTimestamp() { - if (null === $this->_timestamp) { - $this->setTimestamp(self::DEFAULT_TIMESTAMP); + if (null === $this->_timestamp) { + $this->setTimestamp(new DateTime()); } return $this->_timestamp; } @@ -139,9 +131,9 @@ * Set timestamp * * @azure Timestamp Edm.DateTime - * @param string $value + * @param DateTime $value */ - public function setTimestamp($value = '1900-01-01T00:00:00') + public function setTimestamp(DateTime $value) { $this->_timestamp = $value; } @@ -230,6 +222,8 @@ break; case 'edm.double': $values[$accessor->AzurePropertyName] = floatval($values[$accessor->AzurePropertyName]); break; + case 'edm.datetime': + $values[$accessor->AzurePropertyName] = $this->_convertToDateTime($values[$accessor->AzurePropertyName]); break; } } @@ -242,6 +236,7 @@ $this->$method($values[$accessor->AzurePropertyName]); } } else if ($throwOnError) { + require_once 'Zend/Service/WindowsAzure/Exception.php'; throw new Zend_Service_WindowsAzure_Exception("Property '" . $accessor->AzurePropertyName . "' was not found in \$values array"); } } @@ -268,7 +263,7 @@ $properties = $type->getProperties(); foreach ($properties as $property) { $accessor = self::getAzureAccessor($property); - if ($accessor !== null) { + if (!is_null($accessor)) { $azureAccessors[] = $accessor; } } @@ -277,7 +272,7 @@ $methods = $type->getMethods(); foreach ($methods as $method) { $accessor = self::getAzureAccessor($method); - if ($accessor !== null) { + if (!is_null($accessor)) { $azureAccessors[] = $accessor; } } @@ -325,4 +320,35 @@ 'AzurePropertyType' => isset($azureProperties[1]) ? $azureProperties[1] : '' ); } + + /** + * Converts a string to a DateTime object. Returns false on failure. + * + * @param string $value The string value to parse + * @return DateTime|boolean + */ + protected function _convertToDateTime($value = '') + { + if ($value === '') { + return false; + } + + if ($value instanceof DateTime) { + return $value; + } + + if (@strtotime($value) !== false) { + try { + if (substr($value, -1) == 'Z') { + $value = substr($value, 0, strlen($value) - 1); + } + return new DateTime($value, new DateTimeZone('UTC')); + } + catch (Exception $ex) { + return false; + } + } + + return false; + } }