Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EmmanuelGuther/73d7b1fd777b0f7290a6bf2d30a79aee to your computer and use it in GitHub Desktop.
Save EmmanuelGuther/73d7b1fd777b0f7290a6bf2d30a79aee to your computer and use it in GitHub Desktop.
Extension function to check if timestamp value is before X days
fun Long.checkTimeIsOldThan(days: Int): Boolean {
val daysInMillis = TimeUnit.DAYS.toMillis(days.toLong())
val currentTime = Date().time
val previousTime = this
val differ = currentTime - previousTime
return !(differ < daysInMillis && differ > -daysInMillis)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment