diff options
author | John Layt <john@layt.net> | 2010-03-30 08:55:33 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2010-03-30 08:56:24 (GMT) |
commit | 568475d98d77c3ade027eb88e571ca8b84088002 (patch) | |
tree | 8f139c3b9b7722f572ba65b1281e6c020b59fd4c /tests/auto/qgl | |
parent | bc4fe607fe65dca24460d4f612c5815b4767e988 (diff) | |
download | Qt-568475d98d77c3ade027eb88e571ca8b84088002.zip Qt-568475d98d77c3ade027eb88e571ca8b84088002.tar.gz Qt-568475d98d77c3ade027eb88e571ca8b84088002.tar.bz2 |
Fix QDate::isLeapYear() for years < 1
The current formula for isLeapYear() assumes that years -4, -8, etc are
leap years in the Julian Calendar. This is not the case, leap years in
fact fall in -1, -5, -9, etc as there is no year 0 in the Julian
Calendar (count back 4 years from 4AD to confirm). The
julianDayFromDate() and getDateFromJulianDay() functions correctly
calculate this, but isValid() uses isLeapYear() and so causes setDate()
to incorrectly reject valid dates.
Sample test code to round-trip a jd to ymd and back to jd:
QDate testDate;
QDate loopDate = QDate::fromJulianDay(1);
while ( loopDate.toJulianDay() <= 5373484 ) { // <= 9999-12-31
testDate.setDate( loopDate.year(),
loopDate.month(),
loopDate.day() );
if ( !testDate.isValid() || loopDate != testDate ) {
qDebug() << "Round Trip failed : " <<
loopDate.toJulianDay() << " = " <<
loopDate.year() << loopDate.month() <<
loopDate.day() << " = " <<
testDate.toJulianDay();
}
loopDate.addDays(1);
}
Before the fix, 29 Feb 1 BC (year = -1) and all other BC leap days
returned by year() month() day() would result in setDate() failing.
After the fix the round trip works fine.
Merge-request: 2282
Reviewed-by: Olivier Goffart <ogoffart@trolltech.com>
Diffstat (limited to 'tests/auto/qgl')
0 files changed, 0 insertions, 0 deletions