Skip to content

Commit

Permalink
Merge pull request #43
Browse files Browse the repository at this point in the history
* fix: Fixed few crashes and change date format to 24 for api
  • Loading branch information
a2ke5e1 authored Aug 1, 2024
1 parent 98d6eb8 commit eb2090c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
11 changes: 0 additions & 11 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
applicationId = "com.a3.yearlyprogess"
minSdk = 30
targetSdk = 35
versionCode = 76
versionCode = 77
val localVersionCode = versionCode
versionName = "2.${localVersionCode!! - 64}-beta"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface SunriseSunsetApi {
@Query("lat") lat: Double,
@Query("lng") lon: Double,
@Query("date_start") startDate: String,
@Query("date_end") endDate: String
@Query("date_end") endDate: String,
@Query("time_format") timeFormat: String = "24"
): Response<SunriseSunsetResponse>
}
45 changes: 36 additions & 9 deletions app/src/main/java/com/a3/yearlyprogess/data/models/Result.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.a3.yearlyprogess.data.models

import android.icu.text.SimpleDateFormat
import android.icu.util.TimeZone
import java.util.Calendar
import java.util.Date
import java.util.Locale

Expand Down Expand Up @@ -58,14 +59,40 @@ data class Result(
}

private fun convertToDateTime(time: String): Date {
val dateTime = "$date $time"
val formatter = SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss a", Locale.getDefault()
)
val timeZone = TimeZone.getTimeZone(timezone) // Adjust as needed
formatter.timeZone = timeZone

val newDate = formatter.parse(dateTime)
return newDate
try {
val dateTime = "$date $time"
val formatter = SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss", Locale.getDefault()
)
val timeZone = TimeZone.getTimeZone(timezone) // Adjust as needed
formatter.timeZone = timeZone

val newDate = formatter.parse(dateTime)
return newDate
} catch (ex: Exception) {
ex.printStackTrace()
}

val cal = Calendar.getInstance()
cal.timeInMillis = System.currentTimeMillis()

val year = date.split("-")[0].toInt()
val month = date.split("-")[1].toInt()
val day = date.split("-")[2].toInt()

cal.set(Calendar.YEAR, year)
cal.set(Calendar.MONTH, month - 1)
cal.set(Calendar.DAY_OF_MONTH, day)


val onlyTime = time.split(" ")[0]
val hour = onlyTime.split(":")[0].toInt()
val minute = onlyTime.split(":")[1].toInt()
val second = onlyTime.split(":")[2].toInt()
cal.set(Calendar.HOUR_OF_DAY, hour)
cal.set(Calendar.MINUTE, minute)
cal.set(Calendar.SECOND, second)

return cal.time
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class WidgetUpdateBroadcastReceiver : BroadcastReceiver() {
if (response.isSuccessful && result != null) {
storeSunriseSunset(context, result)
}
}
catch (ex: Exception) {
Log.d("WUBR", ex.message.toString())
} finally {
cancel()
}
Expand Down

0 comments on commit eb2090c

Please sign in to comment.