Skip to content

Commit

Permalink
Merge pull request #143 from TimerTiTi/141-fix-timemapper
Browse files Browse the repository at this point in the history
close #141 fix time mapper
  • Loading branch information
koreatlwls authored Jun 19, 2024
2 parents f6638ac + 61b62c3 commit e8a0588
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ import java.time.LocalDate
import java.time.LocalDateTime

fun AMPMHours.toLocalDateTime(currentDate: LocalDate): LocalDateTime {
val hours = if (dayTime == AMPMHours.DayTime.AM) hours else hours + 12
return currentDate.atTime(hours, minutes)
val adjustedHours = when {
dayTime == AMPMHours.DayTime.AM && hours == 12 -> 0
dayTime == AMPMHours.DayTime.PM && hours == 12 -> 12
dayTime == AMPMHours.DayTime.PM -> hours + 12
else -> hours
}
return currentDate.atTime(adjustedHours, minutes)
}

fun LocalDateTime.toAMPMHours(): AMPMHours {
return AMPMHours(
hours = if (hour < 12) hour else hour - 12,
hours = when {
hour == 0 -> 12
hour > 12 -> hour - 12
else -> hour
},
minutes = minute,
dayTime = if (hour < 12) AMPMHours.DayTime.AM else AMPMHours.DayTime.PM,
)
Expand Down

0 comments on commit e8a0588

Please sign in to comment.