<commit_before>package uk.gov.dvla.vehicles.presentation.common.filters

import org.joda.time.{DateTime, DateTimeZone}
import play.api.mvc.{Result, Filter, RequestHeader,Results}
import uk.gov.dvla.vehicles.presentation.common.filters.ServiceOpen.whitelist
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

trait EnsureServiceOpenFilter extends Filter {

  private val millisPerHour = 3600000
  protected val opening: Int
  protected val closing: Int
  protected val dateTimeZone: DateTimeZoneService
  protected val html: String

  override def apply(nextFilter: (RequestHeader) => Future[Result])(requestHeader: RequestHeader): Future[Result] = {
    if (whitelist.exists(requestHeader.path.contains)) nextFilter(requestHeader)
    else if (!serviceOpen()) Future(Results.Ok(html))
         else nextFilter(requestHeader)
  }

  def serviceOpen(currentDateTime: DateTime = new DateTime(dateTimeZone.currentDateTimeZone)): Boolean = {
    isNotSunday(currentDateTime) && isDuringOpeningHours(currentDateTime.getMillisOfDay)
  }

  def isNotSunday(day: DateTime): Boolean = day.getDayOfWeek != 7

  def isDuringOpeningHours(timeInMillis: Int): Boolean = {
    if (closing >= opening) (timeInMillis >= opening) && (timeInMillis < closing)
    else (timeInMillis >= opening) || (timeInMillis < closing)
  }
}

trait DateTimeZoneService {<commit_msg>Title is the focus element on the private keeper page<commit_after>package uk.gov.dvla.vehicles.presentation.common.filters

import org.joda.time.{DateTime, DateTimeZone}
import play.api.mvc.{Result, Filter, RequestHeader,Results}
import uk.gov.dvla.vehicles.presentation.common.filters.ServiceOpen.whitelist
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

trait EnsureServiceOpenFilter extends Filter {

  protected val opening: Int
  protected val closing: Int
  protected val dateTimeZone: DateTimeZoneService
  protected val html: Appendable

  override def apply(nextFilter: (RequestHeader) => Future[Result])(requestHeader: RequestHeader): Future[Result] = {
    if (whitelist.exists(requestHeader.path.contains)) nextFilter(requestHeader)
    else if (!serviceOpen()) Future(Results.Ok(html))
         else nextFilter(requestHeader)
  }

  def serviceOpen(currentDateTime: DateTime = new DateTime(dateTimeZone.currentDateTimeZone)): Boolean = {
    isNotSunday(currentDateTime) && isDuringOpeningHours(currentDateTime.getMillisOfDay)
  }

  def isNotSunday(day: DateTime): Boolean = day.getDayOfWeek != 7

  def isDuringOpeningHours(timeInMillis: Int): Boolean = {
    if (closing >= opening) (timeInMillis >= opening) && (timeInMillis < closing)
    else (timeInMillis >= opening) || (timeInMillis < closing)
  }
}

trait DateTimeZoneService {
{'fraction_non_alphanumeric': 0.09964028776978417, 'fraction_numerical': 0.003237410071942446, 'mean_word_length': 5.733656174334141, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3754594', 'n_tokens_mistral': 810, 'n_tokens_neox': 793, 'n_words': 179}