Project

General

Profile

Actions

Task #20016

open

wrong age calculating in stdWrap

Added by Vladimir Podkovanov almost 16 years ago. Updated almost 7 years ago.

Status:
New
Priority:
Should have
Category:
Frontend
Start date:
2009-02-13
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.3
Tags:
Complexity:
Sprint Focus:

Description

Function stdWrap.age assumes that year always consist of 365 days. It leads to wrong age calculations when measured in years. Since ver 4.2 we can use negative timestamps so we can store birthdays and then use stdWrap.age to render ages of people, but because of this bug ages are being shown incorectly.

(issue imported from #M10437)


Related issues 5 (0 open5 closed)

Related to TYPO3 Core - Bug #18321: wrong time value, when weekday is sunday an year is a leap yearClosed2008-02-27

Actions
Related to TYPO3 Core - Task #51628: Precise date calculation for stdWrap.ageClosed2013-09-01

Actions
Related to TYPO3 Core - Bug #23056: Rename t3lib_BEfunc::time and introduce new functionClosed2010-06-30

Actions
Related to TYPO3 Core - Task #56200: Clean up duplicated code in calcAgeClosed2014-02-21

Actions
Precedes TYPO3 Core - Task #59984: Followup for calcAge refactoringRejected2014-06-29

Actions
Actions #1

Updated by Tim Lochmüller over 15 years ago

Replace the 365 in the calcAge function with 365.2425!!!
http://en.wikipedia.org/wiki/Year#Calendar_year

This reduce the calculation mistake with very "old" calculations against 0.

Actions #2

Updated by Alexander Opitz over 11 years ago

  • Status changed from New to Needs Feedback
  • Target version deleted (0)

The issue is very old, does this issue exists in newer versions of TYPO3 CMS (4.5 or 6.1)?

Actions #3

Updated by Chris topher over 11 years ago

  • Status changed from Needs Feedback to Accepted
  • TYPO3 Version changed from 4.2 to 6.1
  • Complexity set to easy

Tim Lochmüller wrote:

Replace the 365 in the calcAge function with 365.2425!!!

This is still unchanged in ContentObjectRenderer.php.

Actions #4

Updated by Gerrit Code Review about 11 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/23508

Actions #5

Updated by Vladimir Podkovanov about 11 years ago

Tim Lochmüller wrote:

Replace the 365 in the calcAge function with 365.2425!!!
http://en.wikipedia.org/wiki/Year#Calendar_year

This doesn't solve the bug, as around birthday date the age would be rendered incorrectly, so it is still useless for displaying age of people.
For example if current year is leap year then age rendered by stdWrap.age will increase a day before than actual birthday.
So, to correctly fix that should be used PHP date time functions working with actual calendar.

Actions #6

Updated by Alexander Opitz about 11 years ago

  • Status changed from Under Review to New
  • Assignee set to Ernesto Baschny
  • Complexity deleted (easy)

This function calculates the age for given seconds, so you don't have the qualified dates for that calculation. So the function don't know when there is a leap year or leap seconds.
The calculation is enough for what it is used inside the core.

The function exists as
- TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::calcAge
- TYPO3\CMS\Backend\Utility\BackendUtility::calcAge

To get the wanted functionality we should implement one new function with an other parameter structure and use DateTime diff. The old functions could be deprecated then.

@Ernesto would you vote for the change? If yes, where to put this one function?

Actions #7

Updated by Vladimir Podkovanov about 11 years ago

Alexander Opitz wrote:

This function calculates the age for given seconds, so you don't have the qualified dates for that calculation. So the function don't know when there is a leap year or leap seconds.

Not really. The function uses date in form of UNIX timestamp not just period of time in seconds.
From TSref:

If enabled with a "1" (number, integer) the content is seen as a date (UNIX-time) and the difference from present time and the content-time is returned as one of these eight variations:

Since TYPO3 allows negative timestamps then the age function can be used to display age of people too, if not this bug.

UPDATE: I understood you now, you are talking about calcAge() function and I'm about stdWrap's age function.
In this case I think better not to use calcAge() in stdWrap's age calculation, as it is not working with dates.
The bug itself is about stdWrap's age.

Actions #8

Updated by Alexander Opitz about 11 years ago

So the problem is the function:

    public function stdWrap_age($content = '', $conf = array()) {
        $content = $this->calcAge($GLOBALS['EXEC_TIME'] - $content, $conf['age']);
        return $content;
    }

It only gives the seconds of difference to the real calculation function. So we should solve this with my given proposal.

Actions #9

Updated by Alexander Opitz about 11 years ago

  • Tracker changed from Bug to Task

From #51628

A suggestion from Phillip Gampe:
... should refactor the method to use DateTime->diff(), which should be accurate, but does only exists for PHP 5.3. Thus it cannot go into 4.5.
@see http://stackoverflow.com/a/3923228/1234469
I would even suggest that you turn this "bug" into a TASK and we submit this only to 6.2 with the subject "Precise date calculation for stdWrap.age". This should be covered with unit tests of course (which in this case a really simple, because we do not need mocking).
Actions #10

Updated by Ernesto Baschny about 11 years ago

  • Status changed from New to Accepted
  • Target version set to 6.2.0

Sounds like a nice idea and using DateTime object would be the way to go. PHP 5.3 and TYPO3 6.2 fits.

A central "calcAge" method (with a better name maybe) could be placed in a new core\Utility\DateTimeUtility which could also hold GeneralUtility::convertMicrotime and GeneralUtility::milliseconds

Actions #11

Updated by Alexander Opitz about 11 years ago

@Ernesto
As you are assigned, do you want to do this?

Actions #12

Updated by Ernesto Baschny about 11 years ago

  • Category set to Content Rendering
  • Assignee deleted (Ernesto Baschny)

I would want to, but won't have the time. I didn't assign it to myself, you did that. :)

