eZ Publish  [trunk]
eZDateTime Class Reference

Locale aware date and time handler. More...

List of all members.

Public Member Functions

 adjustDateTime ($hour, $minute=0, $second=0, $month=0, $day=0, $year=0)
 attribute ($name)
 attributes ()
 day ()
 duplicate ()
 eZDateTime ($datetime=false)
 hasAttribute ($name)
 hour ()
 isEqualTo (&$datetime)
 isGreaterThan (&$datetime, $equal=false)
 isValid ()
 locale ()
 minute ()
 month ()
 second ()
 setDay ($day)
 setHMS ($hour, $min=0, $sec=0)
 setHour ($hour)
 setLocale ($locale)
 setMDY ($month, $day=0, $year=0)
 setMDYHMS ($month, $day, $year, $hour, $min, $sec=0)
 setMinute ($min)
 setMonth ($month)
 setSecond ($sec)
 setTimeStamp ($stamp)
 setYear ($year)
 timeStamp ()
 timeZone ()
 toDate ()
 toString ($short=false)
 toTime ()
 year ()

Static Public Member Functions

static create ($hour=-1, $minute=-1, $second=-1, $month=-1, $day=-1, $year=-1)
static currentTimeStamp ()

Public Attributes

 $DateTime
 The current datetime as a timestamp.
 $IsValid
 $Locale
 Locale object, is just a reference to minimize memory usage.

Detailed Description

Locale aware date and time handler.

eZDateTime handles 24 hour time values in hours, minutes and seconds and date values. The datetime stored as a timestamp with the number of seconds since the epoch. See PHP function date() and time() for more information.

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

Change the time directly with setHour(), setMinute(), setSecond() and setHMS(). Change the date directly with setYear(), setMonth(), setDay() and setMDY(). You can also adjust the date time relative to it's current value by using adjustDateTime(). Use timeStamp() to get the current timestamp value or year(), month(), day(), hour(), minute() and second() for the respective values.

When creating new datetimes you're advised to use the static create() function which returns a new eZDateTime 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' );

$dt1 = new eZDateTime();
$dt2 = eZDateTime::create();
$dt2->setLocale( $us_locale );
$dt2->adjustDateTime( -8, 0, 0, 1, 2, 3 );
$dt3 = $dt1->duplicate();

print( $dt1->toString() );
print( $dt2->toString( true ) );
print( $dt1->isEqualTo( $dt3 ) ? 'true' : 'false' ); // Prints 'true'
See also:
eZDate, eZTime, eZLocale

Definition at line 61 of file ezdatetime.php.


Member Function Documentation

eZDateTime::adjustDateTime ( hour,
minute = 0,
second = 0,
month = 0,
day = 0,
year = 0 
)

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

Definition at line 378 of file ezdatetime.php.

eZDateTime::attribute ( name)

Definition at line 110 of file ezdatetime.php.

Definition at line 93 of file ezdatetime.php.

Referenced by hasAttribute().

static eZDateTime::create ( hour = -1,
minute = -1,
second = -1,
month = -1,
day = -1,
year = -1 
) [static]

Creates a new eZDate object with the time values $hour, $minute and $second, date values $month, $day and $year and returns a reference to it. Any value can be ommitted or set to -1 to use the current date or time value.

Definition at line 450 of file ezdatetime.php.

static eZDateTime::currentTimeStamp ( ) [static]

Returns the current date and time as a UNIX timestamp

Definition at line 202 of file ezdatetime.php.

Referenced by eZContentFunctions\createAndPublishObject().

Returns the day element.

Definition at line 248 of file ezdatetime.php.

Referenced by attribute().

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 473 of file ezdatetime.php.

eZDateTime::eZDateTime ( datetime = false)

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

Definition at line 67 of file ezdatetime.php.

Referenced by create().

Definition at line 105 of file ezdatetime.php.

Returns the hour element.

Definition at line 256 of file ezdatetime.php.

Referenced by attribute().

eZDateTime::isEqualTo ( &$  datetime)

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

Note:
If $datetime is either eZDate or eZTime it will create temporary objects with toDate() and toTime() and use these for comparison.

Definition at line 424 of file ezdatetime.php.

eZDateTime::isGreaterThan ( &$  datetime,
equal = false 
)

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

Note:
If $datetime is either eZDate or eZTime it will create temporary objects with toDate() and toTime() and use these for comparison.

Definition at line 393 of file ezdatetime.php.

Returns:
true if the date has valid data.

Definition at line 154 of file ezdatetime.php.

Referenced by attribute().

Returns the current locale.

Definition at line 170 of file ezdatetime.php.

Returns the minute element.

Definition at line 264 of file ezdatetime.php.

Referenced by attribute().

Returns the month element.

Definition at line 240 of file ezdatetime.php.

Referenced by attribute().

Returns the second element.

Definition at line 272 of file ezdatetime.php.

Referenced by attribute().

eZDateTime::setDay ( day)

Sets the day leaving the other elements untouched.

Definition at line 300 of file ezdatetime.php.

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

Sets all hour, minute and second elements leaving the other elements untouched.

Definition at line 340 of file ezdatetime.php.

eZDateTime::setHour ( hour)

Sets the hour leaving the other elements untouched.

Definition at line 310 of file ezdatetime.php.

eZDateTime::setLocale ( locale)

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

Definition at line 162 of file ezdatetime.php.

eZDateTime::setMDY ( month,
day = 0,
year = 0 
)

Sets the year, month and day elements. If $day or $year is omitted or set 0 they will get a value taken from the current time.

Definition at line 359 of file ezdatetime.php.

eZDateTime::setMDYHMS ( month,
day,
year,
hour,
min,
sec = 0 
)

Sets all hour, minute and second elements leaving the other elements untouched.

Definition at line 350 of file ezdatetime.php.

Sets the minute leaving the other elements untouched.

Definition at line 320 of file ezdatetime.php.

eZDateTime::setMonth ( month)

Sets the month leaving the other elements untouched.

Definition at line 290 of file ezdatetime.php.

Sets the second leaving the other elements untouched.

Definition at line 330 of file ezdatetime.php.

Definition at line 192 of file ezdatetime.php.

eZDateTime::setYear ( year)

Sets the year leaving the other elements untouched.

Definition at line 280 of file ezdatetime.php.

Returns the timestamp value, this is the number of seconds since the epoch.

Note:
The value is returned as a reference and should not be modified.

Definition at line 187 of file ezdatetime.php.

Referenced by attribute(), isEqualTo(), and isGreaterThan().

Returns the current time zone.

Definition at line 178 of file ezdatetime.php.

Creates an eZDate object of this datetime with the same date and locale. Returns a reference to the object.

Definition at line 211 of file ezdatetime.php.

Referenced by isEqualTo(), and isGreaterThan().

eZDateTime::toString ( short = false)

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

Definition at line 483 of file ezdatetime.php.

Creates an eZTime object of this datetime with the same time and locale. Returns a reference to the object.

Definition at line 222 of file ezdatetime.php.

Referenced by isEqualTo(), and isGreaterThan().

Returns the year element.

Definition at line 232 of file ezdatetime.php.

Referenced by attribute().


Member Data Documentation

eZDateTime::$DateTime

The current datetime as a timestamp.

Definition at line 497 of file ezdatetime.php.

eZDateTime::$IsValid

Definition at line 498 of file ezdatetime.php.

eZDateTime::$Locale

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

Definition at line 495 of file ezdatetime.php.


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