## 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. */
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. class ezcFeedDateElement extends ezcFeedElement
42. {
43. /**
44. * Sets the property $name to $value.
45. *
46. * @param string $name The property name
47. * @param mixed $value The property value
48. * @ignore
49. */
50. public function __set( $name, $value )
51. {
52. switch ( $name )
53. {
54. case 'date':
55. $this-> properties [$name] = $this->prepareDate( $value );
56. break;
58. default:
59. parent::__set( $name, $value );
60. }
61. }
63. /**
64. * Returns the value of property $name.
65. *
66. * @param string $name The property name
67. * @return mixed
68. * @ignore
69. */
70. public function __get( $name )
71. {
72. switch ( $name )
73. {
74. case 'date':
75. if ( isset( $this-> properties [$name] ) )
76. {
77. return $this-> properties [$name];
78. }
79. break;
81. default:
82. return parent::__get( $name );
83. }
84. }
86. /**
87. * Returns if the property $name is set.
88. *
89. * @param string $name The property name
90. * @return bool
91. * @ignore
92. */
93. public function __isset( $name )
94. {
95. switch ( $name )
96. {
97. case 'date':
98. return isset( $this-> properties [$name] );
100. default:
101. return parent::__isset( $name );
102. }
103. }
105. /**
106. * Returns the provided $date (timestamp, string or DateTime object) as a
107. * DateTime object.
108. *
109. * It preserves the timezone if $date contained timezone information.
110. *
111. * @param mixed $date A date specified as a timestamp, string or DateTime object
112. * @return DateTime
113. */
114. private function prepareDate( $date )
115. {
116. if ( is_numeric ( $date ) )
117. {
118. return new DateTime( "@{$date}" );
119. }
120. else if ( $date instanceof DateTime )
121. {
122. return $date;
123. }
124. else
125. {
126. try
127. {
128. $d = new DateTime( $date );
129. }
130. catch ( Exception $e )
131. {
132. return new DateTime();
133. }
135. return $d;
136. }
137. }
138. }
139. ?>

Documentation generated by phpDocumentor 1.4.3