Actions #13

Updated by Alexander Opitz about 11 years ago

  • Assignee set to Alexander Opitz

Ohh shame on me. :)

Actions #14

Updated by Alexander Opitz about 11 years ago

Another problem is the rounding on some parts, so it is possible that after 1,5 years the value 2 years is shown.

Actions #15

Updated by Gerrit Code Review about 11 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #16

Updated by Gerrit Code Review about 11 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #17

Updated by Gerrit Code Review about 11 years ago

Patch set 3 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #18

Updated by Gerrit Code Review about 11 years ago

Patch set 4 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #19

Updated by Gerrit Code Review about 11 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #20

Updated by Gerrit Code Review over 10 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #21

Updated by Gerrit Code Review over 10 years ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #22

Updated by Gerrit Code Review over 10 years ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #23

Updated by Gerrit Code Review over 10 years ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #24

Updated by Gerrit Code Review over 10 years ago

Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #25

Updated by Gerrit Code Review over 10 years ago

Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #26

Updated by Gerrit Code Review over 10 years ago

Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #27

Updated by Gerrit Code Review over 10 years ago

Patch set 13 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #28

Updated by Gerrit Code Review over 10 years ago

Patch set 14 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #29

Updated by Gerrit Code Review over 10 years ago

Patch set 15 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #30

Updated by Gerrit Code Review over 10 years ago

Patch set 16 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #31

Updated by Gerrit Code Review over 10 years ago

Patch set 17 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #32

Updated by Gerrit Code Review over 10 years ago

Patch set 18 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #33

Updated by Gerrit Code Review over 10 years ago

Patch set 19 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/24635

Actions #34

Updated by Gerrit Code Review over 10 years ago

Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/31231

Actions #35

Updated by Alexander Opitz over 10 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #36

Updated by Helmut Hummel over 10 years ago

  • Status changed from Resolved to Accepted
  • Target version changed from 6.2.0 to next-patchlevel
  • TYPO3 Version changed from 6.1 to 6.2
Actions #37

Updated by Gerrit Code Review over 10 years ago

  • Status changed from Accepted 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/31242

Actions #38

Updated by Gerrit Code Review over 10 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/31242

Actions #39

Updated by Mathias Schreiber almost 10 years ago

  • Target version changed from next-patchlevel to 7.2 (Frontend)
Actions #40

Updated by Alexander Opitz over 9 years ago

  • Status changed from Under Review to In Progress
  • Target version changed from 7.2 (Frontend) to 7.5
Actions #41

Updated by Gerrit Code Review over 9 years ago

  • Status changed from In Progress to Under Review

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/31242

Actions #42

Updated by Gerrit Code Review about 9 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/31242

Actions #43

Updated by Benni Mack about 9 years ago

  • Target version changed from 7.5 to 7 LTS
Actions #44

Updated by Alexander Opitz about 9 years ago

  • Target version changed from 7 LTS to 8 LTS

Still no information about utility vs. service, so this won't made it before feature freeze for 7 LTS.

Actions #45

Updated by Anja Leichsenring almost 8 years ago

  • Status changed from Under Review to Closed
Actions #46

Updated by Alexander Opitz almost 8 years ago

  • Status changed from Closed to Under Review

The state of this issue isn't changed.

Actions #47

Updated by Benni Mack over 7 years ago

  • Target version changed from 8 LTS to Candidate for Major Version
Actions #48

Updated by Susanne Moog about 7 years ago

  • Category changed from Content Rendering to Frontend
Actions #49

Updated by Alexander Opitz almost 7 years ago

  • Status changed from Under Review to New
  • % Done changed from 100 to 0

With #83171 intl support was integrated, so we can do this patches with intl support.

Actions

Also available in: Atom PDF