equal
deleted
inserted
replaced
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_XmlRpc |
16 * @package Zend_XmlRpc |
17 * @subpackage Value |
17 * @subpackage Value |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: DateTime.php 20278 2010-01-14 14:48:59Z ralph $ |
20 * @version $Id: DateTime.php 24593 2012-01-05 20:35:02Z matthew $ |
21 */ |
21 */ |
22 |
22 |
23 |
23 |
24 /** |
24 /** |
25 * Zend_XmlRpc_Value_Scalar |
25 * Zend_XmlRpc_Value_Scalar |
29 |
29 |
30 /** |
30 /** |
31 * @category Zend |
31 * @category Zend |
32 * @package Zend_XmlRpc |
32 * @package Zend_XmlRpc |
33 * @subpackage Value |
33 * @subpackage Value |
34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
34 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
36 */ |
36 */ |
37 class Zend_XmlRpc_Value_DateTime extends Zend_XmlRpc_Value_Scalar |
37 class Zend_XmlRpc_Value_DateTime extends Zend_XmlRpc_Value_Scalar |
38 { |
38 { |
39 /** |
39 /** |
46 /** |
46 /** |
47 * ISO compatible format string for XML/RPC datetime values |
47 * ISO compatible format string for XML/RPC datetime values |
48 * |
48 * |
49 * @var string |
49 * @var string |
50 */ |
50 */ |
51 protected $_isoFormatString = 'YYYYMMddTHH:mm:ss'; |
51 protected $_isoFormatString = 'yyyyMMddTHH:mm:ss'; |
52 |
52 |
53 /** |
53 /** |
54 * Set the value of a dateTime.iso8601 native type |
54 * Set the value of a dateTime.iso8601 native type |
55 * |
55 * |
56 * The value is in iso8601 format, minus any timezone information or dashes |
56 * The value is in iso8601 format, minus any timezone information or dashes |
67 } elseif ($value instanceof DateTime) { |
67 } elseif ($value instanceof DateTime) { |
68 $this->_value = $value->format($this->_phpFormatString); |
68 $this->_value = $value->format($this->_phpFormatString); |
69 } elseif (is_numeric($value)) { // The value is numeric, we make sure it is an integer |
69 } elseif (is_numeric($value)) { // The value is numeric, we make sure it is an integer |
70 $this->_value = date($this->_phpFormatString, (int)$value); |
70 $this->_value = date($this->_phpFormatString, (int)$value); |
71 } else { |
71 } else { |
72 $timestamp = strtotime($value); |
72 $timestamp = new DateTime($value); |
73 if ($timestamp === false || $timestamp == -1) { // cannot convert the value to a timestamp |
73 if ($timestamp === false) { // cannot convert the value to a timestamp |
74 require_once 'Zend/XmlRpc/Value/Exception.php'; |
74 require_once 'Zend/XmlRpc/Value/Exception.php'; |
75 throw new Zend_XmlRpc_Value_Exception('Cannot convert given value \''. $value .'\' to a timestamp'); |
75 throw new Zend_XmlRpc_Value_Exception('Cannot convert given value \''. $value .'\' to a timestamp'); |
76 } |
76 } |
77 |
77 |
78 $this->_value = date($this->_phpFormatString, $timestamp); // Convert the timestamp to iso8601 format |
78 $this->_value = $timestamp->format($this->_phpFormatString); // Convert the timestamp to iso8601 format |
79 } |
79 } |
80 } |
80 } |
81 |
81 |
82 /** |
82 /** |
83 * Return the value of this object as iso8601 dateTime value |
83 * Return the value of this object as iso8601 dateTime value |