Created
July 27, 2011 10:12
-
-
Save timendum/1109074 to your computer and use it in GitHub Desktop.
Calculate the birth date form CodiceFiscale
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static GregorianCalendar getDateFromCF(String cf) { | |
| GregorianCalendar date = new GregorianCalendar(); | |
| int anno = Integer.parseInt("19" + cf.substring(6, 8)); | |
| date.set(GregorianCalendar.YEAR, anno); | |
| int month = 0; | |
| switch (Character.toUpperCase(cf.charAt(8))) { | |
| case 'A': | |
| month = GregorianCalendar.JANUARY; | |
| break; | |
| case 'B': | |
| month = GregorianCalendar.FEBRUARY; | |
| break; | |
| case 'C': | |
| month = GregorianCalendar.MARCH; | |
| break; | |
| case 'D': | |
| month = GregorianCalendar.APRIL; | |
| break; | |
| case 'E': | |
| month = GregorianCalendar.MAY; | |
| break; | |
| case 'H': | |
| month = GregorianCalendar.JUNE; | |
| break; | |
| case 'L': | |
| month = GregorianCalendar.JULY; | |
| break; | |
| case 'M': | |
| month = GregorianCalendar.AUGUST; | |
| break; | |
| case 'P': | |
| month = GregorianCalendar.SEPTEMBER; | |
| break; | |
| case 'R': | |
| month = GregorianCalendar.OCTOBER; | |
| break; | |
| case 'S': | |
| month = GregorianCalendar.NOVEMBER; | |
| break; | |
| case 'T': | |
| month = GregorianCalendar.DECEMBER; | |
| break; | |
| default: | |
| throw new IllegalArgumentException("Mese errato: " + cf.charAt(8)); | |
| } | |
| date.set(GregorianCalendar.MONTH, month); | |
| int day = Integer.parseInt(cf.substring(9, 11)); | |
| if (day > 40) { | |
| // woman | |
| day -= 40; | |
| } | |
| date.set(GregorianCalendar.DAY_OF_MONTH, day); | |
| return date; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment