<commit_before>package constraints.common

import models.DayMonthYear
import org.joda.time.DateTime
import play.api.data.validation.{Constraint, ValidationError, Valid, Invalid}
import scala.util.Try
import services.DateService

object DayMonthYear {
  private final val MinYear = 999
  private final val MaxYear = 9999

  def required: Constraint[Int] = Constraint[Int]("constraint.required") {
    case i if i > 0 => Valid
    case _ => Invalid(ValidationError("error.dropDownInvalid")) // TODO test coverage
  }

  def validDate(minYear: Int = MinYear, maxYear: Int = MaxYear): Constraint[DayMonthYear] = {
    def isValidDateTime(dmy: DayMonthYear) = Try(new DateTime(dmy.year, dmy.month, dmy.day, 0, 0)).isSuccess
    def isWithinYearBounds(dmy: DayMonthYear) = dmy.year > minYear && dmy.year < maxYear

    Constraint("constraint.required") {
      case dmy: DayMonthYear if isValidDateTime(dmy) && isWithinYearBounds(dmy)  => Valid
      case dmy: DayMonthYear => Invalid(ValidationError("error.invalid"))
      case _ => Invalid(ValidationError("error.required")) // TODO test coverage
    }
  }

  def after(earliest: DayMonthYear): Constraint[DayMonthYear] = {
    Constraint("constraint.withinTwoYears") {
      case dmy: DayMonthYear if dmy >= earliest => Valid
      case _ => Invalid(ValidationError("error.withinTwoYears"))
    }
  }

  def notInFuture(dateService: DateService): Constraint[DayMonthYear] = {
    Constraint("constraint.notInFuture") {
      case dmy: DayMonthYear if dmy <= dateService.today => Valid
      case _ => Invalid(ValidationError("error.notInFuture"))
    }
  }

}<commit_msg>Fixing up a compilation warning<commit_after>package constraints.common

import models.{DayMonthYear => ModelsDMY}
import org.joda.time.DateTime
import play.api.data.validation.{Constraint, ValidationError, Valid, Invalid}
import scala.util.Try
import services.DateService

object DayMonthYear {
  private final val MinYear = 999
  private final val MaxYear = 9999

  def required: Constraint[Int] = Constraint[Int]("constraint.required") {
    case i if i > 0 => Valid
    case _ => Invalid(ValidationError("error.dropDownInvalid")) // TODO test coverage
  }

  def validDate(minYear: Int = MinYear, maxYear: Int = MaxYear): Constraint[ModelsDMY] = {
    def isValidDateTime(dmy: ModelsDMY) = Try(new DateTime(dmy.year, dmy.month, dmy.day, 0, 0)).isSuccess
    def isWithinYearBounds(dmy: ModelsDMY) = dmy.year > minYear && dmy.year < maxYear

    Constraint("constraint.required") {
      case dmy: ModelsDMY if isValidDateTime(dmy) && isWithinYearBounds(dmy)  => Valid
      case dmy: ModelsDMY => Invalid(ValidationError("error.invalid"))
      case _ => Invalid(ValidationError("error.required")) // TODO test coverage
    }
  }

  def after(earliest: ModelsDMY): Constraint[ModelsDMY] = {
    Constraint("constraint.withinTwoYears") {
      case dmy: ModelsDMY if dmy >= earliest => Valid
      case _ => Invalid(ValidationError("error.withinTwoYears"))
    }
  }

  def notInFuture(dateService: DateService): Constraint[ModelsDMY] = {
    Constraint("constraint.notInFuture") {
      case dmy: ModelsDMY if dmy <= dateService.today => Valid
      case _ => Invalid(ValidationError("error.notInFuture"))
    }
  }

}
{'fraction_non_alphanumeric': 0.11724776303609998, 'fraction_numerical': 0.006170934896636841, 'mean_word_length': 4.323481116584565, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6027088', 'n_tokens_mistral': 1022, 'n_tokens_neox': 966, 'n_words': 227}