eZ Publish  [4.2]
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:

//include_once( 'lib/ezlocale/classes/ezlocale.php' );
//include_once( 'lib/ezlocale/classes/ezdatetime.php' );

$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 83 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 400 of file ezdatetime.php.

eZDateTime::attribute ( name)

Definition at line 132 of file ezdatetime.php.

eZDateTime::attributes ( )

Definition at line 115 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 472 of file ezdatetime.php.

static eZDateTime::currentTimeStamp ( ) [static]

Returns the current date and time as a UNIX timestamp

Definition at line 224 of file ezdatetime.php.

Referenced by eZContentFunctions\createAndPublishObject().

eZDateTime::day ( )

Returns the day element.

Definition at line 270 of file ezdatetime.php.

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.

Definition at line 495 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 89 of file ezdatetime.php.

Referenced by create().

eZDateTime::hasAttribute ( name)

Definition at line 127 of file ezdatetime.php.

eZDateTime::hour ( )

Returns the hour element.

Definition at line 278 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 446 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 415 of file ezdatetime.php.

eZDateTime::isValid ( )
Returns:
true if the date has valid data.

Definition at line 176 of file ezdatetime.php.

Referenced by attribute().

eZDateTime::locale ( )

Returns the current locale.

Definition at line 192 of file ezdatetime.php.

eZDateTime::minute ( )

Returns the minute element.

Definition at line 286 of file ezdatetime.php.

Referenced by attribute().

eZDateTime::month ( )

Returns the month element.

Definition at line 262 of file ezdatetime.php.

Referenced by attribute().

eZDateTime::second ( )

Returns the second element.

Definition at line 294 of file ezdatetime.php.

Referenced by attribute().

eZDateTime::setDay ( day)

Sets the day leaving the other elements untouched.

Definition at line 322 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 362 of file ezdatetime.php.

eZDateTime::setHour ( hour)

Sets the hour leaving the other elements untouched.

Definition at line 332 of file ezdatetime.php.

eZDateTime::setLocale ( locale)

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

Definition at line 184 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 381 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 372 of file ezdatetime.php.

eZDateTime::setMinute ( min)

Sets the minute leaving the other elements untouched.

Definition at line 342 of file ezdatetime.php.

eZDateTime::setMonth ( month)

Sets the month leaving the other elements untouched.

Definition at line 312 of file ezdatetime.php.

eZDateTime::setSecond ( sec)

Sets the second leaving the other elements untouched.

Definition at line 352 of file ezdatetime.php.

eZDateTime::setTimeStamp ( stamp)

Definition at line 214 of file ezdatetime.php.

eZDateTime::setYear ( year)

Sets the year leaving the other elements untouched.

Definition at line 302 of file ezdatetime.php.

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.

Definition at line 209 of file ezdatetime.php.

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

eZDateTime::timeZone ( )

Returns the current time zone.

Definition at line 200 of file ezdatetime.php.

eZDateTime::toDate ( )

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

Definition at line 233 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 505 of file ezdatetime.php.

eZDateTime::toTime ( )

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

Definition at line 244 of file ezdatetime.php.

Referenced by isEqualTo(), and isGreaterThan().

eZDateTime::year ( )

Returns the year element.

Definition at line 254 of file ezdatetime.php.

Referenced by attribute().


Member Data Documentation

eZDateTime::$DateTime

The current datetime as a timestamp.

Definition at line 519 of file ezdatetime.php.

eZDateTime::$IsValid

Definition at line 520 of file ezdatetime.php.

eZDateTime::$Locale

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

Definition at line 517 of file ezdatetime.php.


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