Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
This Field Type represents a date without time information.
Name | Internal name | Expected input type |
---|---|---|
Date | ezdate | mixed |
Table of contents:
Table of Contents | ||
---|---|---|
|
Description
This Field Type makes it possible to store and retrieve date information.
PHP API Field Type
Input expectations
If input value is of type string
or integer
, it will be passed directly to the PHP's built-in \DateTime
class constructor, therefore the same input format expectations apply.
It is also possible to directly pass an instance of \DateTime
.
Type | Example |
---|---|
string | "2012-08-28 12:20 Europe/Berlin" |
integer | 1346149200 |
\DateTime | new \DateTime() |
Note |
---|
Time information is not stored. Before storing, the provided input value will be set to the the beginning of the day in the given or the environment timezone. |
Value object
Properties
The Value class of this field type contains the following properties:
Property | Type | Description |
---|---|---|
$date | \DateTime | This property will be used for the text content. |
String representation
String representation of the date value will generate the date string in the format "l d F Y" as accepted by PHP's built-in date()
function.
Example:
Wednesday 22 May 2013
Constructor
The constructor for this value object will initialize a new Value object with the value provided. It accepts an instance of PHP's built-in \DateTime
class.
Hash format
Hash value of this Field Type is an array with two keys:
Key | Type | Description | Example |
---|---|---|---|
| integer | Time information as a timestamp. |
|
| string | Time information as a string in RFC 850 date format. As input, this will have higher precedence over the | "Friday, 23-May-14 14:56:14 GMT+0000" |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
$hash = array( "timestamp" => 1400856992, "rfc850" => "Friday, 23-May-14 14:56:14 GMT+0000" ); |
Validation
This Field Type does not perform any special validation of the input value.
Settings
The field definition of this Field Type can be configured with one option:
Name | Type | Default value | Description |
---|---|---|---|
defaultType | mixed | Type::DEFAULT_EMPTY | One of the See below for more details. |
Following defaultType
default value options are available as constants in the eZ\Publish\Core\FieldType\Date\Type
class:
Constant | Description |
---|---|
DEFAULT_EMPTY | Default value will be empty. |
DEFAULT_CURRENT_DATE | Default value will use current date. |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
use eZ\Publish\Core\FieldType\Date\Type; $settings = array( "defaultType" => Type::DEFAULT_EMPTY ); |
Template rendering
The template called by the ez_render_field() Twig function while rendering a Date field has access to the following parameters:
Parameter | Type | Default | Description |
---|---|---|---|
locale | string | Internal parameter set by the system based on current request locale or if not set calculated based on the language of the field. |
Example:
Code Block |
---|
{{ ez_render_field(content, 'date') }} |