Skip to content

Commit

Permalink
fix: Fix datetime formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbukachi authored and kibettheophilus committed Nov 9, 2023
1 parent 20274f0 commit f9d9bc7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import java.util.Locale

fun Session.toPresentationModel(): SessionPresentationModel {
val startTime = getTimePeriod(this.startDateTime)
val endTime = getTimePeriod(this.endDateTime)
return SessionPresentationModel(
id = this.id,
title = this.title,
description = this.description,
venue = this.rooms,
startTime = startTime.time,
endTime = this.endTime,
endTime = "${endTime.time} ${endTime.period}",
amOrPm = startTime.period,
isStarred = this.isBookmarked,
level = this.sessionLevel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ data class SessionsUiState(
val isError: Boolean = false,
val errorMessage: String = "",
val eventDays: List<EventDate> = emptyList(),
val selectedEventDay: EventDate = EventDate("1", 1)
val selectedEventDay: EventDate = EventDate("-1", 1)
)
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class SessionsViewModel @Inject constructor(
_sessionsUiState.update {
it.copy(
eventDays = sessionDays,
selectedEventDay = sessionDays.first()
selectedEventDay = if (it.selectedEventDay.value == "-1") { sessionDays.first() } else { it.selectedEventDay }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.android254.presentation.utils

import android.text.format.DateUtils
import timber.log.Timber
import java.text.SimpleDateFormat
import java.util.Date
Expand All @@ -24,16 +25,10 @@ fun String.getTimeDifference(): String {
return try {
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault())
val timePosted = dateFormat.parse(this)
val currentTime = Date()

val timeDifference = currentTime.time - timePosted.time
val currentTime = Date()

val minutesDifference = timeDifference / (1000 * 60)
if (minutesDifference <= 60) {
"$minutesDifference mins ago"
} else {
"${minutesDifference / 60} hours ago"
}
return DateUtils.getRelativeTimeSpanString(timePosted.time, currentTime.time, DateUtils.DAY_IN_MILLIS).toString()
} catch (e: Exception) {
Timber.e(e)
this
Expand Down

0 comments on commit f9d9bc7

Please sign in to comment.