[Korganizer-devel] [Bug 227666] wrong age calculation for birth year 1961 in 2010, 2011 and 2012

John Layt john at layt.net
Mon Feb 22 19:58:26 CET 2010


https://bugs.kde.org/show_bug.cgi?id=227666


John Layt <john at layt.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john at layt.net




--- Comment #2 from John Layt <john layt net>  2010-02-22 19:57:55 ---
The problem lies in the following code:

qint64 KOHelper::yearDiff( const QDate &start, const QDate &end )
{
  return static_cast<qint64>( start.daysTo( end ) / 365.25 );
}

In case 1 above this gives

( 19 Feb 2010 - 19 Feb 1961 ) / 365.25
= ( 2455246 - 2437349 ) / 365.25
= 17897 / 365.25
= 48.9993
= 48

When obviously it should be 49.  you could add a few more days on to the end
date to fix the rounding, or do it properly:

if ( end.month() > start.month() ||
    ( end.month() == start.month() &&
      end.day() > start.day() ) {
    end.year() - start.year();
} else {
    end.year() - start.year() - 1;
}

I should probably provide KCalendarSystem methods to do this.

This assumes a standard rule for date maths that if the end month has fewer
days than the start month you move to the last day of the same month.  So a
birthday on the 29th Feb will be moved to 28th Feb, which is the law in the UK.

I think KOrganizer follows the day of year rule, i.e. always falls on day 60 so
would be 1st March in non-leap years, which would be wrong in the UK context at
least.

Don't even get me started on rules for moving Hebrew birthdays, those rules
blow my mind :-)

Also it doesn't localise the calendar system either, but that seems widespread
throughout KOrganizer, there's a lot of inconsistencies as a result if the user
has a non-Gregorian system calendar selected. Perhaps KO should always force to
run in Gregorian for now, especially as iCalendar only supports Gregorian?

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Korganizer-devel mailing list