Comment 104 for bug 1530670

Revision history for this message
Daniel (hackie) wrote :

I believe it's wrong to fix the bug in a way which lets the same error popping up again in 16 years.

I would write something like this:

    return QDateTime(
        QDate(
          ((QDate::currentDate().year() + 4 - ((date >> 20) & 0xf)) & 0xfff0) + ((date >> 20) & 0xf),
          (date >> 16) & 0xf,
          (date >> 11) & 0x1f),
        QTime((date >> 6) & 0x1f, date & 0x3f, sec / 1000, sec % 1000),
        Qt::UTC);

(didn't compile this snippet)

It will always calculate the GPS year relative to the current system date, 12 years to the past and 4 years to the future. In other words: 0 will be interpreted as 2016 in the years 2012..2027. When run in 2028 (and his GPS is still alive) it will be interpreted as 2032 etc.