Created
December 14, 2022 12:26
-
-
Save shohiebsense/cb04f07fa229c58267fc5d697afce034 to your computer and use it in GitHub Desktop.
Also note that the cache is using the same simpledateformat, ended up as a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val LAST_REQUEST_TIME_MILLISECONDS = "last_request_time_milliseconds" | |
private val getDateFormat = SimpleDateFormat("dd-hh-mm-ss") | |
private fun isRapidRequest(lastRequestDateTime: String): Boolean { | |
if (lastRequestDateTime.isBlank()) return false | |
val date = getDateFormat.format(Date()) | |
val dateTimeIntArrayList = date.split("-") | |
val lastDatetimeIntArrayList = lastRequestDateTime.split("-") | |
val currentDay = dateTimeIntArrayList[0].toInt() | |
val lastRequestTimeInDay = dateTimeIntArrayList[0].toInt() | |
if (currentDay != lastRequestTimeInDay) { | |
return false | |
} | |
val currentHour = dateTimeIntArrayList[1].toInt() | |
val lastrequestTimeInHour = lastDatetimeIntArrayList[1].toInt() | |
if ((currentHour - lastrequestTimeInHour).absoluteValue > 1) { | |
return false | |
} | |
val currentMinute = dateTimeIntArrayList[2].toInt() | |
val lastrequestTimeInMinute = lastDatetimeIntArrayList[2].toInt() | |
return (currentMinute - lastrequestTimeInMinute) | |
.absoluteValue < BuildConfig.ACCESS_INTERVAL_LIMIT | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment