Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DateTime.php

class DateTime

Same name in this branch
  1. 11.1.x core/lib/Drupal/Core/Datetime/Element/Datetime.php \Drupal\Core\Datetime\Element\Datetime

Validates that a value is a valid "datetime" according to a given format.

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

  • class \Symfony\Component\Validator\Constraint
    • class \Symfony\Component\Validator\Constraints\DateTime extends \Symfony\Component\Validator\Constraint

Expanded class hierarchy of DateTime

See also

https://www.php.net/manual/en/datetime.format.php

19 string references to 'DateTime'
DateField::defineValueProcessPipeline in core/modules/datetime/src/Plugin/migrate/field/DateField.php
Apply any custom processing to the field bundle migrations.
DateField::getFieldType in core/modules/datetime/src/Plugin/migrate/field/DateField.php
Computes the destination type of a migrated field.
datetime.info.yml in core/modules/datetime/datetime.info.yml
core/modules/datetime/datetime.info.yml
datetime.migrate_drupal.yml in core/modules/datetime/migrations/state/datetime.migrate_drupal.yml
core/modules/datetime/migrations/state/datetime.migrate_drupal.yml
Datetime::getHtml5DateFormat in core/lib/Drupal/Core/Datetime/Element/Datetime.php
Retrieves the right format for an HTML5 date element.

... See full list

File

vendor/symfony/validator/Constraints/DateTime.php, line 23

Namespace

Symfony\Component\Validator\Constraints
View source
class DateTime extends Constraint {
    public const INVALID_FORMAT_ERROR = '1a9da513-2640-4f84-9b6a-4d99dcddc628';
    public const INVALID_DATE_ERROR = 'd52afa47-620d-4d99-9f08-f4d85b36e33c';
    public const INVALID_TIME_ERROR = '5e797c9d-74f7-4098-baa3-94390c447b27';
    protected const ERROR_NAMES = [
        self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR',
        self::INVALID_DATE_ERROR => 'INVALID_DATE_ERROR',
        self::INVALID_TIME_ERROR => 'INVALID_TIME_ERROR',
    ];
    public string $format = 'Y-m-d H:i:s';
    public string $message = 'This value is not a valid datetime.';
    
    /**
     * @param non-empty-string|array<string,mixed>|null $format  The datetime format to match (defaults to 'Y-m-d H:i:s')
     * @param string[]|null                             $groups
     * @param array<string,mixed>                       $options
     */
    public function __construct(string|array|null $format = null, ?string $message = null, ?array $groups = null, mixed $payload = null, array $options = []) {
        if (\is_array($format)) {
            $options = array_merge($format, $options);
        }
        elseif (null !== $format) {
            $options['value'] = $format;
        }
        parent::__construct($options, $groups, $payload);
        $this->message = $message ?? $this->message;
    }
    public function getDefaultOption() : ?string {
        return 'format';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Constraint::$groups public property The groups that the constraint belongs to.
Constraint::$payload public property Domain-specific data attached to a constraint.
Constraint::addImplicitGroupName public function Adds the given group if this constraint is in the Default group. 2
Constraint::CLASS_CONSTRAINT public constant Marks a constraint that can be put onto classes.
Constraint::DEFAULT_GROUP public constant The name of the group given to all constraints with no explicit group.
Constraint::getErrorName public static function Returns the name of the given error code.
Constraint::getRequiredOptions public function Returns the name of the required options. 22
Constraint::getTargets public function Returns whether the constraint can be put onto classes, properties or
both.
8
Constraint::normalizeOptions protected function
Constraint::PROPERTY_CONSTRAINT public constant Marks a constraint that can be put onto properties.
Constraint::validatedBy public function Returns the name of the class that validates this constraint. 9
Constraint::__get public function Returns the value of a lazily initialized option. 2
Constraint::__isset public function 1
Constraint::__set public function Sets the value of a lazily initialized option. 1
Constraint::__sleep public function Optimizes the serialized value to minimize storage space.
DateTime::$format public property
DateTime::$message public property
DateTime::ERROR_NAMES protected constant Maps error codes to the names of their constants. Overrides Constraint::ERROR_NAMES
DateTime::getDefaultOption public function Returns the name of the default option. Overrides Constraint::getDefaultOption
DateTime::INVALID_DATE_ERROR public constant
DateTime::INVALID_FORMAT_ERROR public constant
DateTime::INVALID_TIME_ERROR public constant
DateTime::__construct public function Overrides Constraint::__construct
RSS feed
Powered by Drupal