mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
fix #253, properly handle birthdays without a year specified
This commit is contained in:
@@ -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)
|
||||||
|
Reference in New Issue
Block a user