I have written this code to compare two time values in milliseconds. The comparison is of current time with the time defined in the database.
fun check_for_lecture(complete:(Boolean) -> Unit) : Int{
for (x in UpdateScheduledLecturesService.lectures) {
try {
val start_time = x.start_time.toInt()
val end_time = x.end_time.toInt()
val timeRightnow = System.currentTimeMillis().toInt()
// CompareTo returns a negative number if it's less than other, or a positive number if it's greater than other.
//(also tried)if (timeRightnow == start_time || timeRightnow > start_time && timeRightnow < end_time) {
val compareWstarttime= timeRightnow.compareTo(start_time)
val compareWendtime = timeRightnow.compareTo(end_time)
if(compareWstarttime > 0 && compareWendtime < 0){
count++
lectureID = x.lectureID
Log.d(TAG, "Test: lectureId assigned")
complete(true)
} else {
Log.d(TAG, "no lectures at this time")
complete(false)
}
} catch (e: ParseException) {
Log.d(TAG, "Exception")
e.printStackTrace()
complete(false)
}
}
However, it is not working. I am not sure where I am going wrong.
This is an example of when I print them:
current time :436239119, start time : 1520845200, end time : 1520848800.