coerceTime

fun coerceTime(time: LocalTime, timeFormat: TimeFormat = TimeFormat.HOUR_24): LocalTime

Returns the closest selectable time for time under timeFormat.

This is useful before calling io.github.kezlab.compose.pickers.time.TimePickerState.selectTime when app-owned state can contain values outside custom picker lists.

Throws

if the item lists needed by timeFormat are empty, contain duplicates, or contain values outside their supported ranges.


fun coerceTime(hour: Int, minute: Int, timeFormat: TimeFormat = TimeFormat.HOUR_24): LocalTime

Returns the closest selectable time for hour and minute under timeFormat.

hour is interpreted as hour-of-day in 0..23.

Throws

if hour or minute is outside the supported range, or if the item lists needed by timeFormat are invalid.


fun coerceTime(displayHour: Int, minute: Int, period: TimePeriod): LocalTime

Returns the closest selectable time for a 12-hour display value.

displayHour is interpreted as the format-hour shown to users in 1..12; period supplies AM/PM. This is useful when app-owned form or preset values are stored as a display hour plus period instead of a 24-hour LocalTime.

Throws

if displayHour is outside 1..12, minute is outside 0..59, or the 12-hour item lists are invalid.