Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIPP-1857: Fallback to ZonedDateTime parser when the default one fails #73

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object JsonFormatters extends DateTimeFormatters {
}

private def parseDate(input: String): Option[Instant] =
scala.util.control.Exception.nonFatalCatch[Instant].opt(Instant.from(ZonedDateTime.parse(input).toInstant)) orElse
scala.util.control.Exception.nonFatalCatch[Instant].opt(ZonedDateTime.parse(input).toInstant) orElse
scala.util.control.Exception.nonFatalCatch[Instant].opt(Instant.from(dateAndOptionalTimeFormatter.parse(input)))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import cats.implicits.*
import io.swagger.v3.oas.models.info.Info
import uk.gov.hmrc.integrationcatalogue.config.AppConfig
import uk.gov.hmrc.integrationcatalogue.models.ApiStatus
import uk.gov.hmrc.integrationcatalogue.models.ApiStatus._
import uk.gov.hmrc.integrationcatalogue.models.ApiStatus.*
import uk.gov.hmrc.integrationcatalogue.models.common.ApiType
import uk.gov.hmrc.integrationcatalogue.models.JsonFormatters.dateAndOptionalTimeFormatter

import java.time.Instant
import java.time.{Instant, ZonedDateTime}
import java.util
import scala.jdk.CollectionConverters.*
import scala.reflect.runtime.universe.*
Expand Down Expand Up @@ -124,6 +124,8 @@ trait OASExtensionsAdapter extends ExtensionKeys {
case Some(x: String) =>
Try[Instant] {
Instant.from(dateAndOptionalTimeFormatter.parse(x))
} orElse Try {
ZonedDateTime.parse(x).toInstant
} match {
case Success(instant) => Validated.valid(instant)
case Failure(_) => "Reviewed date is not a valid date".invalidNel[Instant]
Expand Down