Skip to content

Commit

Permalink
[Fix]: TimePicker 오류 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong committed Feb 18, 2024
1 parent c655d98 commit 08c6297
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ fun TimePicker(
color = Gray700,
fontWeight = FontWeight.SemiBold
)

var hourValue by remember { mutableIntStateOf(if(localTime.hour==0) 12 else localTime.hour) }
var timeType by remember {
mutableStateOf(if (localTime.hour >= 12) TimePickerType.PM else TimePickerType.AM)
}
var hourValue by remember {
mutableIntStateOf(
if (localTime.hour > 12) localTime.hour - 12
else if (localTime.hour == 0) 12
else localTime.hour
)
}
var minuteValue by remember { mutableIntStateOf(localTime.minute) }
var timeType by remember { mutableStateOf(TimePickerType.AM) }

BottomSheetScreen(
onDismissRequest = onDismissRequest,
Expand Down Expand Up @@ -86,12 +93,13 @@ fun TimePicker(
modifier = Modifier
.align(Alignment.CenterEnd)
.clickable {
val transHour = when (timeType) {
TimePickerType.AM -> if (hourValue == 12) -12 else 0
TimePickerType.PM -> if (hourValue == 12) 0 else 12
}
onConfirm(
LocalTime(
hour = hourValue + when (timeType) {
TimePickerType.AM -> if (hourValue==12) -12 else 0
TimePickerType.PM -> if (hourValue==12) 0 else 12
},
hour = hourValue + transHour,
minute = minuteValue
)
)
Expand All @@ -105,7 +113,7 @@ fun TimePicker(
) {
NumberPicker(
value = hourValue,
range = 1.. 12,
range = 1..12,
dividersColor = Primary3,
textStyle = timeTextStyle,
onValueChange = {
Expand All @@ -115,7 +123,7 @@ fun TimePicker(
Spacer(modifier = Modifier.width(20.dp))
NumberPicker(
value = minuteValue,
range = 0..if (hourValue == 12 && timeType == TimePickerType.PM) 0 else 59,
range = 0..59,
dividersColor = Primary3,
textStyle = timeTextStyle,
onValueChange = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import kotlinx.datetime.TimeZone
import kotlinx.datetime.minus
import kotlinx.datetime.number
import kotlinx.datetime.todayIn
import timber.log.Timber

@Composable
fun ScheduleAddScreen(
Expand Down Expand Up @@ -248,7 +249,7 @@ fun ScheduleAddScreen(
val fixedHour = if (it.hour == 0) 24 else it.hour
val timeHour = (fixedHour - 1) % 12 + 1
val timeMinute = it.minute
val timeAmPm = if (fixedHour < 12) "오전" else "오후"
val timeAmPm = if (fixedHour < 12 || fixedHour == 24) "오전" else "오후"
runCatching {
String.format(format, timeAmPm, timeHour, timeMinute)
}.onFailure { exception ->
Expand Down

0 comments on commit 08c6297

Please sign in to comment.