Move this code:
val timePicker = createTimePicker{
_, hour, minute ->
c[Calendar.HOUR] = hour
c[Calendar.MINUTE] = minute
}
// Do time picking stuff
timePicker.show()
return if (DateFormat.is24HourFormat(context)){
Toast.makeText(context, "Chose 24-hour clause", Toast.LENGTH_SHORT).show()
SimpleDateFormat("dd mmm, yyyy 'at' HH:mm", Locale.getDefault()).format(c.time)}
else{
Toast.makeText(context, "Chose 12-hour clause", Toast.LENGTH_SHORT).show()
SimpleDateFormat("dd mmm, yyyy 'at' hh:mm aa", Locale.getDefault()).format(c.time)}