Bug #79975
closedTCA -> input -> eval: 'time' not relative timestamp
0%
Description
Hi,
any 'time' field in my extension (cal) produces absolute timestamps, not relative like described: The display will be like "23:45" while the database will be "85500"
I'm getting: 1487886300
My tca:
'start_time' => array( 'exclude' => 1, 'label' => 'LLL:EXT:cal/Resources/Private/Language/locallang_db.xml:tx_cal_event.start_time', 'displayCond' => 'FIELD:allday:!=:1', 'config' => array( 'type' => 'input', 'size' => '12', 'max' => '20', 'eval' => 'time', 'default' => '0' ) ),
Files
Updated by Mario Matzulla almost 8 years ago
I think the faulty code is located in \TYPO3\CMS\Core\DataHandling\DataHandler
public function checkValue_input_Eval($value, $evalArray, $is_in) {
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;
You can NOT handle all those eval values the same way. The input '23:45' with 'time' will produce a timestamp for the current day and not a relative one!
Updated by Mario Matzulla almost 8 years ago
This fixes the issue (tested for 'time'):
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 {
switch ($func) {
case 'time':
$valueArr = explode(':', $value);
$value = $valueArr0 * 3600 + $valueArr1 * 60;
break;
case 'timesec':
$valueArr = explode(':', $value);
$value = $valueArr0 * 3600 + $valueArr1 * 60 + $valueArr2;
break;
case 'date':
case 'datetime':
// 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;
}
}
break;
Updated by Mario Matzulla almost 8 years ago
Here a diff of my changes
Updated by Mario Matzulla almost 8 years ago
and here a patch
Updated by Gerrit Code Review almost 8 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51964
Updated by Gerrit Code Review almost 8 years ago
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51966
Updated by Gerrit Code Review almost 8 years ago
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51970
Updated by Gerrit Code Review almost 8 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51970
Updated by Gerrit Code Review almost 8 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51970
Updated by Mona Muzaffar almost 8 years ago
- Related to Epic #80852: Datetime handling in backend added
Updated by Benni Mack almost 8 years ago
- Target version changed from 8 LTS to next-patchlevel
Updated by Markus Klein over 7 years ago
- Parent task changed from #81489 to #77562
Updated by Markus Klein over 7 years ago
- Status changed from Under Review to Closed
- Target version deleted (
next-patchlevel)
Closing this as duplicate of #79249
Updated by Markus Klein over 7 years ago
- Is duplicate of Bug #79249: TCA fields with eval types "time" or "timesec" are incorrectly stored in the database added
Updated by Markus Klein over 7 years ago
- Related to deleted (Epic #80852: Datetime handling in backend)