Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezdate.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezdate.php 7544 2001-09-28 06:29:32Z jhe $
5 //
6 // Definition of eZCompany class
7 //
8 // Created on: <06-Sep-2000 16:20:20 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
45 class eZDate
46 {
51 function __construct( $year = 0, $month = 0, $day = 0, $year_add = 0, $month_add = 0, $day_add = 0 )
52 {
53 if ( is_a( $year, "eZDate" ) )
54 {
55 $this->setYear( $year->year() );
56 $this->setMonth( $year->month() );
57 $this->setDay( $year->day() );
58 }
59 else if ( ( $year == 0 ) && ( $month == 0 ) && ( $day == 0 ) )
60 {
61 $now = getdate();
62 $this->setYear( $now["year"] );
63 $this->setMonth( $now["mon"] );
64 $this->setDay( $now["mday"] );
65 }
66 else
67 {
68 $this->setYear( $year );
69 $this->setMonth( $month );
70 $this->setDay( $day );
71 }
72 $this->move( $year_add, $month_add, $day_add );
73 }
74
78 function year()
79 {
80 return $this->Year;
81 }
82
86 function month()
87 {
88 return $this->Month;
89 }
90
94 function day()
95 {
96 return $this->Day;
97 }
98
102 function setYear( $value )
103 {
104 $this->Year = $value;
105 setType( $this->Year, "integer" );
106 }
107
111 function setMonth( $value )
112 {
113 $this->Month = $value;
114 setType( $this->Month, "integer" );
115 }
116
120 function setDay( $value )
121 {
122 $this->Day = $value;
123 setType( $this->Day, "integer" );
124 }
125
130 function setMySQLDate( $value )
131 {
132 if ( preg_match( "/([0-9]{4})-([0-9]{2})-([0-9]{2})/", $value, $valueArray ) )
133 {
134 $this->setYear( $valueArray[1] );
135 $this->setMonth( $valueArray[2] );
136 $this->setDay( $valueArray[3] );
137 }
138 else
139 {
140 print( "<b>Error:</b> eZDate::setMySQLDate() received wrong MySQL date format." );
141 }
142 }
143
147 function mySQLDate()
148 {
149 $return = $this->Year;
150 $return = $return . "-" . $this->addZero($this->Month);
151 $return = $return . "-" . $this->addZero($this->Day);
152
153 return $return;
154 }
155
159 function setTimeStamp( $value )
160 {
161 $formattedTime =& date('Ymd', $value );
162
163 if ( preg_match( "/([0-9]{4})([0-9]{2})([0-9]{2})/", $formattedTime, $valueArray ) )
164 {
165 $this->setYear( $valueArray[1] );
166 $this->setMonth( $valueArray[2] );
167 $this->setDay( $valueArray[3] );
168 }
169 else
170 {
171 print( "<b>Error:</b> eZDateTime::setMySQLTimeStamp() received wrong MySQL timestamp format." );
172 }
173
174 }
175
182 function timeStamp( $returnNow=false )
183 {
184 if ( $returnNow == true )
185 return time();
186 else
187 return mktime( 0, 0, 0,
188 $this->month(), $this->day(), $this->year() );
189 }
190
191
195 function daysInMonth()
196 {
197 $lastday = mktime( 2, 0, 0, $this->Month + 1, 0, $this->Year );
198
199 return date( "d", $lastday );
200 }
201
206 function dayOfWeek( $mondayFirst = true )
207 {
208 $weekday = date( "w", mktime( 1, 0, 0, $this->Month, $this->Day, $this->Year ) );
209
210 if ( $mondayFirst == true )
211 {
212 if ( $weekday == 0 )
213 $weekday = 7;
214 }
215 else
216 {
217 $weekday = $weekday + 1;
218 }
219
220 return $weekday;
221 }
222
227 function addZero( $value )
228 {
229 $ret = $value;
230 if ( $ret < 10 )
231 {
232 $ret = "0". $ret;
233 }
234
235 return $ret;
236 }
237
242 function dayName( $mondayFirst )
243 {
244 $day = "unknown";
245
246 if ( $mondayFirst == true )
247 {
248 switch( $this->dayOfWeek( $mondayFirst ) )
249 {
250 case 1 :
251 {
252 $day = "mon";
253 }
254 break;
255
256 case 2 :
257 {
258 $day = "tue";
259 }
260 break;
261
262 case 3 :
263 {
264 $day = "wed";
265 }
266 break;
267
268 case 4 :
269 {
270 $day = "thu";
271 }
272 break;
273
274 case 5 :
275 {
276 $day = "fri";
277 }
278 break;
279
280 case 6 :
281 {
282 $day = "sat";
283 }
284 break;
285
286 case 7 :
287 {
288 $day = "sun";
289 }
290 break;
291 }
292 }
293 else
294 {
295 switch( $this->dayOfWeek( $mondayFirst ) )
296 {
297 case 1 :
298 {
299 $day = "sun";
300 }
301 break;
302
303 case 2 :
304 {
305 $day = "mon";
306 }
307 break;
308
309 case 3 :
310 {
311 $day = "tue";
312 }
313 break;
314
315 case 4 :
316 {
317 $day = "wed";
318 }
319 break;
320
321 case 5 :
322 {
323 $day = "thu";
324 }
325 break;
326
327 case 6 :
328 {
329 $day = "fri";
330 }
331 break;
332
333 case 7 :
334 {
335 $day = "sat";
336 }
337 break;
338 }
339 }
340
341 return $day;
342 }
343
347 function monthName( )
348 {
349 $month = "unknown";
350
351 switch( $this->Month )
352 {
353 case 1 :
354 {
355 $month = "jan";
356 }
357 break;
358
359 case 2 :
360 {
361 $month = "feb";
362 }
363 break;
364
365 case 3 :
366 {
367 $month = "mar";
368 }
369 break;
370
371 case 4 :
372 {
373 $month = "apr";
374 }
375 break;
376
377 case 5 :
378 {
379 $month = "may";
380 }
381 break;
382
383 case 6 :
384 {
385 $month = "jun";
386 }
387 break;
388
389 case 7 :
390 {
391 $month = "jul";
392 }
393 break;
394
395 case 8 :
396 {
397 $month = "aug";
398 }
399 break;
400
401 case 9 :
402 {
403 $month = "sep";
404 }
405 break;
406
407 case 10 :
408 {
409 $month = "oct";
410 }
411 break;
412
413 case 11 :
414 {
415 $month = "nov";
416 }
417 break;
418
419 case 12 :
420 {
421 $month = "dec";
422 }
423 break;
424 }
425 return $month;
426 }
427
431 function isValid()
432 {
433 return checkdate( $this->Month(), $this->Day(), $this->Year() );
434 }
435
439 function equals( $date )
440 {
441 if ( $this->Year == $date->year() &&
442 $this->Month == $date->month() &&
443 $this->Day == $date->day() )
444 {
445 return true;
446 }
447 else
448 {
449 return false;
450 }
451 }
452
462 function isGreater( &$date, $equal=false )
463 {
464 $ret = false;
465
466 if ( is_a( $date, "eZDate" ) )
467 {
468 if ( $date->year() < $this->Year )
469 $ret = false;
470 else if ( $date->year() > $this->Year )
471 $ret = true;
472 else
473 {
474 if ( $date->month() < $this->Month )
475 $ret = false;
476 else if ( $date->month() > $this->Month )
477 $ret = true;
478 else
479 {
480 if ( $equal == false )
481 {
482 if ( $date->day() > $this->Day )
483 {
484 $ret = true;
485 }
486 }
487 else
488 {
489 if ( $date->day() >= $this->Day )
490 {
491 $ret = true;
492 }
493 }
494 }
495 }
496 }
497 return $ret;
498 }
499
503 function move( $year_num, $month_num, $day_num )
504 {
505 $date = getdate( mktime( 0, 0, 0,
506 $this->Month + $month_num,
507 $this->Day + $day_num,
508 $this->Year + $year_num ) );
509 $this->Year = $date["year"];
510 $this->Month = $date["mon"];
511 $this->Day = $date["mday"];
512 }
513
514 var $Year;
515 var $Month;
516 var $Day;
517 }
518
519 ?>
$day
else $day
Definition: appointmentedit.php:665
$year
else $year
Definition: appointmentedit.php:655
$month
else $month
Definition: appointmentedit.php:660
$date
$date
Definition: bugpreview.php:66
eZDate
Definition: ezdate.php:46
eZDate\isGreater
isGreater(&$date, $equal=false)
Definition: ezdate.php:462
eZDate\mySQLDate
mySQLDate()
Definition: ezdate.php:147
eZDate\day
day()
Definition: ezdate.php:94
eZDate\__construct
__construct( $year=0, $month=0, $day=0, $year_add=0, $month_add=0, $day_add=0)
Definition: ezdate.php:51
eZDate\dayOfWeek
dayOfWeek( $mondayFirst=true)
Definition: ezdate.php:206
eZDate\isValid
isValid()
Definition: ezdate.php:431
eZDate\setTimeStamp
setTimeStamp( $value)
Definition: ezdate.php:159
eZDate\move
move( $year_num, $month_num, $day_num)
Definition: ezdate.php:503
eZDate\setDay
setDay( $value)
Definition: ezdate.php:120
eZDate\$Year
$Year
Definition: ezdate.php:514
eZDate\dayName
dayName( $mondayFirst)
Definition: ezdate.php:242
eZDate\year
year()
Definition: ezdate.php:78
eZDate\monthName
monthName()
Definition: ezdate.php:347
eZDate\timeStamp
timeStamp( $returnNow=false)
Definition: ezdate.php:182
eZDate\addZero
addZero( $value)
Definition: ezdate.php:227
eZDate\month
month()
Definition: ezdate.php:86
eZDate\setYear
setYear( $value)
Definition: ezdate.php:102
eZDate\setMySQLDate
setMySQLDate( $value)
Definition: ezdate.php:130
eZDate\daysInMonth
daysInMonth()
Definition: ezdate.php:195
eZDate\setMonth
setMonth( $value)
Definition: ezdate.php:111
eZDate\$Month
$Month
Definition: ezdate.php:515
eZDate\equals
equals( $date)
Definition: ezdate.php:439
eZDate\$Day
$Day
Definition: ezdate.php:516
$now
$now
Definition: ezcalendar/user/dayview.php:401
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.