Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import ezvcard.property.Anniversary
import ezvcard.property.Birthday
import ezvcard.util.PartialDate
import java.time.LocalDate
import java.time.ZonedDateTime
import java.time.format.DateTimeParseException
import java.time.temporal.Temporal
import java.util.logging.Level

object EventHandler: DataRowHandler() {
Expand All @@ -27,15 +29,22 @@ object EventHandler: DataRowHandler() {
super.handle(values, contact)

val dateStr = values.getAsString(Event.START_DATE) ?: return
var full: LocalDate? = null
var full: Temporal? = null
var partial: PartialDate? = null
try {
full = LocalDate.parse(dateStr)
} catch(e: DateTimeParseException) {
} catch(_: DateTimeParseException) {
try {
partial = PartialDate.parse(dateStr)
} catch (e: IllegalArgumentException) {
logger.log(Level.WARNING, "Couldn't parse birthday/anniversary date from database", e)
// Some server providers (e.g. t-mobile) include time information
// This is allowed by RFC2426: https://www.rfc-editor.org/rfc/rfc2426#section-3.1.5
// And RFC6350: https://www.rfc-editor.org/rfc/rfc6350#section-6.2.5
full = ZonedDateTime.parse(dateStr)
} catch (_: DateTimeParseException) {
try {
partial = PartialDate.parse(dateStr)
} catch (e: IllegalArgumentException) {
logger.log(Level.WARNING, "Couldn't parse birthday/anniversary date from database: $dateStr", e)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import java.time.LocalDate
import java.time.ZoneId
import java.time.ZoneOffset
import java.time.ZonedDateTime

@RunWith(RobolectricTestRunner::class)
class EventHandlerTest {
Expand Down Expand Up @@ -46,6 +49,18 @@ class EventHandlerTest {
)
}

@Test
fun testStartDate_WithTime() {
val contact = Contact()
EventHandler.handle(ContentValues().apply {
put(Event.START_DATE, "1953-10-15T23:10:00Z")
}, contact)
assertEquals(
ZonedDateTime.of(1953, 10, 15, 23, 10, 0, 0, ZoneId.of(ZoneOffset.UTC.id)),
contact.customDates[0].property.date
)
}

@Test
fun testStartDate_Partial() {
val contact = Contact()
Expand Down