Apache Zeta Components Manual :: File Source for date.php

Source for file date.php

Documentation is available at date.php

  1. <?php
  2. /**
  3.  * File containing the ezcFeedDateElement class.
  4.  *
  5.  * Licensed to the Apache Software Foundation (ASF) under one
  6.  * or more contributor license agreements.  See the NOTICE file
  7.  * distributed with this work for additional information
  8.  * regarding copyright ownership.  The ASF licenses this file
  9.  * to you under the Apache License, Version 2.0 (the
  10.  * "License"); you may not use this file except in compliance
  11.  * with the License.  You may obtain a copy of the License at
  12.  * 
  13.  *   http://www.apache.org/licenses/LICENSE-2.0
  14.  * 
  15.  * Unless required by applicable law or agreed to in writing,
  16.  * software distributed under the License is distributed on an
  17.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18.  * KIND, either express or implied.  See the License for the
  19.  * specific language governing permissions and limitations
  20.  * under the License.
  21.  *
  22.  * @package Feed
  23.  * @version //autogentag//
  24.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25.  * @filesource
  26.  */
  27.  
  28. /**
  29.  * Class defining a date element.
  30.  *
  31.  * @property DateTime $date 
  32.  *                     The date stored as a DateTime object. An integer timestamp
  33.  *                     or a formatted string date can be assigned to the $date
  34.  *                     property, and it will be converted to a DateTime object.
  35.  *                     If the conversion was not successful, the current date
  36.  *                     is assigned to the property.
  37.  *
  38.  * @package Feed
  39.  * @version //autogentag//
  40.  */
  41. {
  42.     /**
  43.      * Sets the property $name to $value.
  44.      *
  45.      * @param string $name The property name
  46.      * @param mixed $value The property value
  47.      * @ignore
  48.      */
  49.     public function __set$name$value )
  50.     {
  51.         switch $name )
  52.         {
  53.             case 'date':
  54.                 $this->properties[$name$this->prepareDate$value );
  55.                 break;
  56.  
  57.             default:
  58.                 parent::__set$name$value );
  59.         }
  60.     }
  61.  
  62.     /**
  63.      * Returns the value of property $name.
  64.      *
  65.      * @param string $name The property name
  66.      * @return mixed 
  67.      * @ignore
  68.      */
  69.     public function __get$name )
  70.     {
  71.         switch $name )
  72.         {
  73.             case 'date':
  74.                 if isset$this->properties[$name) )
  75.                 {
  76.                     return $this->properties[$name];
  77.                 }
  78.                 break;
  79.  
  80.             default:
  81.                 return parent::__get$name );
  82.         }
  83.     }
  84.  
  85.     /**
  86.      * Returns if the property $name is set.
  87.      *
  88.      * @param string $name The property name
  89.      * @return bool 
  90.      * @ignore
  91.      */
  92.     public function __isset$name )
  93.     {
  94.         switch $name )
  95.         {
  96.             case 'date':
  97.                 return isset$this->properties[$name);
  98.  
  99.             default:
  100.                 return parent::__isset$name );
  101.         }
  102.     }
  103.  
  104.     /**
  105.      * Returns the provided $date (timestamp, string or DateTime object) as a
  106.      * DateTime object.
  107.      *
  108.      * It preserves the timezone if $date contained timezone information.
  109.      *
  110.      * @param mixed $date A date specified as a timestamp, string or DateTime object
  111.      * @return DateTime 
  112.      */
  113.     private function prepareDate$date )
  114.     {
  115.         if is_numeric$date ) )
  116.         {
  117.             return new DateTime"@{$date});
  118.         }
  119.         else if $date instanceof DateTime )
  120.         {
  121.             return $date;
  122.         }
  123.         else
  124.         {
  125.             try
  126.             {
  127.                 $d new DateTime$date );
  128.             }
  129.             catch Exception $e )
  130.             {
  131.                 return new DateTime();
  132.             }
  133.  
  134.             return $d;
  135.         }
  136.     }
  137. }
  138. ?>
Documentation generated by phpDocumentor 1.4.3