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