Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
eZDateTime Class Reference
Locale system

Locale aware date and time handler. More...

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

## Static Public Member Functions
static | currentTimeStamp ()
static | create ( $hour=-1, $minute=-1, $second=-1, $month=-1, $day=-1, $year=-1)

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

## 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'
eZDateTime
Locale aware date and time handler.
Definition: ezdatetime.php:62
eZDateTime\create
static create( $hour=-1, $minute=-1, $second=-1, $month=-1, $day=-1, $year=-1)
Definition: ezdatetime.php:451
eZLocale\instance
static instance( $localeString=false)
Definition: ezlocale.php:1536

See also
  eZDate, eZTime, eZLocale

Definition at line 61 of file ezdatetime.php.

## Constructor & Destructor Documentation

## ◆ __construct()

eZDateTime::__construct | ( |  | $datetime = `false` | ) |

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

Parameters

  eZDate | eZTime | bool | $datetime |

Definition at line 68 of file ezdatetime.php.

References eZLocale\instance().

## Member Function Documentation

## ◆ adjustDateTime()

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

## ◆ attribute()

eZDateTime::attribute | ( |  | $name | ) |

Definition at line 111 of file ezdatetime.php.

References day(), hour(), isValid(), minute(), month(), second(), timeStamp(), eZDebug\writeError(), and year().

## ◆ attributes()

eZDateTime::attributes | ( |  | ) |

Definition at line 94 of file ezdatetime.php.

Referenced by hasAttribute().

## ◆ create()

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

## ◆ currentTimeStamp()

static eZDateTime::currentTimeStamp | ( |  | ) |
| static

Returns the current date and time as a UNIX timestamp

Definition at line 203 of file ezdatetime.php.

Referenced by eZContentFunctions\createAndPublishObject().

## ◆ day()

eZDateTime::day | ( |  | ) |

Returns the day element.

Definition at line 249 of file ezdatetime.php.

Referenced by attribute().

## ◆ duplicate()

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

## ◆ hasAttribute()

eZDateTime::hasAttribute | ( |  | $name | ) |

Definition at line 106 of file ezdatetime.php.

References attributes().

## ◆ hour()

eZDateTime::hour | ( |  | ) |

Returns the hour element.

Definition at line 257 of file ezdatetime.php.

Referenced by attribute().

## ◆ isEqualTo()

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

References timeStamp(), toDate(), and toTime().

## ◆ isGreaterThan()

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

References timeStamp(), toDate(), and toTime().

## ◆ isValid()

eZDateTime::isValid | ( |  | ) |

Returns
  true if the date has valid data.

Definition at line 155 of file ezdatetime.php.

References $IsValid.

Referenced by attribute().

## ◆ locale()

eZDateTime::locale | ( |  | ) |

Returns the current locale.

Definition at line 171 of file ezdatetime.php.

References $Locale.

## ◆ minute()

eZDateTime::minute | ( |  | ) |

Returns the minute element.

Definition at line 265 of file ezdatetime.php.

Referenced by attribute().

## ◆ month()

eZDateTime::month | ( |  | ) |

Returns the month element.

Definition at line 241 of file ezdatetime.php.

Referenced by attribute().

## ◆ second()

eZDateTime::second | ( |  | ) |

Returns the second element.

Definition at line 273 of file ezdatetime.php.

Referenced by attribute().

## ◆ setDay()

eZDateTime::setDay | ( |  | $day | ) |

Sets the day leaving the other elements untouched.

Definition at line 301 of file ezdatetime.php.

## ◆ setHMS()

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

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

Definition at line 341 of file ezdatetime.php.

## ◆ setHour()

eZDateTime::setHour | ( |  | $hour | ) |

Sets the hour leaving the other elements untouched.

Definition at line 311 of file ezdatetime.php.

## ◆ setLocale()

eZDateTime::setLocale | ( |  | $locale | ) |

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

Definition at line 163 of file ezdatetime.php.

## ◆ setMDY()

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

## ◆ setMDYHMS()

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

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

Definition at line 351 of file ezdatetime.php.

## ◆ setMinute()

eZDateTime::setMinute | ( |  | $min | ) |

Sets the minute leaving the other elements untouched.

Definition at line 321 of file ezdatetime.php.

## ◆ setMonth()

eZDateTime::setMonth | ( |  | $month | ) |

Sets the month leaving the other elements untouched.

Definition at line 291 of file ezdatetime.php.

## ◆ setSecond()

eZDateTime::setSecond | ( |  | $sec | ) |

Sets the second leaving the other elements untouched.

Definition at line 331 of file ezdatetime.php.

## ◆ setTimeStamp()

eZDateTime::setTimeStamp | ( |  | $stamp | ) |

Definition at line 193 of file ezdatetime.php.

## ◆ setYear()

eZDateTime::setYear | ( |  | $year | ) |

Sets the year leaving the other elements untouched.

Definition at line 281 of file ezdatetime.php.

## ◆ timeStamp()

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

References $DateTime.

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

## ◆ timeZone()

eZDateTime::timeZone | ( |  | ) |

Returns the current time zone.

Definition at line 179 of file ezdatetime.php.

## ◆ toDate()

eZDateTime::toDate | ( |  | ) |

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

Definition at line 212 of file ezdatetime.php.

Referenced by isEqualTo(), and isGreaterThan().

## ◆ toString()

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

## ◆ toTime()

eZDateTime::toTime | ( |  | ) |

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

Definition at line 223 of file ezdatetime.php.

Referenced by isEqualTo(), and isGreaterThan().

## ◆ year()

eZDateTime::year | ( |  | ) |

Returns the year element.

Definition at line 233 of file ezdatetime.php.

Referenced by attribute().

## Member Data Documentation

## ◆ $DateTime

eZDateTime::$DateTime

The current datetime as a timestamp.

Definition at line 498 of file ezdatetime.php.

Referenced by timeStamp().

## ◆ $IsValid

eZDateTime::$IsValid

Definition at line 499 of file ezdatetime.php.

Referenced by isValid().

## ◆ $Locale

eZDateTime::$Locale

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

Definition at line 496 of file ezdatetime.php.

Referenced by locale().

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

- ezdatetime.php

Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.