Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezdatetime.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezdatetime.php 7544 2001-09-28 06:29:32Z jhe $
5 //
6 // Definition of eZDateTime class
7 //
8 // Created on: <07-Sep-2000 15:20:51 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
51 // include_once( "kernel/classes/ezdate.php" );
52 // include_once( "kernel/classes/eztime.php" );
53
54 class eZDateTime
55 {
60 function __construct( $year=-1, $month=-1, $day=-1, $hour=-1, $minute=-1, $second=-1 )
61 {
62 if ( ( $year == -1 ) && ( $month == -1 ) && ( $day == -1 ) && ( $hour == -1 ) && ( $minute == -1 ) && ( $second == -1 ) )
63 {
64 $now = getdate();
65 $this->Date = new eZDate( $now[ "year" ], $now[ "mon" ], $now[ "mday" ] );
66 $this->Time = new eZTime( $now[ "hours" ], $now[ "minutes" ], $now[ "seconds" ] );
67 }
68 else
69 {
70 $this->Date = new eZDate( $year, $month, $day );
71 $this->Time = new eZTime( $hour, $minute, $second );
72 }
73 }
74
78 function year()
79 {
80 return $this->Date->year();
81 }
82
86 function month()
87 {
88 return $this->Date->month();
89 }
90
94 function day()
95 {
96 return $this->Date->day();
97 }
98
102 function hour()
103 {
104 return $this->Time->hour();
105 }
106
110 function minute()
111 {
112 return $this->Time->minute();
113 }
114
118 function second()
119 {
120 return $this->Time->second();
121 }
122
126 function mySQLDateTime( )
127 {
128 if ( $this->month() < "10" )
129 {
130 $month = ( "0" . $this->month() );
131 }
132 else
133 {
134 $month = $this->month();
135 }
136
137 if ( $this->day() < "10" )
138 {
139 $day = ( "0" . $this->day() );
140 }
141 else
142 {
143 $day = $this->day();
144 }
145
146 if ( $this->hour() < "10" )
147 {
148 $hour = ( "0" . $this->hour() );
149 }
150 else
151 {
152 $hour = $this->hour();
153 }
154
155 if ( $this->minute() < "10" )
156 {
157 $minute = ( "0" . $this->minute() );
158 }
159 else
160 {
161 $minute = $this->minute();
162 }
163
164 if ( $this->second() < "10" )
165 {
166 $second = ( "0" . $this->second() );
167 }
168 else
169 {
170 $second = $this->second();
171 }
172 $current = ( $this->year() . "-" . $month . "-" . $day . " " . $hour . ":" . $minute . ":" . $second );
173 return $current;
174 }
175
179 function setYear( $value )
180 {
181 $this->Date->setYear( $value );
182 }
183
187 function setMonth( $value )
188 {
189 $this->Date->setMonth( $value );
190 }
191
195 function setDay( $value )
196 {
197 $this->Date->setDay( $value );
198 }
199
203 function setHour( $value )
204 {
205 $this->Time->setHour( $value );
206 }
207
211 function setMinute( $value )
212 {
213 $this->Time->setMinute( $value );
214 }
215
219 function setSecond( $value )
220 {
221 $this->Time->setSecond( $value );
222 }
223
227 function setSecondsElapsed( $value )
228 {
229 $this->Time->setSecondsElapsed( $value );
230 }
231
235 function setSecondsElapsedHMS( $hour, $minute, $second )
236 {
237 $this->Time->setSecondsElapsedHMS( $hour, $minute, $second );
238 }
239
244 function &date()
245 {
246 return $this->Date;
247 }
248
253 function &time()
254 {
255 return $this->Time;
256 }
257
262 function setMySQLDateTime( $value )
263 {
264 if ( preg_match( "/([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/", $value, $valueArray ) )
265 {
266 $this->setYear( $valueArray[1] );
267 $this->setMonth( $valueArray[2] );
268 $this->setDay( $valueArray[3] );
269 $this->setHour( $valueArray[4] );
270 $this->setMinute( $valueArray[5] );
271 $this->setSecond( $valueArray[6] );
272 }
273 else
274 {
275 print( "<b>Error:</b> eZDateTime::setMySQLDateTime() received wrong MySQL datetime format." );
276 }
277 }
278
282 function setMySQLTimeStamp( $value )
283 {
284 if ( preg_match( "/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", $value, $valueArray ) )
285 {
286 $this->setYear( $valueArray[1] );
287 $this->setMonth( $valueArray[2] );
288 $this->setDay( $valueArray[3] );
289 $this->setHour( $valueArray[4] );
290 $this->setMinute( $valueArray[5] );
291 $this->setSecond( $valueArray[6] );
292 }
293 else
294 {
295 print( "<b>Error:</b> eZDateTime::setMySQLTimeStamp() received wrong MySQL timestamp format." );
296 }
297 }
298
302 function setTimeStamp( $value )
303 {
304 $formattedTime = date('YmdHis', $value );
305
306 if ( preg_match( "/([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", $formattedTime, $valueArray ) )
307 {
308 $this->setYear( $valueArray[1] );
309 $this->setMonth( $valueArray[2] );
310 $this->setDay( $valueArray[3] );
311 $this->setHour( $valueArray[4] );
312 $this->setMinute( $valueArray[5] );
313 $this->setSecond( $valueArray[6] );
314 }
315 else
316 {
317 print( "<b>Error:</b> eZDateTime::setMySQLTimeStamp() received wrong MySQL timestamp format." );
318 }
319
320 }
321
328 public function timeStamp( $returnNow=false )
329 {
330 if ( $returnNow == true )
331 return time();
332 else
333 {
334 return mktime( $this->hour(), $this->minute(), $this->second(),
335 $this->month(), $this->day(), $this->year() );
336 }
337
338 }
339
340
345 function mysqlTimeStamp()
346 {
347 $year = $this->year();
348
349 $month = $this->addZero( $this->month() );
350 $day = $this->addZero( $this->day() );
351
352 $hour = $this->addZero( $this->hour() );
353 $minute = $this->addZero( $this->minute() );
354 $second = $this->addZero( $this->second() );
355
356 return $year . $month . $day . $hour . $minute . $second;
357 }
358
363 static public function addZero( $value )
364 {
365 $ret = $value;
366 if ( $ret < 10 )
367 {
368 $ret = "0". $ret;
369 }
370
371 return $ret;
372 }
373
377 function daysInMonth()
378 {
379 return $this->Date->daysInMonth();
380 }
381
386 function dayOfWeek( $mondayFirst )
387 {
388 return $this->Date->dayOfWeek( $mondayFirst );
389 }
390
395 function dayName( $mondayFirst )
396 {
397 return $this->Date->dayName( $mondayFirst );
398 }
399
400
404 function monthName( )
405 {
406 return $this->Date->monthName();
407 }
408
412 function isValid()
413 {
414 return $this->Date->isValid();
415 }
416
420 function dateEquals( $date )
421 {
422 return $this->Date->equals( $date );
423 }
424
434 function isGreater( &$datetime, $equal=false )
435 {
436 $ret = false;
437
438 if ( is_a( $datetime, "eZDateTime" ) )
439 {
440 if ( $this->Date->equals( $datetime->date() ) == true )
441 $ret = $this->Time->isGreater( $datetime->time(), $equal );
442 else
443 $ret = $this->Date->isGreater( $datetime->date(), false );
444 }
445 return $ret;
446 }
447
448
449 var $Date;
450 var $Time;
451
452 }
453
454 ?>
$day
else $day
Definition: appointmentedit.php:665
$year
else $year
Definition: appointmentedit.php:655
$month
else $month
Definition: appointmentedit.php:660
$datetime
$datetime
Definition: appointmentview.php:108
$date
$date
Definition: bugpreview.php:66
eZDateTime
Definition: ezdatetime.php:55
eZDateTime\date
& date()
Definition: ezdatetime.php:244
eZDateTime\setHour
setHour( $value)
Definition: ezdatetime.php:203
eZDateTime\setMinute
setMinute( $value)
Definition: ezdatetime.php:211
eZDateTime\setSecondsElapsed
setSecondsElapsed( $value)
Definition: ezdatetime.php:227
eZDateTime\dayOfWeek
dayOfWeek( $mondayFirst)
Definition: ezdatetime.php:386
eZDateTime\mySQLDateTime
mySQLDateTime()
Definition: ezdatetime.php:126
eZDateTime\addZero
static addZero( $value)
Definition: ezdatetime.php:363
eZDateTime\setSecond
setSecond( $value)
Definition: ezdatetime.php:219
eZDateTime\second
second()
Definition: ezdatetime.php:118
eZDateTime\$Date
$Date
Definition: ezdatetime.php:449
eZDateTime\month
month()
Definition: ezdatetime.php:86
eZDateTime\time
& time()
Definition: ezdatetime.php:253
eZDateTime\setSecondsElapsedHMS
setSecondsElapsedHMS( $hour, $minute, $second)
Definition: ezdatetime.php:235
eZDateTime\day
day()
Definition: ezdatetime.php:94
eZDateTime\dayName
dayName( $mondayFirst)
Definition: ezdatetime.php:395
eZDateTime\setMySQLTimeStamp
setMySQLTimeStamp( $value)
Definition: ezdatetime.php:282
eZDateTime\setYear
setYear( $value)
Definition: ezdatetime.php:179
eZDateTime\mysqlTimeStamp
mysqlTimeStamp()
Definition: ezdatetime.php:345
eZDateTime\year
year()
Definition: ezdatetime.php:78
eZDateTime\setTimeStamp
setTimeStamp( $value)
Definition: ezdatetime.php:302
eZDateTime\$Time
$Time
Definition: ezdatetime.php:450
eZDateTime\minute
minute()
Definition: ezdatetime.php:110
eZDateTime\setMonth
setMonth( $value)
Definition: ezdatetime.php:187
eZDateTime\timeStamp
timeStamp( $returnNow=false)
Definition: ezdatetime.php:328
eZDateTime\setMySQLDateTime
setMySQLDateTime( $value)
Definition: ezdatetime.php:262
eZDateTime\hour
hour()
Definition: ezdatetime.php:102
eZDateTime\setDay
setDay( $value)
Definition: ezdatetime.php:195
eZDateTime\dateEquals
dateEquals( $date)
Definition: ezdatetime.php:420
eZDateTime\isGreater
isGreater(&$datetime, $equal=false)
Definition: ezdatetime.php:434
eZDateTime\daysInMonth
daysInMonth()
Definition: ezdatetime.php:377
eZDateTime\__construct
__construct( $year=-1, $month=-1, $day=-1, $hour=-1, $minute=-1, $second=-1)
Definition: ezdatetime.php:60
eZDateTime\monthName
monthName()
Definition: ezdatetime.php:404
eZDateTime\isValid
isValid()
Definition: ezdatetime.php:412
eZDate
Definition: ezdate.php:46
eZTime
Definition: eztime.php:38
$minute
$minute
Definition: export_froogle.php:311
$hour
$hour
Definition: export_froogle.php:310
$now
$now
Definition: ezcalendar/user/dayview.php:401
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$current
$current
Definition: slideshow.php:97
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.