Magento file: lib/Zend/XmlRpc/Value/DateTime.php

Please LogIn to Reply!

Post By: admin | 26-01-2012 06:35 Reply

Magento folder: lib/Zend/XmlRpc/Value/
Magento file: lib/Zend/XmlRpc/Value/DateTime.php

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_XmlRpc
  17. * @subpackage Value
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  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 $
  21. */
  22. /**
  23. * Zend_XmlRpc_Value_Scalar
  24. */
  25. #require_once 'Zend/XmlRpc/Value/Scalar.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_XmlRpc
  29. * @subpackage Value
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_XmlRpc_Value_DateTime extends Zend_XmlRpc_Value_Scalar
  34. {
  35. /**
  36. * PHP compatible format string for XML/RPC datetime values
  37. *
  38. * @var string
  39. */
  40. protected $_phpFormatString = 'Ymd\\TH:i:s';
  41. /**
  42. * ISO compatible format string for XML/RPC datetime values
  43. *
  44. * @var string
  45. */
  46. protected $_isoFormatString = 'YYYYMMddTHH:mm:ss';
  47. /**
  48. * Set the value of a dateTime.iso8601 native type
  49. *
  50. * The value is in iso8601 format, minus any timezone information or dashes
  51. *
  52. * @param mixed $value Integer of the unix timestamp or any string that can be parsed
  53. * to a unix timestamp using the PHP strtotime() function
  54. */
  55. public function __construct($value)
  56. {
  57. $this->_type = self::XMLRPC_TYPE_DATETIME;
  58. if ($value instanceof Zend_Date) {
  59. $this->_value = $value->toString($this->_isoFormatString);
  60. } elseif ($value instanceof DateTime) {
  61. $this->_value = $value->format($this->_phpFormatString);
  62. } elseif (is_numeric($value)) { // The value is numeric, we make sure it is an integer
  63. $this->_value = date($this->_phpFormatString, (int)$value);
  64. } else {
  65. $timestamp = strtotime($value);
  66. if ($timestamp === false || $timestamp == -1) { // cannot convert the value to a timestamp
  67. #require_once 'Zend/XmlRpc/Value/Exception.php';
  68. throw new Zend_XmlRpc_Value_Exception('Cannot convert given value \''. $value .'\' to a timestamp');
  69. }
  70. $this->_value = date($this->_phpFormatString, $timestamp); // Convert the timestamp to iso8601 format
  71. }
  72. }
  73. /**
  74. * Return the value of this object as iso8601 dateTime value
  75. *
  76. * @return int As a Unix timestamp
  77. */
  78. public function getValue()
  79. {
  80. return $this->_value;
  81. }
  82. }
`Reply Or Comment!
Please LogIn to Reply!