So I need to get time in milliseconds for Monday of this week and time in milliseconds of Sunday for this week and with code below it worked fine till I installed app on emulator and if I set time to Sunday it returns Jun 18 - Jun 24
, but on Samsung Galaxy s5 it returns Jun 11 - Jun 17 <- this is how it should show
Am I doing something wrong?
getMondayTime
method returns time in milliseconds for monday
private fun getMondayTime(): Long{
val calendar = Calendar.getInstance()
calendar.timeInMillis = System.currentTimeMillis()
calendar.firstDayOfWeek = Calendar.MONDAY
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
calendar.set(Calendar.MILLISECOND, 0)
return calendar.timeInMillis
}
getSundayTime
returns time in milliseconds for sunday
private fun getSundayTime(): Long {
val calendar = Calendar.getInstance()
calendar.timeInMillis = System.currentTimeMillis()
calendar.firstDayOfWeek = Calendar.MONDAY
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY)
calendar.set(Calendar.HOUR_OF_DAY, 22)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
calendar.set(Calendar.MILLISECOND, 0)
return calendar.timeInMillis
}
Here I'm putting all this time into places
fun generateWeek(): Week{
val format = SimpleDateFormat("MMM d", Locale.ENGLISH)
val mondayTime = getMondayTime()
val sundayTime = getSundayTime()
val label = "${format.format(mondayTime)} - ${format.format(sundayTime)}"
return Week(label, mondayTime, sundayTime)
}