Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezdate.php
Go to the documentation of this file.
1 <?php
57 class eZDate
58 {
63 public function __construct( $date = false )
64 {
65 if ( $date === false )
66 {
67 $date = mktime( 0, 0, 0 );
68 }
69 else
70 {
71 $arr = getdate( $date );
72 $date = mktime( 0, 0, 0, $arr['mon'], $arr['mday'], $arr['year'] );
73 }
74 $this->Date = $date;
75 $this->Locale = eZLocale::instance();
76 $this->IsValid = $date !== null;
77 }
78
79 function attributes()
80 {
81 return array( 'timestamp',
82 'is_valid',
83 'year',
84 'month',
85 'day' );
86 }
87
88 function hasAttribute( $name )
89 {
90 return in_array( $name, $this->attributes() );
91 }
92
93 function attribute( $name )
94 {
95 if ( $name == 'timestamp' )
96 return $this->timeStamp();
97 else if ( $name == 'is_valid' )
98 return $this->isValid();
99 else if ( $name == 'day' )
100 return $this->day();
101 else if ( $name == 'year' )
102 return $this->year();
103 else if ( $name == 'month' )
104 return $this->month();
105
106 eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ );
107 return false;
108 }
109
113 function isValid()
114 {
115 return $this->IsValid;
116 }
117
121 function setLocale( $locale )
122 {
123 $this->Locale = $locale;
124 }
125
129 function locale()
130 {
131 return $this->Locale;
132 }
133
139 function timeStamp()
140 {
141 return $this->Date;
142 }
143
144 function setTimeStamp( $stamp )
145 {
146 $this->Date = $stamp;
147 $this->IsValid = $stamp !== null;
148 }
149
153 function setYear( $year )
154 {
155 $arr = getdate( $this->Date );
156 $this->Date = mktime( 0, 0, 0, $arr['mon'], $arr['mday'], $year );
157 }
158
162 function setMonth( $month )
163 {
164 $arr = getdate( $this->Date );
165 $this->Date = mktime( 0, 0, 0, $month, $arr['mday'], $arr['year'] );
166 }
167
171 function setDay( $day )
172 {
173 $arr = getdate( $this->Date );
174 $this->Date = mktime( 0, 0, 0, $arr['mon'], $day, $arr['year'] );
175 }
176
180 function year()
181 {
182 return date( 'Y', $this->Date );
183 }
184
188 function month()
189 {
190 return date( 'm', $this->Date );
191 }
192
196 function day()
197 {
198 return date( 'd', $this->Date );
199 }
200
205 function setMDY( $month, $day = 0, $year = 0 )
206 {
207 if ( $year != 0 )
208 $date = mktime( 0, 0, 0, $month, $day, $year );
209 else if ( $day != 0 )
210 $date = mktime( 0, 0, 0, $month, $day );
211 else
212 $date = mktime( 0, 0, 0, $month );
213 $this->Date = $date;
214 }
215
220 function adjustDate( $month, $day = 0, $year = 0 )
221 {
222 $arr = getdate( $this->Date );
223 $date = mktime( 0, 0, 0, $month + $arr['mon'], $day + $arr['mday'], $year + $arr['year'] );
224 $this->Date = $date;
225 }
226
232 function isGreaterThan( $date, $equal = false )
233 {
234 $d1 = $this->timeStamp();
235 if ( $date instanceof eZDate )
236 {
237 $d2 = $date->timeStamp();
238 }
239 else
240 {
241 $arr = getdate( $date );
242 $d2 = mktime( 0, 0, 0, $arr['mon'], $arr['mday'], $arr['year'] );
243 }
244 if ( $d1 > $d2 )
245 return true;
246 else if ( $equal and $d1 == $d2 )
247 return true;
248 else
249 return false;
250 }
255 function isEqualTo( $date )
256 {
257 $d1 = $this->timeStamp();
258 if ( $date instanceof eZDate )
259 {
260 $d2 = $date->timeStamp();
261 }
262 else
263 {
264 $arr = getdate( $date );
265 $d2 = mktime( 0, 0, 0, $arr['mon'], $arr['mday'], $arr['year'] );
266 }
267 return $d1 == $d2;
268 }
269
274 static function create( $month, $day = 0, $year = 0 )
275 {
276 if ( $year != 0 )
277 $date = mktime( 0, 0, 0, $month, $day, $year );
278 else if ( $day != 0 )
279 $date = mktime( 0, 0, 0, $month, $day );
280 else
281 $date = mktime( 0, 0, 0, $month );
282 $newDateObject = new eZDate( $date );
283 return $newDateObject;
284 }
285
290 function duplicate()
291 {
292 $copy = clone $this;
293 return $copy;
294 }
295
300 function toString( $short = false )
301 {
302 if ( $short )
303 $str = $this->Locale->formatShortDate( $this->Date );
304 else
305 $str = $this->Locale->formatDate( $this->Date );
306 return $str;
307 }
308
309
311 public $Locale;
313 public $Date;
314 public $IsValid;
315 }
316
317 ?>
eZDate
Locale aware date handler.
Definition: ezdate.php:58
eZDate\adjustDate
adjustDate( $month, $day=0, $year=0)
Definition: ezdate.php:220
eZDate\day
day()
Definition: ezdate.php:196
eZDate\setTimeStamp
setTimeStamp( $stamp)
Definition: ezdate.php:144
eZDate\hasAttribute
hasAttribute( $name)
Definition: ezdate.php:88
eZDate\isValid
isValid()
Definition: ezdate.php:113
eZDate\$IsValid
$IsValid
Definition: ezdate.php:314
eZDate\setYear
setYear( $year)
Definition: ezdate.php:153
eZDate\setLocale
setLocale( $locale)
Definition: ezdate.php:121
eZDate\toString
toString( $short=false)
Definition: ezdate.php:300
eZDate\timeStamp
timeStamp()
Definition: ezdate.php:139
eZDate\year
year()
Definition: ezdate.php:180
eZDate\locale
locale()
Definition: ezdate.php:129
eZDate\$Locale
$Locale
Locale object, is just a reference to minimize memory usage.
Definition: ezdate.php:311
eZDate\__construct
__construct( $date=false)
Definition: ezdate.php:63
eZDate\setDay
setDay( $day)
Definition: ezdate.php:171
eZDate\isGreaterThan
isGreaterThan( $date, $equal=false)
Definition: ezdate.php:232
eZDate\$Date
$Date
The current date as a timestamp without hour, minute or second values.
Definition: ezdate.php:313
eZDate\setMDY
setMDY( $month, $day=0, $year=0)
Definition: ezdate.php:205
eZDate\setMonth
setMonth( $month)
Definition: ezdate.php:162
eZDate\attribute
attribute( $name)
Definition: ezdate.php:93
eZDate\duplicate
duplicate()
Definition: ezdate.php:290
eZDate\month
month()
Definition: ezdate.php:188
eZDate\attributes
attributes()
Definition: ezdate.php:79
eZDate\isEqualTo
isEqualTo( $date)
Definition: ezdate.php:255
eZDate\create
static create( $month, $day=0, $year=0)
Definition: ezdate.php:274
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZLocale\instance
static instance( $localeString=false)
Definition: ezlocale.php:1536
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.