Add startOfDay & endOfDay methods

feature/top10
Aurelien Hubert 7 years ago
parent 83226b7175
commit 3d34097371
  1. 22
      app/src/main/java/net/pokeranalytics/android/util/extensions/DateExtension.kt

@ -96,3 +96,25 @@ fun Date.getFormattedDuration(toDate: Date) : String {
return "$hoursStr:$minutesStr" return "$hoursStr:$minutesStr"
} }
// Return the date of the beginning of the current date
fun Date.startOfTheDay() : Date {
val calendar = Calendar.getInstance()
calendar.time = this
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
calendar.set(Calendar.MILLISECOND, 0)
return calendar.time
}
// Return the date of the end of the current date
fun Date.endOfTheDay() : Date {
val calendar = Calendar.getInstance()
calendar.time = this
calendar.set(Calendar.HOUR_OF_DAY, 23)
calendar.set(Calendar.MINUTE, 59)
calendar.set(Calendar.SECOND, 59)
calendar.set(Calendar.MILLISECOND, 999)
return calendar.time
}
Loading…
Cancel
Save