eZPublishCommunityProject(LegacyStack)  2013.9
eZDateTime Class Reference

Locale aware date and time handler. More...

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. More...
 
 $IsValid
 
 $Locale
 Locale object, is just a reference to minimize memory usage. More...
 

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->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

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.

eZDateTime::attribute (   $name)
eZDateTime::attributes ( )

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.

static eZDateTime::currentTimeStamp ( )
static

Returns the current date and time as a UNIX timestamp

Referenced by eZContentFunctions\createAndPublishObject().

eZDateTime::day ( )

Returns the day element.

Referenced by attribute().

eZDateTime::duplicate ( )
Deprecated:
This function is deprecated in PHP5, use the PHP5 clone keyword instead Creates an exact copy of this object and returns it.
eZDateTime::eZDateTime (   $datetime = false)

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

Referenced by create().

eZDateTime::hasAttribute (   $name)
eZDateTime::hour ( )

Returns the hour element.

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.
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.
eZDateTime::isValid ( )
Returns
true if the date has valid data.

Referenced by attribute().

eZDateTime::locale ( )

Returns the current locale.

eZDateTime::minute ( )

Returns the minute element.

Referenced by attribute().

eZDateTime::month ( )

Returns the month element.

Referenced by attribute().

eZDateTime::second ( )

Returns the second element.

Referenced by attribute().

eZDateTime::setDay (   $day)

Sets the day leaving the other elements untouched.

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

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

eZDateTime::setHour (   $hour)

Sets the hour leaving the other elements untouched.

eZDateTime::setLocale (   $locale)

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

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.

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

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

eZDateTime::setMinute (   $min)

Sets the minute leaving the other elements untouched.

eZDateTime::setMonth (   $month)

Sets the month leaving the other elements untouched.

eZDateTime::setSecond (   $sec)

Sets the second leaving the other elements untouched.

eZDateTime::setTimeStamp (   $stamp)
eZDateTime::setYear (   $year)

Sets the year leaving the other elements untouched.

eZDateTime::timeStamp ( )

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.

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

eZDateTime::timeZone ( )

Returns the current time zone.

eZDateTime::toDate ( )

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

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.

eZDateTime::toTime ( )

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

Referenced by isEqualTo(), and isGreaterThan().

eZDateTime::year ( )

Returns the year element.

Referenced by attribute().

Member Data Documentation

eZDateTime::$DateTime

The current datetime as a timestamp.

Referenced by timeStamp().

eZDateTime::$IsValid

Referenced by isValid().

eZDateTime::$Locale

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

Referenced by locale().


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