<commit_before>package almhirt.common

import scalaz._, Scalaz._
import org.joda.time.{ DateTime, DateTimeZone, LocalDateTime }
import scala.concurrent.duration.FiniteDuration

trait CanCreateUuid { def getUuid(): java.util.UUID; def getUniqueString(): String }

trait CanCreateDateTime { def getDateTime(): DateTime; def getUtcTimestamp: LocalDateTime }

trait CanCreateUuidsAndDateTimes extends CanCreateUuid with CanCreateDateTime

object CanCreateUuidsAndDateTimes {
  def apply(): CanCreateUuidsAndDateTimes = new CanCreateUuidsAndDateTimes {
    override def getUuid(): java.util.UUID = java.util.UUID.randomUUID()
    override def getUniqueString(): String = almhirt.converters.MiscConverters.uuidToBase64String(java.util.UUID.randomUUID())
    override def getDateTime(): DateTime = new DateTime()
    override def getUtcTimestamp(): LocalDateTime = new LocalDateTime(DateTimeZone.UTC)
  }

  def utc(): CanCreateUuidsAndDateTimes = new CanCreateUuidsAndDateTimes {
    override def getUuid(): java.util.UUID = java.util.UUID.randomUUID()
    override def getUniqueString(): String = almhirt.converters.MiscConverters.uuidToBase64String(java.util.UUID.randomUUID())
    override def getDateTime(): DateTime = new DateTime(DateTimeZone.UTC)
    override def getUtcTimestamp(): LocalDateTime = new LocalDateTime(DateTimeZone.UTC)
  }

  def timeShifted(timeShift: FiniteDuration): CanCreateUuidsAndDateTimes = {
    val timeshiftMillis = timeShift.toMillis.toInt
    new CanCreateUuidsAndDateTimes {
      override def getUuid(): java.util.UUID = java.util.UUID.randomUUID()
      override def getUniqueString(): String = almhirt.converters.MiscConverters.uuidToBase64String(java.util.UUID.randomUUID())
      override def getDateTime(): DateTime = new DateTime(DateTimeZone.UTC).plusMillis(timeshiftMillis)
      override def getUtcTimestamp(): LocalDateTime = new LocalDateTime(DateTimeZone.UTC).plusMillis(timeshiftMillis)
    }
  }

  private val regexStr = """(?:[-\w:@&=+,.!~*'_;]|%\p{XDigit}{2})(?:[-\w:@&=+,.!~*'$_;]|%\p{XDigit}{2})*"""
  private val regex = regexStr.r
  def validateUniqueStringId(str: String): AlmValidation[String] =
    if ((regex findFirstIn str).nonEmpty) {
      str.success
    } else {
      BadDataProblem(s""""$id" is not a valid id. It must conform to the regular expression "$regexStr".""").failure
    }
}<commit_msg>timeshift in seconds<commit_after>package almhirt.common

import scalaz._, Scalaz._
import org.joda.time.{ DateTime, DateTimeZone, LocalDateTime }
import scala.concurrent.duration.FiniteDuration

trait CanCreateUuid { def getUuid(): java.util.UUID; def getUniqueString(): String }

trait CanCreateDateTime { def getDateTime(): DateTime; def getUtcTimestamp: LocalDateTime }

trait CanCreateUuidsAndDateTimes extends CanCreateUuid with CanCreateDateTime

object CanCreateUuidsAndDateTimes {
  def apply(): CanCreateUuidsAndDateTimes = new CanCreateUuidsAndDateTimes {
    override def getUuid(): java.util.UUID = java.util.UUID.randomUUID()
    override def getUniqueString(): String = almhirt.converters.MiscConverters.uuidToBase64String(java.util.UUID.randomUUID())
    override def getDateTime(): DateTime = new DateTime()
    override def getUtcTimestamp(): LocalDateTime = new LocalDateTime(DateTimeZone.UTC)
  }

  def utc(): CanCreateUuidsAndDateTimes = new CanCreateUuidsAndDateTimes {
    override def getUuid(): java.util.UUID = java.util.UUID.randomUUID()
    override def getUniqueString(): String = almhirt.converters.MiscConverters.uuidToBase64String(java.util.UUID.randomUUID())
    override def getDateTime(): DateTime = new DateTime(DateTimeZone.UTC)
    override def getUtcTimestamp(): LocalDateTime = new LocalDateTime(DateTimeZone.UTC)
  }

  def timeShifted(timeShift: FiniteDuration): CanCreateUuidsAndDateTimes = {
    val timeshiftSeconds = timeShift.toSeconds.toInt
    new CanCreateUuidsAndDateTimes {
      override def getUuid(): java.util.UUID = java.util.UUID.randomUUID()
      override def getUniqueString(): String = almhirt.converters.MiscConverters.uuidToBase64String(java.util.UUID.randomUUID())
      override def getDateTime(): DateTime = new DateTime(DateTimeZone.UTC).plusSeconds(timeshiftSeconds)
      override def getUtcTimestamp(): LocalDateTime = new LocalDateTime(DateTimeZone.UTC).plusSeconds(timeshiftSeconds)
    }
  }

  private val regexStr = """(?:[-\w:@&=+,.!~*'_;]|%\p{XDigit}{2})(?:[-\w:@&=+,.!~*'$_;]|%\p{XDigit}{2})*"""
  private val regex = regexStr.r
  def validateUniqueStringId(str: String): AlmValidation[String] =
    if ((regex findFirstIn str).nonEmpty) {
      str.success
    } else {
      BadDataProblem(s""""$id" is not a valid id. It must conform to the regular expression "$regexStr".""").failure
    }
}
{'fraction_non_alphanumeric': 0.11906269791006967, 'fraction_numerical': 0.0033776651889381466, 'mean_word_length': 5.292164674634794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '418752', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1452, 'n_words': 308}