mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-13 22:58:54 +02:00
ef4c5eb65e
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
40 lines
982 B
Scala
40 lines
982 B
Scala
package com.twitter.timelineranker.model
|
|
|
|
import com.twitter.timelineranker.{thriftscala => thrift}
|
|
import com.twitter.util.Time
|
|
|
|
object TimeRange {
|
|
val default: TimeRange = TimeRange(None, None)
|
|
|
|
def fromThrift(range: thrift.TimeRange): TimeRange = {
|
|
TimeRange(
|
|
from = range.fromMs.map(Time.fromMilliseconds),
|
|
to = range.toMs.map(Time.fromMilliseconds)
|
|
)
|
|
}
|
|
}
|
|
|
|
case class TimeRange(from: Option[Time], to: Option[Time]) extends TimelineRange {
|
|
|
|
throwIfInvalid()
|
|
|
|
def throwIfInvalid(): Unit = {
|
|
(from, to) match {
|
|
case (Some(fromTime), Some(toTime)) =>
|
|
require(fromTime <= toTime, "from-time must be less than or equal to-time.")
|
|
case _ => // valid, do nothing.
|
|
}
|
|
}
|
|
|
|
def toThrift: thrift.TimeRange = {
|
|
thrift.TimeRange(
|
|
fromMs = from.map(_.inMilliseconds),
|
|
toMs = to.map(_.inMilliseconds)
|
|
)
|
|
}
|
|
|
|
def toTimelineRangeThrift: thrift.TimelineRange = {
|
|
thrift.TimelineRange.TimeRange(toThrift)
|
|
}
|
|
}
|