Issue Bug Closed

#79249TCA fields with eval types "time" or "timesec" are incorrectly stored in the database

Dominique Kreemers 01/10/17, 14:55 updated 10/02/18, 11:03

Description

As mentioned in the title, TCA fields with eval value “time” or “timesec” are stored incorrectly to the database in TYPO3 8.5.1.
In my setup i will get the value “1484084700” in the database if i select 23:45 for the give field.

The documentation suggests that the value will just hold the seconds from 1970-01-01 00:00:00 to the selected time:

https://docs.typo3.org/typo3cms/TCAReference/Reference/Columns/Input/Index.html#eval

The display will be like "23:45" while the database will be "85500".

In TYPO3 8.4.1 this works as expected. It seems like the changes from #77702 have changed this behaviour.

Following code block is responsible for this issue:
(/typo3/sysext/core/Classes/DataHandling/DataHandler.php @Line #2693)

case 'time':
case 'timesec':
case 'date':
case 'datetime':
    // a hyphen as first character indicates a negative timestamp
    if ((strpos($value, '-') === false && strpos($value, ':') === false) || strpos($value, '-') === 0) {
        $value = (int)$value;
    } else {
        // ISO 8601 dates
        $dateTime = new \DateTime($value);
        // The returned timestamp is always UTC
        $value = $dateTime->getTimestamp();
    }
    // $value is a UTC timestamp here.
    // The value will be stored in the server’s local timezone, but treated as UTC, so we brute force
    // subtract the offset here. The offset is subtracted instead of added because the value is stored
    // in the timezone, but interpreted as UTC, so if we switched the server to UTC, the correct
    // value would be returned.
    if ($value !== 0 && !$this->dontProcessTransformations) {
        $value -= date('Z', $value);
    }
    break;

Reviews 2