Merge pull request #709 from qwertyfinger/partial-date-export-v3
Export partial dates to vCard 3.0 with year 1900
This commit is contained in:
commit
a439ca20a3
|
@ -71,23 +71,20 @@ class VcfExporter {
|
||||||
card.addEmail(email)
|
card.addEmail(email)
|
||||||
}
|
}
|
||||||
|
|
||||||
contact.events.forEach {
|
contact.events.forEach { event ->
|
||||||
if (it.type == Event.TYPE_ANNIVERSARY || it.type == Event.TYPE_BIRTHDAY) {
|
if (event.type == Event.TYPE_ANNIVERSARY || event.type == Event.TYPE_BIRTHDAY) {
|
||||||
val dateTime = it.value.getDateTimeFromDateString(false)
|
val dateTime = event.value.getDateTimeFromDateString(false)
|
||||||
if (it.value.startsWith("--")) {
|
|
||||||
val partialDate = PartialDate.builder().year(null).month(dateTime.monthOfYear).date(dateTime.dayOfMonth).build()
|
|
||||||
if (it.type == Event.TYPE_BIRTHDAY) {
|
|
||||||
card.birthdays.add(Birthday(partialDate))
|
|
||||||
} else {
|
|
||||||
card.anniversaries.add(Anniversary(partialDate))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Calendar.getInstance().apply {
|
Calendar.getInstance().apply {
|
||||||
clear()
|
clear()
|
||||||
|
if (event.value.startsWith("--")) {
|
||||||
|
set(Calendar.YEAR, 1900)
|
||||||
|
} else {
|
||||||
set(Calendar.YEAR, dateTime.year)
|
set(Calendar.YEAR, dateTime.year)
|
||||||
|
|
||||||
|
}
|
||||||
set(Calendar.MONTH, dateTime.monthOfYear - 1)
|
set(Calendar.MONTH, dateTime.monthOfYear - 1)
|
||||||
set(Calendar.DAY_OF_MONTH, dateTime.dayOfMonth)
|
set(Calendar.DAY_OF_MONTH, dateTime.dayOfMonth)
|
||||||
if (it.type == Event.TYPE_BIRTHDAY) {
|
if (event.type == Event.TYPE_BIRTHDAY) {
|
||||||
card.birthdays.add(Birthday(time))
|
card.birthdays.add(Birthday(time))
|
||||||
} else {
|
} else {
|
||||||
card.anniversaries.add(Anniversary(time))
|
card.anniversaries.add(Anniversary(time))
|
||||||
|
@ -95,7 +92,6 @@ class VcfExporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
contact.addresses.forEach {
|
contact.addresses.forEach {
|
||||||
val address = Address()
|
val address = Address()
|
||||||
|
|
|
@ -18,6 +18,7 @@ import com.simplemobiletools.contacts.pro.models.Event
|
||||||
import com.simplemobiletools.contacts.pro.models.Organization
|
import com.simplemobiletools.contacts.pro.models.Organization
|
||||||
import ezvcard.Ezvcard
|
import ezvcard.Ezvcard
|
||||||
import ezvcard.VCard
|
import ezvcard.VCard
|
||||||
|
import ezvcard.util.PartialDate
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.net.URLDecoder
|
import java.net.URLDecoder
|
||||||
|
@ -94,13 +95,21 @@ class VcfImporter(val activity: SimpleActivity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
ezContact.anniversaries.forEach {
|
ezContact.anniversaries.forEach { anniversary ->
|
||||||
val event = Event(formatDateToDayCode(it.date), CommonDataKinds.Event.TYPE_ANNIVERSARY)
|
val event = if (anniversary.date != null) {
|
||||||
|
Event(formatDateToDayCode(anniversary.date), CommonDataKinds.Event.TYPE_ANNIVERSARY)
|
||||||
|
} else {
|
||||||
|
Event(formatPartialDateToDayCode(anniversary.partialDate), CommonDataKinds.Event.TYPE_ANNIVERSARY)
|
||||||
|
}
|
||||||
events.add(event)
|
events.add(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
ezContact.birthdays.forEach {
|
ezContact.birthdays.forEach { birthday ->
|
||||||
val event = Event(formatDateToDayCode(it.date), CommonDataKinds.Event.TYPE_BIRTHDAY)
|
val event = if (birthday.date != null) {
|
||||||
|
Event(formatDateToDayCode(birthday.date), CommonDataKinds.Event.TYPE_BIRTHDAY)
|
||||||
|
} else {
|
||||||
|
Event(formatPartialDateToDayCode(birthday.partialDate), CommonDataKinds.Event.TYPE_BIRTHDAY)
|
||||||
|
}
|
||||||
events.add(event)
|
events.add(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,12 +177,18 @@ class VcfImporter(val activity: SimpleActivity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatDateToDayCode(date: Date): String {
|
private fun formatDateToDayCode(date: Date): String {
|
||||||
val year = 1900 + date.year
|
val year = if (date.year == 0) "-" else "${1900 + date.year}"
|
||||||
val month = String.format("%02d", date.month + 1)
|
val month = String.format("%02d", date.month + 1)
|
||||||
val day = String.format("%02d", date.date)
|
val day = String.format("%02d", date.date)
|
||||||
return "$year-$month-$day"
|
return "$year-$month-$day"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun formatPartialDateToDayCode(partialDate: PartialDate): String {
|
||||||
|
val month = String.format("%02d", partialDate.month)
|
||||||
|
val day = String.format("%02d", partialDate.date)
|
||||||
|
return "--$month-$day"
|
||||||
|
}
|
||||||
|
|
||||||
private fun getContactGroups(ezContact: VCard): ArrayList<Group> {
|
private fun getContactGroups(ezContact: VCard): ArrayList<Group> {
|
||||||
val groups = ArrayList<Group>()
|
val groups = ArrayList<Group>()
|
||||||
if (ezContact.categories != null) {
|
if (ezContact.categories != null) {
|
||||||
|
|
Loading…
Reference in New Issue