Fix dateformat

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2024-06-19 09:57:52 +02:00 committed by Alper Öztürk
parent bc893388df
commit 274132a12d
2 changed files with 20 additions and 23 deletions

View file

@ -44,21 +44,26 @@ class CalendarEventManager(private val context: Context) {
CalendarContract.Events.DTSTART, CalendarContract.Events.DTSTART,
) )
val selection = "${CalendarContract.Events.TITLE} = ? AND ${CalendarContract.Events.DTSTART} = ?"
val selectionArgs = arrayOf(eventTitle, eventStartDate.toString())
val cursor = context.contentResolver.query( val cursor = context.contentResolver.query(
CalendarContract.Events.CONTENT_URI, CalendarContract.Events.CONTENT_URI,
projection, projection,
selection, null,
selectionArgs, null,
"${CalendarContract.Events.DTSTART} ASC" "${CalendarContract.Events.DTSTART} ASC"
) )
cursor?.use { cursor?.use {
if (cursor.moveToFirst()) { val idIndex = cursor.getColumnIndex(CalendarContract.Events._ID)
val idIndex = cursor.getColumnIndex(CalendarContract.Events._ID) val titleIndex = cursor.getColumnIndex(CalendarContract.Events.TITLE)
return cursor.getLong(idIndex) val startDateIndex = cursor.getColumnIndex(CalendarContract.Events.DTSTART)
while (cursor.moveToNext()) {
val title = cursor.getString(titleIndex)
val startDate = cursor.getLong(startDateIndex)
if (eventTitle == title && startDate == eventStartDate) {
return cursor.getLong(idIndex)
}
} }
} }

View file

@ -12,6 +12,7 @@ import com.nextcloud.model.SearchResultEntryType
import com.owncloud.android.lib.common.SearchResultEntry import com.owncloud.android.lib.common.SearchResultEntry
import java.text.ParseException import java.text.ParseException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date
import java.util.TimeZone import java.util.TimeZone
fun SearchResultEntry.getType(): SearchResultEntryType { fun SearchResultEntry.getType(): SearchResultEntryType {
@ -30,26 +31,17 @@ fun SearchResultEntry.getType(): SearchResultEntryType {
} }
} }
// FIXME
@SuppressLint("SimpleDateFormat") @SuppressLint("SimpleDateFormat")
fun SearchResultEntry.parseDateTimeRange(): Long? { fun SearchResultEntry.parseDateTimeRange(): Long? {
// Define the input and output date formats val cleanedSubline: String = subline.replace('\u202F', ' ')
val inputFormat = SimpleDateFormat("MMM d, yyyy h:mm a") val formatter = SimpleDateFormat("MMM d, yyyy h:mm a")
val outputFormat = SimpleDateFormat("MMM d, yyyy HH:mm a") val startDate = cleanedSubline.substringBefore(" -")
// Parse the input date string
val startDateTime = inputFormat.parse(subline.split(" - ")[0])
// Format the date to the desired output format
val result = outputFormat.format(startDateTime)
val formatter = SimpleDateFormat("MMM dd, yyyy HH:MM")
try { try {
val date = formatter.parse(result) val date: Date? = formatter.parse(startDate)
formatter.timeZone = TimeZone.getTimeZone("UTC") formatter.timeZone = TimeZone.getTimeZone("UTC")
return date?.time return date?.time
} catch (e: ParseException) { } catch (e: ParseException) {
return null return null
} }
} }