Move AAMVA age calculation into CardDetect
authorJeffrey Malone <ieatlint@tehinterweb.com>
Sat, 6 Nov 2010 22:47:18 +0000 (15:47 -0700)
committerJeffrey Malone <ieatlint@tehinterweb.com>
Sat, 6 Nov 2010 22:47:18 +0000 (15:47 -0700)
carddetect.cpp
magcard.h
magread.cpp

index 58473a4..1e0aacb 100644 (file)
@@ -195,6 +195,12 @@ void CardDetect::aamvaCardCheck( QString expDate ) {
        }
        card->aamvaBirthday = QDate::fromString( bday, "yyyyMMdd" );
 
        }
        card->aamvaBirthday = QDate::fromString( bday, "yyyyMMdd" );
 
+       //set the age
+       /* FIXME a leap year can offset this by a day ... */
+       card->aamvaAge = QDate::currentDate().year() - card->aamvaBirthday.year();
+       if( card->aamvaBirthday.dayOfYear() > QDate::currentDate().dayOfYear() )
+               card->aamvaAge--;
+
        //set the expiration date
        if( expDate.endsWith( "99" ) ) { // expires on the birth day and month in the given year
                expDate.replace( 2, 4, bday.mid( 4, 4 ) );
        //set the expiration date
        if( expDate.endsWith( "99" ) ) { // expires on the birth day and month in the given year
                expDate.replace( 2, 4, bday.mid( 4, 4 ) );
index cfa4d37..8febfb5 100644 (file)
--- a/magcard.h
+++ b/magcard.h
@@ -56,6 +56,7 @@ class MagCard {
                QString aamvaIssuerName;
                QString aamvaIssuerAbr;
                QDate aamvaBirthday;
                QString aamvaIssuerName;
                QString aamvaIssuerAbr;
                QDate aamvaBirthday;
+               int aamvaAge;
 
                MagCard() {
                        encoding = UNSET;
 
                MagCard() {
                        encoding = UNSET;
index 71a7199..30dab66 100644 (file)
@@ -191,17 +191,11 @@ void MagRead::aamvaPage() {
        /* Calculate the age */
        QDate curDate = QDate::currentDate();
 
        /* Calculate the age */
        QDate curDate = QDate::currentDate();
 
-       /* FIXME a leap year can offset this by a day ... */
-       int age = QDate::currentDate().year() - card.aamvaBirthday.year();
-       if( card.aamvaBirthday.dayOfYear() > QDate::currentDate().dayOfYear() ) {
-               age--;
-       }
-
-       QString ageStr = QString ( "<span style=\"font-size:32pt;\">Age %1 </span>" ).arg( age );
-       if( age < 18 ) {
+       QString ageStr = QString ( "<span style=\"font-size:32pt;\">Age %1 </span>" ).arg( card.aamvaAge );
+       if( card.aamvaAge < 18 ) {
                ageStr.prepend( "<font color=\"red\">" );
                ageStr.append( "</font>" );
                ageStr.prepend( "<font color=\"red\">" );
                ageStr.append( "</font>" );
-       } else if( age < 21 ) {
+       } else if( card.aamvaAge < 21 ) {
                ageStr.prepend( "<font color=\"yellow\">" );
                ageStr.append( "</font>" );
        }
                ageStr.prepend( "<font color=\"yellow\">" );
                ageStr.append( "</font>" );
        }