Android-Week-View
Android-Week-View copied to clipboard
Bug: side hours aren't formatted to 24 hours
Events get formatted fine, but not side hours:

Also, I've noticed that the library uses some constant ways to show the time formatting, by checking if the system uses 24 hours or not. That's not the best way to do it.
The correct way to do it is by getting the OS format alone :
/**
* gets the default time formatter of the device
*/
@JvmStatic
fun getFormatTimeUsingDeviceSettings(context: Context, useUtc: Boolean): java.text.DateFormat {
return (DateFormat.getTimeFormat(context)
?: SimpleDateFormat("HH:mm", Locale.getDefault()))
}
Seems it's a part of the sample itself, in BaseActivity. Here's how it should be there:
private fun setupDateTimeInterpreter(shortDate: Boolean) {
val calendar = Calendar.getInstance()
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
calendar.set(Calendar.MILLISECOND, 0)
val dateFormat = DateFormat.getTimeFormat(this@BaseActivity)
?: SimpleDateFormat("HH:mm", Locale.getDefault())
weekView.dateTimeInterpreter = object : DateTimeInterpreter {
...
override fun interpretTime(hour: Int): String {
calendar.set(Calendar.HOUR_OF_DAY, hour)
return dateFormat.format(calendar.time)
}
}
}
Fixed it here: https://github.com/alamkanak/Android-Week-View/pull/496