Issue Bug Closed

#79557Date fields DataMapper handling problem

Oliver Pfaff 01/30/17, 15:47 updated 12/02/25, 14:36

Description

Hello everybody,
the handling of date fields seems incorrect in \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper here we have(without the debugs :) ):

 if (!is_null($columnMap) && !is_null($columnMap->getDateTimeStorageFormat())) {
                $storageFormat = $columnMap->getDateTimeStorageFormat();
                $timeZoneToStore = clone $input;
                DebuggerUtility::var_dump($timeZoneToStore,'datetime in mapper after clone');
                // set to UTC to store in database
                $timeZoneToStore->setTimezone(new \DateTimeZone('UTC'));
                DebuggerUtility::var_dump($timeZoneToStore,'datetime after timezone switch');
                switch ($storageFormat) {
                    case 'datetime':
                        $parameter = $timeZoneToStore->format('Y-m-d H:i:s');
                        break;
                    case 'date':
                        $parameter = $timeZoneToStore->format('Y-m-d');
                        DebuggerUtility::var_dump($parameter,'formatted date parameter');
                        break;
                    default:
                        throw new \InvalidArgumentException('Column map DateTime format "' . $storageFormat . '" is unknown. Allowed values are datetime or date.', 1395353470);
                }

Now i have a date field in a form, where only the date is stored, the time part is 00:00:00.
Im from Germany and my datetime has the timezone +1. After the UTC switch i have the time 23:00:00 from the day before and this date will go to the DB.
When we get the value from the DB extbase will add my timezone but unfortunately to the wrong date :D

You can see the debugs from the code in the attached screenshot.

Reviews 1