fix #312, make birthday parsing more robust

This commit is contained in:
tibbi 2018-11-29 21:30:51 +01:00
parent 8fbfa684cd
commit 0c1da53df6
1 changed files with 4 additions and 6 deletions

View File

@ -14,8 +14,6 @@ import com.simplemobiletools.contacts.pro.helpers.VcfImporter.ImportResult.*
import com.simplemobiletools.contacts.pro.models.*
import ezvcard.Ezvcard
import ezvcard.VCard
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import java.io.File
import java.io.FileOutputStream
import java.net.URLDecoder
@ -26,8 +24,6 @@ class VcfImporter(val activity: SimpleActivity) {
IMPORT_FAIL, IMPORT_OK, IMPORT_PARTIAL
}
private val PATTERN = "EEE MMM dd HH:mm:ss 'GMT'ZZ YYYY"
private var contactsImported = 0
private var contactsFailed = 0
@ -160,8 +156,10 @@ class VcfImporter(val activity: SimpleActivity) {
}
private fun formatDateToDayCode(date: Date): String {
val dateTime = DateTime.parse(date.toString(), DateTimeFormat.forPattern(PATTERN))
return dateTime.toString("yyyy-MM-dd")
val year = 1900 + date.year
val month = String.format("%02d", date.month + 1)
val day = String.format("%02d", date.date)
return "$year-$month-$day"
}
private fun getContactGroups(ezContact: VCard): ArrayList<Group> {