Repository: expo/expo
File: packages/expo-calendar/android/src/main/java/expo/modules/calendar/next/utils/CalendarNextUtils.kt (Kotlin)

Code before:
val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").apply {
  timeZone = TimeZone.getTimeZone("GMT")
}

/**
 * [SimpleDateFormat] used in native recurrence rule string.
 * The format corresponds to the 'date-time' type defined by RFC-5455 section 3.3.5.
 */
val rrFormat = SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'")

/**
 * [SimpleDateFormat] used in native recurrence rule string for all-day events.
 * The format corresponds to the 'date' type defined by RFC-5455 section 3.3.4.
 */
val allDayRRFormat = SimpleDateFormat("yyyyMMdd").apply {
  timeZone = TimeZone.getTimeZone("GMT")
}

/**
 * @param dateString RFC-5455 date or date-time string (RFC sections 3.3.4 and 3.3.5).
 */
fun parseRrDate(dateString: String): Date? =
  runCatching {
    rrFormat.parse(dateString)
  }.recover {
    allDayRRFormat.parse(dateString)
  }.getOrNull()

suspend fun findEvents(contentResolver: ContentResolver, startDate: Any, endDate: Any, calendars: List<String>): Cursor {
  return withContext(Dispatchers.IO) {
    val eStartDate = Calendar.getInstance()
    val eEndDate = Calendar.getInstance()

    setDateInCalendar(eStartDate, startDate)
    setDateInCalendar(eEndDate, endDate)

    val uriBuilder = CalendarContract.Instances.CONTENT_URI.buildUpon()
    ContentUris.appendId(uriBuilder, eStartDate.timeInMillis)
    ContentUris.appendId(uriBuilder, eEndDate.timeInMillis)

    val uri = uriBuilder.build()
    var selection =
      "((${CalendarContract.Instances.BEGIN} >= ${eStartDate.timeInMillis}) " +
        "AND (${CalendarContract.Instances.END} <= ${eEndDate.timeInMillis}) " +
        "AND (${CalendarContract.Instances.VISIBLE} = 1) "

    if (calendars.isNotEmpty()) {
      val calendarQuery = "AND (${calendars.joinToString(" OR ") { "${CalendarContract.Instances.CALENDAR_ID} = '$it'" }})"
      selection += calendarQuery
    }
    selection += ")"

Review comment (suggestion):
```suggestion
    allDayRrFormat.parse(dateString)
```

Code after:
val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").apply {
  timeZone = TimeZone.getTimeZone("GMT")
}

/**
 * [SimpleDateFormat] used in native recurrence rule string.
 * The format corresponds to the 'date-time' type defined by RFC-5455 section 3.3.5.
 */
val rrFormat = SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'").apply {
  timeZone = TimeZone.getTimeZone("GMT")
}

/**
 * [SimpleDateFormat] used in native recurrence rule string for all-day events.
 * The format corresponds to the 'date' type defined by RFC-5455 section 3.3.4.
 */
val allDayRrFormat = SimpleDateFormat("yyyyMMdd").apply {
  timeZone = TimeZone.getTimeZone("GMT")
}

/**
 * @param dateString RFC-5455 date or date-time string (RFC sections 3.3.4 and 3.3.5).
 */
fun parseRrDate(dateString: String): Date? =
  runCatching {
    rrFormat.parse(dateString)
  }.recover {
    allDayRrFormat.parse(dateString)
  }.getOrNull()

suspend fun findEvents(contentResolver: ContentResolver, startDate: Any, endDate: Any, calendars: List<String>): Cursor {
  return withContext(Dispatchers.IO) {
    val eStartDate = Calendar.getInstance()
    val eEndDate = Calendar.getInstance()

    setDateInCalendar(eStartDate, startDate)
    setDateInCalendar(eEndDate, endDate)

    val uriBuilder = CalendarContract.Instances.CONTENT_URI.buildUpon()
    ContentUris.appendId(uriBuilder, eStartDate.timeInMillis)
    ContentUris.appendId(uriBuilder, eEndDate.timeInMillis)

    val uri = uriBuilder.build()
    var selection =
      "((${CalendarContract.Instances.BEGIN} >= ${eStartDate.timeInMillis}) " +
        "AND (${CalendarContract.Instances.END} <= ${eEndDate.timeInMillis}) " +
        "AND (${CalendarContract.Instances.VISIBLE} = 1) "

    if (calendars.isNotEmpty()) {
      val calendarQuery = "AND (${calendars.joinToString(" OR ") { "${CalendarContract.Instances.CALENDAR_ID} = '$it'" }})"
      selection += calendarQuery