Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
namespace "com.dscvit.vitty"
minSdkVersion 26
targetSdkVersion 36
versionCode 43
versionCode 44
versionName "3.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/com/dscvit/vitty/util/UtilFunctions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale
import java.util.TimeZone

object UtilFunctions {
fun openLink(
Expand Down Expand Up @@ -144,4 +145,32 @@ object UtilFunctions {
intent.putExtra(Intent.EXTRA_STREAM, bitmapUri)
context.startActivity(Intent.createChooser(intent, "Share"))
}

fun parseBackendTimeString(timeString: String): Date? {
try {
val timeRegex = """T(\d{2}):(\d{2}):(\d{2})""".toRegex()
val match = timeRegex.find(timeString)

if (match != null) {
val hours = match.groupValues[1].toInt()
val minutes = match.groupValues[2].toInt()
val seconds = match.groupValues[3].toInt()

val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, hours)
calendar.set(Calendar.MINUTE, minutes)
calendar.set(Calendar.SECOND, seconds)
calendar.set(Calendar.MILLISECOND, 0)

return calendar.time
} else {
val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.Builder().setLanguage("en").setRegion("IN").build())
sdf.timeZone = TimeZone.getTimeZone("Asia/Kolkata")
return sdf.parse(timeString)
}
} catch (e: Exception) {
val calendar = Calendar.getInstance(TimeZone.getTimeZone("Asia/Kolkata"))
return calendar.time
}
}
}
22 changes: 4 additions & 18 deletions app/src/main/java/com/dscvit/vitty/widget/TodayWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ suspend fun fetchTodayData(
var endTime = parseTimeToTimestamp(period.end_time).toDate()

val simpleDateFormat =
SimpleDateFormat("h:mm a", Locale.getDefault())
SimpleDateFormat("h:mm a", Locale("en", "IN"))
val sTime: String =
simpleDateFormat.format(startTime).uppercase(Locale.ROOT)
val eTime: String =
Expand Down Expand Up @@ -347,30 +347,16 @@ suspend fun fetchTodayData(

fun parseTimeToTimestamp(timeString: String): Timestamp =
try {
val sanitizedTime =
if (timeString.contains("+05:53")) {
timeString.replace("+05:53", "+05:30")
} else {
timeString
}
val time = replaceYearIfZero(sanitizedTime)

val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.getDefault())
val date = dateFormat.parse(time)
val date = UtilFunctions.parseBackendTimeString(timeString)
if (date != null) {
Timestamp(date)
} else {
Timber.d("Date parsing error: Unable to parse sanitized time: $time")
Timber.d("Date parsing error: Unable to parse time: $timeString")
Timestamp.now()
}
} catch (e: Exception) {
Timber.d("Date parsing error: Unparseable date: \"$timeString\"")
Timestamp.now()
}

fun replaceYearIfZero(dateStr: String): String =
if (dateStr.startsWith("0")) {
"2023" + dateStr.substring(4)
} else {
dateStr
}

Loading