updated unit test for time difference
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package `in`.sminnovations.attendanceapp
|
||||
|
||||
import com.google.firebase.Timestamp
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.temporal.ChronoUnit
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
@@ -18,5 +19,24 @@ class ExampleUnitTest {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun timeTest(){
|
||||
val currentTime = "30 January 2025 11:01:55 am"
|
||||
val givenTime = "30 January 2025 10:30:55 am"
|
||||
val minutes = 20L
|
||||
val result = isTimeDifferenceGreaterThanMinutes(givenTime, currentTime, minutes)
|
||||
assertEquals(true,result)
|
||||
}
|
||||
|
||||
|
||||
fun isTimeDifferenceGreaterThanMinutes(givenTimeStr: String, currentTimeStr: String, minutes: Long): Boolean {
|
||||
val formatter = DateTimeFormatter.ofPattern("dd MMMM yyyy hh:mm:ss a")
|
||||
|
||||
val givenTime = LocalDateTime.parse(givenTimeStr, formatter)
|
||||
val currentTime = LocalDateTime.parse(currentTimeStr, formatter)
|
||||
|
||||
val timeDifference = abs(ChronoUnit.MINUTES.between(givenTime, currentTime))
|
||||
|
||||
return timeDifference > minutes
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user