Dr. Domenico Giacomo Campanile

Sviluppatore App Web e Mobile

Calculate gender and date of birth from the Italian tax code Android Kotlin

    private fun inverseFiscalCodeCalculate(fiscalCode: String) {

        // Letter corresponding to the month number
        val monthArray = mapOf(
            "A" to "01",
            "B" to "02",
            "C" to "03",
            "D" to "04",
            "E" to "05",
            "H" to "06",
            "L" to "07",
            "M" to "08",
            "P" to "09",
            "R" to "10",
            "S" to "11",
            "T" to "12"
        )

        // Get gender and born date
        val getNumberGender = fiscalCode.substring(9, 11).toInt()
        val getNumberDayDate = if(getNumberGender > 40) abs(getNumberGender - 40) else getNumberGender
        val getNumberMonthDate = fiscalCode.substring(8, 9)
        val getNumberYearDate = fiscalCode.substring(6, 8)
        val filterMonth = monthArray[getNumberMonthDate.toUpperCase()]

        //Check born year
        val yearCheck = parseInt(getNumberYearDate) + 1900
        val dateCheck = Calendar.getInstance()

// Check if the user is older than 85 years. This allows you to determine the millennium to read (1900 or 2000)
        dateCheck.add(Calendar.YEAR, -85) 
        val yearBorn = if (yearCheck < dateCheck.get(Calendar.YEAR))
            parseInt(getNumberYearDate)  + 2000
        else yearCheck

        //User data
        val genderString = if(getNumberGender < 32) "M" else "F"
        va bornDateString = "$getNumberDayDate/$filterMonth/$yearBorn/"

    }
Open chat
Hai bisogno di assistenza?!
Ciao! sono il Dr. Domenico Giacomo Campanile esperto nello sviluppo di applicativi Web e Mobile.
Vuoi creare un App o un sito Web per la tua attività?! ti seguiremo a 360°! Progettazione, Sviluppo, Grafica e Pubblicizzazione sul Web!