Skip to content

Commit

Permalink
PI-2055 Handle null contact start time (#3588)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl authored Apr 5, 2024
1 parent 3cab738 commit 0fb759d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ internal class CreateAppointmentIntTests {

assertThat(appointment.type.code, equalTo(create.type.code))
assertThat(appointment.date, equalTo(start.toLocalDate()))
assertThat(appointment.startTime, isCloseTo(start))
assertThat(appointment.startTime!!, isCloseTo(start))
assertThat(appointment.notes, equalTo(notes))
assertThat(appointment.externalReference, equalTo(create.urn))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import uk.gov.justice.digital.hmpps.datetime.EuropeLondon
import uk.gov.justice.digital.hmpps.exception.NotFoundException
import java.time.Duration
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.*
import java.time.format.DateTimeFormatter

@Entity
Expand All @@ -41,7 +36,7 @@ class Appointment(
val date: LocalDate,

@Column(name = "contact_start_time")
val startTime: ZonedDateTime,
val startTime: ZonedDateTime?,

@Column(name = "contact_end_time")
val endTime: ZonedDateTime?,
Expand Down Expand Up @@ -102,7 +97,7 @@ class Appointment(

val duration: Duration
get() =
if (endTime != null) {
if (startTime != null && endTime != null) {
val sTime = startTime.toLocalTime()
val eTime = endTime.toLocalTime()
if (sTime <= eTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import uk.gov.justice.digital.hmpps.entity.*
import uk.gov.justice.digital.hmpps.exception.ConflictException
import uk.gov.justice.digital.hmpps.ldap.findByUsername
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZonedDateTime

@Service
Expand Down Expand Up @@ -47,7 +48,7 @@ class AppointmentService(
private fun uk.gov.justice.digital.hmpps.entity.Appointment.asAppointment(): Appointment =
Appointment(
Appointment.Type(type.code, type.description),
ZonedDateTime.of(date, startTime.toLocalTime(), EuropeLondon),
ZonedDateTime.of(date, startTime?.toLocalTime() ?: LocalTime.MIDNIGHT, EuropeLondon),
duration,
staff.asStaff(),
location?.asLocation(),
Expand Down

0 comments on commit 0fb759d

Please sign in to comment.