uk.co.unclealex.days.DSL.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thank-you-for-the-days_2.13 Show documentation
Show all versions of thank-you-for-the-days_2.13 Show documentation
A useful DSL for testing with dates.
The newest version!
package uk.co.unclealex.days
import java.time.{Instant, LocalDate, LocalDateTime, ZoneId, ZonedDateTime}
trait DSL {
val January: Month = Month.January
val February: Month = Month.February
val March: Month = Month.March
val April: Month = Month.April
val May: Month = Month.May
val June: Month = Month.June
val July: Month = Month.July
val August: Month = Month.August
val September: Month = Month.September
val October: Month = Month.October
val November: Month = Month.November
val December: Month = Month.December
implicit def toZonedDateTime(
dateAndTime: DateAndTime
)(implicit zoneId: ZoneId): ZonedDateTime = {
dateAndTime.toZonedDateTime(zoneId)
}
implicit def toInstant(
dateAndTime: DateAndTime
)(implicit zoneId: ZoneId): Instant = {
toZonedDateTime(dateAndTime).toInstant
}
implicit val toLocalDateTime: DateAndTime => LocalDateTime = _.toLocalDateTime
implicit val toLocalDate: Date => LocalDate = _.toLocalDate
implicit class IntegersAsHours(hour: Int) {
def am: Time = Time(hour, 0).am
def pm: Time = Time(hour, 0).pm
def asIs: Time = Time(hour, 0)
private def base(
tens: Int
): (Time, Time, Time, Time, Time, Time, Time, Time, Time, Time) = {
def withMinutes(units: Int): Time = {
Time(hour, tens * 10 + units)
}
(
withMinutes(0),
withMinutes(1),
withMinutes(2),
withMinutes(3),
withMinutes(4),
withMinutes(5),
withMinutes(6),
withMinutes(7),
withMinutes(8),
withMinutes(9)
)
}
val (_00, _01, _02, _03, _04, _05, _06, _07, _08, _09) = base(0)
val (_10, _11, _12, _13, _14, _15, _16, _17, _18, _19) = base(1)
val (_20, _21, _22, _23, _24, _25, _26, _27, _28, _29) = base(2)
val (_30, _31, _32, _33, _34, _35, _36, _37, _38, _39) = base(3)
val (_40, _41, _42, _43, _44, _45, _46, _47, _48, _49) = base(4)
val (_50, _51, _52, _53, _54, _55, _56, _57, _58, _59) = base(5)
}
}
object DSL extends DSL
© 2015 - 2024 Weber Informatics LLC | Privacy Policy