Skip to content

Instantly share code, notes, and snippets.

@tomergoldst
Last active January 23, 2021 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomergoldst/7474db6b10278016dc1464d20791cee9 to your computer and use it in GitHub Desktop.
Save tomergoldst/7474db6b10278016dc1464d20791cee9 to your computer and use it in GitHub Desktop.
fun getDaysBetweenRoundUp(t1: Long, t2: Long): Int {
val msDiff = t2 - t1
val daysFraction = msDiff.toFloat() / android.text.format.DateUtils.DAY_IN_MILLIS
return ceil(daysFraction.toDouble()).toInt()
}
fun getDaysBetweenRoundUp(c1: Calendar, c2: Calendar): Int {
return getDaysBetweenRoundUp(c1.timeInMillis, c2.timeInMillis)
}
fun getDaysBetween(t1: Long, t2: Long): Int {
val msDiff = t2 - t1
return TimeUnit.MILLISECONDS.toDays(msDiff).toInt()
}
fun getDaysBetween(c1: Calendar, c2: Calendar): Int {
return getDaysBetween(c1.timeInMillis, c2.timeInMillis)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment