Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

eztime.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: eztime.php 9777 2003-02-20 08:28:46Z br $
5 //
6 // Definition of eZCompany class
7 //
8 // Created on: <08-Sep-2000 13:54:17 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
37 class eZTime
38 {
42 function __construct( $hour=-1, $minute=-1, $second=-1 )
43 {
44 if ( ( $hour == -1 ) && ( $minute == -1 ) && ( $second == -1 ) )
45 {
46 $this->SecondsElapsed = 0;
47 // $now = getdate();
48 // $this->setSecondsElapsedHMS( $now["hours"], $now["minutes"], $now["seconds"] );
49 }
50 else
51 {
52 $this->setSecondsElapsedHMS( $hour, $minute, $second );
53 }
54 }
55
59 function hour()
60 {
61 $value = $this->SecondsElapsed;
62
63 $second = $value % 60;
64 $value = ( $value - $second ) / 60;
65
66 $minute = $value % 60;
67 $value = ( $value - $minute ) / 60;
68
69 $hour = $value % 24;
70
71 return $hour;
72 }
73
77 function minute()
78 {
79 $value = $this->SecondsElapsed;
80
81 $second = $value % 60;
82 $value = ( $value - $second ) / 60;
83
84 $minute = $value % 60;
85
86 return $minute;
87 }
88
92 function second()
93 {
94 $value = $this->SecondsElapsed;
95
96 $second = $value % 60;
97
98 return $second;
99 }
100
104 function secondsElapsed()
105 {
106 return $this->SecondsElapsed;
107 }
108
112 function setHour( $value )
113 {
114 $value = min( $value, 23 );
115 $this->SecondsElapsed = ( ( $value * 3600 ) + ( $this->minute() * 60 ) + $this->second() );
116 setType( $this->SecondsElapsed, "integer" );
117 }
118
122 function setMinute( $value )
123 {
124 $value = min( $value, 59 );
125 $this->SecondsElapsed = ( ( $this->hour() * 3600 ) + ( $value * 20 ) + $this->second() );
126 }
127
131 function setSecond( $value )
132 {
133 $value = min( $value, 59 );
134 $this->SecondsElapsed = ( ( $this->hour() * 3600 ) + ( $this->minute() * 60 ) + $value );
135 }
136
140 function setSecondsElapsed( $value )
141 {
142 $this->SecondsElapsed = $value;
143 }
144
148 function setSecondsElapsedHMS( $hour, $minute, $second )
149 {
150 $this->SecondsElapsed = ( ( $hour * 3600 ) + ( $minute * 60 ) + $second );
151 setType( $this->SecondsElapsed, "integer" );
152 }
153
160 function add( $time )
161 {
162 $ret = false;
163 if ( is_a( $time, "eZTime" ) )
164 {
165 $tmpTime = new eZTime( $this->hour(), $this->minute(), $this->second() );
166
167 $secondsElapsed = ( $this->SecondsElapsed + $time->secondsElapsed() ) % 86400;
168 $tmpTime->setSecondsElapsed( $secondsElapsed );
169
170 $ret = $tmpTime;
171 }
172 else if ( is_numeric( $time ) )
173 {
174 $tmpTime = new eZTime( $this->hour(), $this->minute(), $this->second() );
175 $tmpTime->setSecondsElapsed( $this->secondsElapsed() + $time );
176
177 $ret = $tmpTime;
178 }
179
180 return $ret;
181 }
182
187 function addZero( $value )
188 {
189 $ret = $value;
190 if ( $ret < 10 )
191 {
192 $ret = "0". $ret;
193 }
194
195 return $ret;
196 }
197
206 function subtract( $time )
207 {
208 $ret = false;
209 if ( is_a( $time, "eZTime" ) )
210 {
211 $tmpTime = new eZTime( $this->hour(), $this->minute(), $this->second() );
212
213 $secondsElapsed = ( ( 86400 + $this->SecondsElapsed ) - $time->secondsElapsed() ) % 86400;
214 $tmpTime->setSecondsElapsed( $secondsElapsed );
215
216 $ret = $tmpTime;
217 }
218
219 return $ret;
220 }
221
231 function isGreater( &$time, $equal=false )
232 {
233 $ret = false;
234
235 if ( is_a( $time, "eZTime" ) )
236 {
237 if ( $equal == false )
238 {
239 if ( $time->secondsElapsed() > $this->SecondsElapsed )
240 {
241 $ret = true;
242 }
243 }
244 else
245 {
246 if ( $time->secondsElapsed() >= $this->SecondsElapsed )
247 {
248 $ret = true;
249 }
250 }
251 }
252 return $ret;
253 }
254
261 function equals( &$time )
262 {
263 $ret = false;
264
265 if ( is_a( $time, "eZTime" ) )
266 {
267 if ( $time->secondsElapsed() == $this->SecondsElapsed )
268 {
269 $ret = true;
270 }
271 }
272 return $ret;
273 }
274
280 function setMySQLTime( $value )
281 {
282 if ( preg_match( "/([0-9]{2}):([0-9]{2}):([0-9]{2})/", $value, $valueArray ) )
283 {
284 $this->setSecondsElapsedHMS( $valueArray[1], $valueArray[2], $valueArray[3] );
285 }
286 else
287 {
288 print( "<b>Error:</b> eZTime::setMySQLTime() received wrong MySQL time format." );
289 }
290 }
291
296 function mysqlTime()
297 {
298 $hour = $this->addZero( $this->hour() );
299 $minute = $this->addZero( $this->minute() );
300 $second = $this->addZero( $this->second() );
301
302 return $hour . ":" . $minute . ":" . $second;
303 }
304
308 function setTimeStamp( $value )
309 {
310 $formattedTime =& date('His', $value );
311
312 if ( preg_match( "/([0-9]{2})([0-9]{2})([0-9]{2})/", $formattedTime, $valueArray ) )
313 {
314 $this->setHour( min( $valueArray[1], 23 ) );
315 $this->setMinute( min( $valueArray[2], 59 ) );
316 $this->setSecond( min( $valueArray[3], 59 ) );
317 }
318 else
319 {
320 print( "<b>Error:</b> eZTime::setTimeStamp() received wrong time format." );
321 }
322
323 }
324
331 public function timeStamp( $returnNow = false )
332 {
333 if ( $returnNow == true )
334 return time();
335 else
336 return $this->hour() * 3600 + $this->minute() * 60 + $this->second();
337 }
338
340 var $SecondsElapsed;
341 var $Time;
342 }
343
344 ?>
eZTime
Definition: eztime.php:38
eZTime\mysqlTime
mysqlTime()
Definition: eztime.php:296
eZTime\minute
minute()
Definition: eztime.php:77
eZTime\setSecondsElapsed
setSecondsElapsed( $value)
Definition: eztime.php:140
eZTime\equals
equals(&$time)
Definition: eztime.php:261
eZTime\setHour
setHour( $value)
Definition: eztime.php:112
eZTime\$SecondsElapsed
$SecondsElapsed
Store the number of seconds since 00:00:00.
Definition: eztime.php:340
eZTime\setSecond
setSecond( $value)
Definition: eztime.php:131
eZTime\secondsElapsed
secondsElapsed()
Definition: eztime.php:104
eZTime\subtract
subtract( $time)
Definition: eztime.php:206
eZTime\setSecondsElapsedHMS
setSecondsElapsedHMS( $hour, $minute, $second)
Definition: eztime.php:148
eZTime\setMySQLTime
setMySQLTime( $value)
Definition: eztime.php:280
eZTime\isGreater
isGreater(&$time, $equal=false)
Definition: eztime.php:231
eZTime\setMinute
setMinute( $value)
Definition: eztime.php:122
eZTime\add
add( $time)
Definition: eztime.php:160
eZTime\hour
hour()
Definition: eztime.php:59
eZTime\addZero
addZero( $value)
Definition: eztime.php:187
eZTime\__construct
__construct( $hour=-1, $minute=-1, $second=-1)
Definition: eztime.php:42
eZTime\timeStamp
timeStamp( $returnNow=false)
Definition: eztime.php:331
eZTime\second
second()
Definition: eztime.php:92
eZTime\$Time
$Time
Definition: eztime.php:341
eZTime\setTimeStamp
setTimeStamp( $value)
Definition: eztime.php:308
$minute
$minute
Definition: export_froogle.php:311
$hour
$hour
Definition: export_froogle.php:310
$tmpTime
$tmpTime
Definition: ezcalendar/user/dayview.php:258
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$time
$time
Definition: homepage.php:327
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.