fix #253, properly handle birthdays without a year specified

This commit is contained in:
tibbi
2017-10-25 19:29:20 +02:00
parent 85b6174cd1
commit 60e4d5e6f0

View File

@@ -349,8 +349,12 @@ class MainActivity : SimpleActivity(), NavigationListener {
val contactId = cursor.getIntValue(ContactsContract.CommonDataKinds.Event.CONTACT_ID).toString() val contactId = cursor.getIntValue(ContactsContract.CommonDataKinds.Event.CONTACT_ID).toString()
val name = cursor.getStringValue(ContactsContract.Contacts.DISPLAY_NAME) val name = cursor.getStringValue(ContactsContract.Contacts.DISPLAY_NAME)
val birthDay = cursor.getStringValue(ContactsContract.CommonDataKinds.Event.START_DATE) val birthDay = cursor.getStringValue(ContactsContract.CommonDataKinds.Event.START_DATE)
val formatter = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) val containsYear = birthDay.length > 7
val timestamp = (formatter.parse(birthDay).time / 1000).toInt() val pattern = if (containsYear) "yyyy-MM-dd" else "--MM-dd"
val formatter = SimpleDateFormat(pattern, Locale.getDefault())
var timestamp = (formatter.parse(birthDay).time / 1000).toInt()
if (!containsYear)
timestamp += 45 * YEAR // set year to 2015
val lastUpdated = cursor.getLongValue(ContactsContract.CommonDataKinds.Event.CONTACT_LAST_UPDATED_TIMESTAMP) val lastUpdated = cursor.getLongValue(ContactsContract.CommonDataKinds.Event.CONTACT_LAST_UPDATED_TIMESTAMP)
val event = Event(0, timestamp, timestamp, name, importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR, val event = Event(0, timestamp, timestamp, name, importId = contactId, flags = FLAG_ALL_DAY, repeatInterval = YEAR,
eventType = eventTypeId, source = SOURCE_CONTACT_BIRTHDAY, lastUpdated = lastUpdated) eventType = eventTypeId, source = SOURCE_CONTACT_BIRTHDAY, lastUpdated = lastUpdated)