aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/com/drivergrp/core/time.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/com/drivergrp/core/time.scala')
-rw-r--r--src/main/scala/com/drivergrp/core/time.scala12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/main/scala/com/drivergrp/core/time.scala b/src/main/scala/com/drivergrp/core/time.scala
index 9bafb00..e04343b 100644
--- a/src/main/scala/com/drivergrp/core/time.scala
+++ b/src/main/scala/com/drivergrp/core/time.scala
@@ -21,19 +21,23 @@ object time {
final case class Time(millis: Long) extends AnyVal {
- def isBefore(anotherTime: Time): Boolean = millis < anotherTime.millis
+ def isBefore(anotherTime: Time): Boolean = implicitly[Ordering[Time]].lt(this, anotherTime)
- def isAfter(anotherTime: Time): Boolean = millis > anotherTime.millis
+ def isAfter(anotherTime: Time): Boolean = implicitly[Ordering[Time]].gt(this, anotherTime)
def advanceBy(duration: Duration): Time = Time(millis + duration.toMillis)
}
+ object Time {
+
+ implicit def timeOrdering: Ordering[Time] = Ordering.by(_.millis)
+ }
+
+
final case class TimeRange(start: Time, end: Time) {
def duration: Duration = FiniteDuration(end.millis - start.millis, MILLISECONDS)
}
- implicit def timeOrdering: Ordering[Time] = Ordering.by(_.millis)
-
def startOfMonth(time: Time) = {
Time(make(new GregorianCalendar()) { cal =>
cal.setTime(new Date(time.millis))