eZ Publish  [trunk]
eZTime Class Reference

Locale aware time handler. More...

List of all members.

Public Member Functions

 adjustTime ($hour, $minute=0, $second=0)
 attribute ($name)
 attributes ()
 duplicate ()
 eZTime ($timestamp=false)
 hasAttribute ($name)
 hour ()
 isEqualTo (&$time)
 isGreaterThan (&$time, $equal=false)
 isValid ()
locale ()
 minute ()
 second ()
 setHMS ($hour, $min=0, $sec=0)
 setHour ($hour)
 setLocale (&$locale)
 setMinute ($min)
 setSecond ($sec)
 setTimeOfDay ($timestamp)
 setTimeStamp ($timestamp)
 timeOfDay ()
 timeStamp ()
 toString ($short=false)

Static Public Member Functions

static create ($hour=-1, $minute=-1, $second=-1)
static secondsPerDay ()

Public Attributes

 $Locale
 Locale object, is just a reference to minimize memory usage.
 $Time
 The current time as a clamped timestamp.
const SECONDS_A_DAY = 86400
const SECONDS_A_MINUTE = 60
const SECONDS_AN_HOUR = 3600

Detailed Description

Locale aware time handler.

eZTime handles 24 hour time values in hours, minutes and seconds. The time stored as a timestamp clamped to a 24 hour day, ie 86400.

A new instance of eZTime will automaticly use the current locale and current time, if you however want a different locale use the setLocale() function. The current locale can be fetched with locale().

You can also change the time directly with setHour(), setMinute(), setSecond() and setHMS(). You can also adjust the time relative to it's current value by using adjustTime(). Use timeStamp() to get the current timestamp value or hour(), minute() and second() for the respective values.

When creating new times you're advised to use the static create() function which returns a new eZTime object. You can also create a copy with the duplicate() function.

Time checking is done with the isGreaterThan() and isEqualTo() functions.

Text output is done with toString() which can return a long string (default) or short string representation according to the current locale.

Example:

$us_locale = eZLocale::instance( 'us' );

$time1 = new eZTime();
$time2 = eZTime::create();
$time2->setLocale( $us_locale );
$time2->adjustTime( -8 );
$time3 = $time1->duplicate();

print( $time1->toString() );
print( $time2->toString( true ) );
print( $time1->isEqualTo( $time3 ) ? 'true' : 'false' ); // Prints 'true'
See also:
eZDate, eZDateTime, eZLocale

Definition at line 58 of file eztime.php.


Member Function Documentation

eZTime::adjustTime ( hour,
minute = 0,
second = 0 
)

Adjusts the time relative to it's current value. This is useful for adding/subtracting hours, minutes or seconds to an existing time.

Definition at line 265 of file eztime.php.

eZTime::attribute ( name)

Definition at line 111 of file eztime.php.

Definition at line 96 of file eztime.php.

Referenced by hasAttribute().

static eZTime::create ( hour = -1,
minute = -1,
second = -1 
) [static]

Creates a new eZTime object with the time values $hour, $min and $sec and returns a reference to it. Any value can be ommitted or set to -1 to use the current time value.

Definition at line 276 of file eztime.php.

Deprecated:
This function is deprecated in PHP5, use the PHP5 clone keyword instead Creates an exact copy of this object and returns it.

Definition at line 291 of file eztime.php.

eZTime::eZTime ( timestamp = false)

Creates a new time object with default locale, if $time is not supplied the current time is used.

Definition at line 79 of file eztime.php.

Referenced by create().

eZTime::hasAttribute ( name)

Definition at line 106 of file eztime.php.

Returns the hour element.

Definition at line 193 of file eztime.php.

Referenced by attribute(), setMinute(), setSecond(), and timeStamp().

eZTime::isEqualTo ( &$  time)

Returns true if this object is equal to $time. $time can be specified as a timestamp value or as an eZTime object.

Definition at line 321 of file eztime.php.

eZTime::isGreaterThan ( &$  time,
equal = false 
)

Returns true if this object has a time greater than $time. $time can be specified as a timestamp value or as an eZTime object. If $equal is true it returns true if they are equal as well.

Definition at line 302 of file eztime.php.

Returns:
true if the date has valid data.

Definition at line 133 of file eztime.php.

Referenced by attribute().

Returns a reference to the current locale.

Definition at line 149 of file eztime.php.

Returns the minute element.

Definition at line 201 of file eztime.php.

Referenced by attribute(), setHour(), setSecond(), and timeStamp().

Returns the second element.

Definition at line 209 of file eztime.php.

Referenced by attribute(), setHour(), setMinute(), and timeStamp().

static eZTime::secondsPerDay ( ) [static]
Deprecated:
Use eZTime::SECONDS_A_DAY instead Get number of seconds per day

Definition at line 349 of file eztime.php.

eZTime::setHMS ( hour,
min = 0,
sec = 0 
)

Sets all hour, minute and second elements.

Definition at line 184 of file eztime.php.

Referenced by eZTime().

eZTime::setHour ( hour)

Sets the hour leaving the other elements untouched.

Definition at line 157 of file eztime.php.

eZTime::setLocale ( &$  locale)

Sets the locale to $locale which is used in text output.

Definition at line 141 of file eztime.php.

eZTime::setMinute ( min)

Sets the minute leaving the other elements untouched.

Definition at line 166 of file eztime.php.

eZTime::setSecond ( sec)

Sets the second leaving the other elements untouched.

Definition at line 175 of file eztime.php.

eZTime::setTimeOfDay ( timestamp)

Definition at line 252 of file eztime.php.

Referenced by adjustTime(), and eZTime().

eZTime::setTimeStamp ( timestamp)

Definition at line 232 of file eztime.php.

Referenced by eZTime().

Returns the timestamp value, this is not the number of seconds since the epoch but a clamped value to the number of seconds in a day.

Definition at line 244 of file eztime.php.

Referenced by attribute().

Definition at line 217 of file eztime.php.

Referenced by attribute(), and toString().

eZTime::toString ( short = false)

Creates a string representation of the time using the current locale and returns it. If $short is true a short representation is used.

Definition at line 335 of file eztime.php.


Member Data Documentation

eZTime::$Locale

Locale object, is just a reference to minimize memory usage.

Definition at line 355 of file eztime.php.

eZTime::$Time

The current time as a clamped timestamp.

Definition at line 357 of file eztime.php.

const eZTime::SECONDS_A_DAY = 86400

Number of seconds in a day.

Definition at line 73 of file eztime.php.

Referenced by isEqualTo(), isGreaterThan(), secondsPerDay(), and setTimeOfDay().

Number of seconds in a minute.

Definition at line 63 of file eztime.php.

Referenced by second().

Number of seconds in an hour.

Definition at line 68 of file eztime.php.

Referenced by hour(), and minute().


The documentation for this class was generated from the following file: