Project

General

Profile

Actions

Bug #79975

closed

TCA -> input -> eval: 'time' not relative timestamp

Added by Mario Matzulla about 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Backend User Interface
Target version:
-
Start date:
2017-02-23
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

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

diff.txt (2.32 KB) diff.txt Mario Matzulla, 2017-03-03 15:19
patch.txt (2.83 KB) patch.txt Mario Matzulla, 2017-03-03 16:12

Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #79730: Fix date related acceptance testsClosed2017-02-10

Actions
Is duplicate of TYPO3 Core - Bug #79249: TCA fields with eval types "time" or "timesec" are incorrectly stored in the databaseClosedMarkus Klein2017-01-10

Actions
Actions #1

Updated by Mario Matzulla about 7 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!

Actions #2

Updated by Mario Matzulla about 7 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;
Actions #3

Updated by Josef Glatz about 7 years ago

  • Description updated (diff)
Actions #4

Updated by Mario Matzulla about 7 years ago

Here a diff of my changes

Actions #5

Updated by Mario Matzulla about 7 years ago

and here a patch

Actions #6

Updated by Gerrit Code Review about 7 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

Actions #7

Updated by Gerrit Code Review about 7 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

Actions #8

Updated by Gerrit Code Review about 7 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

Actions #9

Updated by Gerrit Code Review about 7 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

Actions #10

Updated by Gerrit Code Review about 7 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

Actions #11

Updated by Mario Matzulla about 7 years ago

  • Target version set to 8 LTS
Actions #12

Updated by Mona Muzaffar about 7 years ago

  • Related to Epic #80852: Datetime handling in backend added
Actions #13

Updated by Benni Mack almost 7 years ago

  • Target version changed from 8 LTS to next-patchlevel
Actions #14

Updated by Markus Klein almost 7 years ago

  • Parent task set to #81489
Actions #15

Updated by Markus Klein almost 7 years ago

  • Parent task changed from #81489 to #77562
Actions #16

Updated by Markus Klein almost 7 years ago

  • Status changed from Under Review to Closed
  • Target version deleted (next-patchlevel)

Closing this as duplicate of #79249

Actions #17

Updated by Markus Klein almost 7 years ago

  • Is duplicate of Bug #79249: TCA fields with eval types "time" or "timesec" are incorrectly stored in the database added
Actions #18

Updated by Markus Klein almost 7 years ago

  • Related to deleted (Epic #80852: Datetime handling in backend)
Actions #19

Updated by Markus Klein almost 7 years ago

  • Parent task deleted (#77562)
Actions

Also available in: Atom PDF