[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 [email protected] 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$ 21 */ 22 23 24 /** 25 * Zend_XmlRpc_Value_Scalar 26 */ 27 require_once 'Zend/XmlRpc/Value/Scalar.php'; 28 29 30 /** 31 * @category Zend 32 * @package Zend_XmlRpc 33 * @subpackage Value 34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) 35 * @license http://framework.zend.com/license/new-bsd New BSD License 36 */ 37 class Zend_XmlRpc_Value_DateTime extends Zend_XmlRpc_Value_Scalar 38 { 39 /** 40 * PHP compatible format string for XML/RPC datetime values 41 * 42 * @var string 43 */ 44 protected $_phpFormatString = 'Ymd\\TH:i:s'; 45 46 /** 47 * ISO compatible format string for XML/RPC datetime values 48 * 49 * @var string 50 */ 51 protected $_isoFormatString = 'YYYYMMddTHH:mm:ss'; 52 53 /** 54 * Set the value of a dateTime.iso8601 native type 55 * 56 * The value is in iso8601 format, minus any timezone information or dashes 57 * 58 * @param mixed $value Integer of the unix timestamp or any string that can be parsed 59 * to a unix timestamp using the PHP strtotime() function 60 */ 61 public function __construct($value) 62 { 63 $this->_type = self::XMLRPC_TYPE_DATETIME; 64 65 if ($value instanceof Zend_Date) { 66 $this->_value = $value->toString($this->_isoFormatString); 67 } elseif ($value instanceof DateTime) { 68 $this->_value = $value->format($this->_phpFormatString); 69 } elseif (is_numeric($value)) { // The value is numeric, we make sure it is an integer 70 $this->_value = date($this->_phpFormatString, (int)$value); 71 } else { 72 $timestamp = strtotime($value); 73 if ($timestamp === false || $timestamp == -1) { // cannot convert the value to a timestamp 74 require_once 'Zend/XmlRpc/Value/Exception.php'; 75 throw new Zend_XmlRpc_Value_Exception('Cannot convert given value \''. $value .'\' to a timestamp'); 76 } 77 78 $this->_value = date($this->_phpFormatString, $timestamp); // Convert the timestamp to iso8601 format 79 } 80 } 81 82 /** 83 * Return the value of this object as iso8601 dateTime value 84 * 85 * @return int As a Unix timestamp 86 */ 87 public function getValue() 88 { 89 return $this->_value; 90 } 91 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |