Skip to content

Commit

Permalink
Fixed bug that caused alarm to trigger immediately after setting an a…
Browse files Browse the repository at this point in the history
…larm that's before "now" time
  • Loading branch information
JasperEssien2 committed Jul 21, 2022
1 parent 1f44ebc commit 9c53b05
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,24 @@ data class AlarmConfig(
fun timeMilliSeconds(): Long {
val timeMilliSeconds: Long = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Calendar.getInstance().apply {
timeInMillis = System.currentTimeMillis()

set(Calendar.HOUR_OF_DAY, alarmHour)
if (alarmMinute != null)
set(Calendar.MINUTE, alarmMinute)

set(Calendar.SECOND, alarmSecond ?: 0)

Log.i("AlarmManagerHelper", "INstance of ${this.get(Calendar.DATE)}")

if(this <= Calendar.getInstance()){
// Add an additional day, if alarm is set before "now" time
// to prevent alarm from getting triggered
set(Calendar.DATE, this.get(Calendar.DATE) + 1)

Log.i("AlarmManagerHelper", "NEW DATE ${this.get(Calendar.DATE)}")
}


}.timeInMillis

} else {
Expand Down

0 comments on commit 9c53b05

Please sign in to comment.