Skip to content

Enhance data input to clear certain parts of the timestamp. #27

@discordier

Description

@discordier

Issue description

When editing timestamps with formats where parts are missing (Year, day, month, hour, minute, second), PHP does initialize it with the current time() value.
This is correct and good from PHP side, as formats like +1 week are perfectly legal and useful, yet it will break our filtering.

So we need some way to restrict time or date to "zero" in order to allow valid filtering and omit hickups like discussed in MetaModels/filter_fromto#9.

Proposed solution

The idea I had is to add some input screen configuration setting where the user can select one of three possible settings:

  1. do nothing (default and current behaviour)
  2. clear data part (will restrict the date to 01.01.1970 internally).
  3. clear time part (will restrict the time to 00:00:00 internally).

I'd put this setting into the input screen definition of the attribute instance to allow variation of this in the concrete input screens.

Implementation would then be to change the current implementation something along the lines of:

    public function handleEncodePropertyValueFromWidget(EncodePropertyValueFromWidgetEvent $event)
    {
        $attribute = $this->getSupportedAttribute($event);
        if (!$attribute) {
            return;
        }

        $date       = \DateTime::createFromFormat($attribute->getDateTimeFormatString(), $event->getValue());
        $properties = $event->getEnvironment()->getDataDefinition()->getPropertiesDefinition();
        $property   = $properties->getProperty($event->getProperty());
        $extra      = $property->getExtra();
        if (isset($extra['clear'])) {
            switch ($extra['clear']) {
                case 'time':
                    $date->setTime(0, 0, 0);
                    break;
                case 'date':
                    $date->setDate(0, 0, 0);
                    break;
                default:
            }
        }

        if ($date) {
            $event->setValue($date->getTimestamp());
        }
    }

Of course we would also have to add such setting to the fromto filter regarding dates, as otherwise date filtering would begin and end "now" and therefore might not find items due to the offset.

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions