Android-Week-View icon indicating copy to clipboard operation
Android-Week-View copied to clipboard

Bug: side hours aren't formatted to 24 hours

Open AndroidDeveloperLB opened this issue 7 years ago • 2 comments

Events get formatted fine, but not side hours:

image

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()))
}

AndroidDeveloperLB avatar May 06 '18 06:05 AndroidDeveloperLB

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)
        }
    }
}

AndroidDeveloperLB avatar May 06 '18 06:05 AndroidDeveloperLB

Fixed it here: https://github.com/alamkanak/Android-Week-View/pull/496

AndroidDeveloperLB avatar May 06 '18 11:05 AndroidDeveloperLB