Issue Task Closed

#20016wrong age calculating in stdWrap

Vladimir Podkovanov 02/13/09, 17:23 updated 12/02/25, 14:36

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)

Reviews 8

History 2661

Show 1536 earlier messages
  1. Tim Lochmüller commented <span data-processor="relativetime" data-value="2009-05-16T14:30:43+00:00" > 05/16/09, 14:30 </span>

    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.

  2. Alexander Opitz commented and changed status New Needs Feedback target version <span data-processor="relativetime" data-value="2013-05-08T10:34:19+00:00" > 05/08/13, 10:34 </span>

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

  3. Chris topher commented and changed status Needs Feedback Accepted TYPO3 Version 4.2 6.1 Complexity easy <span data-processor="relativetime" data-value="2013-05-08T14:22:07+00:00" > 05/08/13, 14:22 </span>

    Tim Lochmüller wrote:
    > Replace the 365 in the calcAge function with 365.2425!!!

    This is still unchanged in ContentObjectRenderer.php.

  4. Gerrit Code Review changed status Accepted Under Review <span data-processor="relativetime" data-value="2013-08-31T12:13:00+00:00" > 08/31/13, 12:13 </span> Patch set 1 for branch *master* has been pushed to the review server. It is available at https://review.typo3.org/23508

  5. Vladimir Podkovanov commented <span data-processor="relativetime" data-value="2013-08-31T13:59:11+00:00" > 08/31/13, 13:59 </span>

    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.

  6. Alexander Opitz commented and changed status Under Review New assigned to Ernesto Baschny Complexity easy <span data-processor="relativetime" data-value="2013-09-02T11:35:08+00:00" > 09/02/13, 11:35 </span>

    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?

  7. Vladimir Podkovanov commented <span data-processor="relativetime" data-value="2013-09-02T12:16:19+00:00" > 09/02/13, 12:16 </span>

    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.

  8. Alexander Opitz commented <span data-processor="relativetime" data-value="2013-09-02T15:51:54+00:00" > 09/02/13, 15:51 </span>

    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.

  9. Alexander Opitz commented and changed tracker Bug Task <span data-processor="relativetime" data-value="2013-09-02T15:56:45+00:00" > 09/02/13, 15:56 </span>

    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).
  10. Ernesto Baschny commented and changed status New Accepted target version <span data-processor="relativetime" data-value="2013-09-02T17:24:00+00:00" > 09/02/13, 17:24 </span>

    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

  11. Alexander Opitz commented <span data-processor="relativetime" data-value="2013-09-12T10:52:38+00:00" > 09/12/13, 10:52 </span>

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

  12. Ernesto Baschny commented and changed category removed the assignee <span data-processor="relativetime" data-value="2013-09-12T13:46:37+00:00" > 09/12/13, 13:46 </span>

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

  13. Alexander Opitz commented and changed assigned to Alexander Opitz <span data-processor="relativetime" data-value="2013-09-12T14:00:03+00:00" > 09/12/13, 14:00 </span>

    Ohh shame on me. :)

  14. Alexander Opitz commented <span data-processor="relativetime" data-value="2013-10-12T15:49:01+00:00" > 10/12/13, 15:49 </span>

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

  15. Gerrit Code Review changed status Accepted Under Review <span data-processor="relativetime" data-value="2013-10-12T17:55:17+00:00" > 10/12/13, 17:55 </span> Patch set 1 for branch *master* has been pushed to the review server. It is available at https://review.typo3.org/24635

  16. Gerrit Code Review <span data-processor="relativetime" data-value="2013-10-12T20:11:49+00:00" > 10/12/13, 20:11 </span> Patch set 2 for branch *master* has been pushed to the review server. It is available at https://review.typo3.org/24635

  17. Gerrit Code Review <span data-processor="relativetime" data-value="2013-10-13T13:44:59+00:00" > 10/13/13, 13:44 </span> Patch set 3 for branch *master* has been pushed to the review server. It is available at https://review.typo3.org/24635

  18. Gerrit Code Review <span data-processor="relativetime" data-value="2013-10-22T00:49:48+00:00" > 10/22/13, 00:49 </span> Patch set 4 for branch *master* has been pushed to the review server. It is available at https://review.typo3.org/24635

  19. Alexander Opitz commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2014-06-29T18:30:28+00:00" > 06/29/14, 18:30 </span>

    Applied in changeset commit:4c52cb3cfe4f6819a29f1daa064859affe23989d.

  20. Helmut Hummel commented and changed status Resolved Accepted target version TYPO3 Version 6.1 6.2 <span data-processor="relativetime" data-value="2014-06-29T23:34:47+00:00" > 06/29/14, 23:34 </span>

  1. Gerrit Code Review pushed patch set 1 for master to change 31242 status Accepted Under Review <span data-processor="relativetime" data-value="2014-06-30T11:45:12+00:00" > 06/30/14, 11:45 </span>

  2. Gerrit Code Review <span data-processor="relativetime" data-value="2014-08-03T20:14:49+00:00" > 08/03/14, 20:14 </span> 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

  3. Alexander Opitz changed status Under Review In Progress target version <span data-processor="relativetime" data-value="2015-06-10T14:19:30+00:00" > 06/10/15, 14:19 </span>

  4. Gerrit Code Review changed status In Progress Under Review <span data-processor="relativetime" data-value="2015-07-17T10:06:03+00:00" > 07/17/15, 10:06 </span> 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

  5. Gerrit Code Review <span data-processor="relativetime" data-value="2015-08-26T14:26:49+00:00" > 08/26/15, 14:26 </span> 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

  6. Alexander Opitz commented and changed target version <span data-processor="relativetime" data-value="2015-10-06T16:06:11+00:00" > 10/06/15, 16:06 </span>

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

  7. Alexander Opitz commented and changed status Closed Under Review <span data-processor="relativetime" data-value="2016-12-31T20:05:08+00:00" > 12/31/16, 20:05 </span>

    The state of this issue isn’t changed.

  8. Alexander Opitz commented and changed status Under Review New done 100 % 0 % <span data-processor="relativetime" data-value="2017-11-30T14:25:30+00:00" > 11/30/17, 14:25 </span>

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

  9. Benjamin Franzke commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-04-24T06:10:10+00:00" > 04/24/25, 06:10 </span>

    Applied in changeset commit:f79db3e8ee1f8e035f2f3446f8666cabec2780c4.