Skip to content

Commit

Permalink
form dates can be up to 11 years in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Nov 26, 2024
1 parent 4853a7c commit 7a3d81e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 8 additions & 2 deletions modules/common/src/main/Form.scala
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,14 @@ object Form:
formatter
.stringFormatter[List[String]](_.mkString(sep), _.split(sep).map(_.trim).toList.filter(_.nonEmpty))

def inTheFuture(m: Mapping[Instant]) =
m.verifying("The date must be set in the future", _.isAfterNow)
private val dateHumanFormatter =
import java.time.format.*
DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)

def inTheFuture(m: Mapping[Instant], max: Instant = nowInstant.plusYears(11)) =
m
.verifying("The date must be set in the future", _.isAfterNow)
.verifying(s"The date must be set before ${dateHumanFormatter.print(max)}", _.isBefore(max))

object ISODate:
val pattern = "yyyy-MM-dd"
Expand Down
9 changes: 3 additions & 6 deletions modules/swiss/src/main/SwissForm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,9 @@ final class SwissForm(using mode: play.api.Mode):
)
)

def nextRound =
Form(
single(
"date" -> inTheFuture(ISOInstantOrTimestamp.mapping)
)
)
def nextRound = Form:
single:
"date" -> inTheFuture(ISOInstantOrTimestamp.mapping)

object SwissForm:

Expand Down

0 comments on commit 7a3d81e

Please sign in to comment.