Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ import javax.ws.rs.core.Response.Status
import scala.util.Try

private[v1] class SimpleDateParam(val originalValue: String) {

private val formats: Seq[SimpleDateFormat] = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this is a field though. There's no need for that. The format objects can be created on demand to parse the input. If this SimpleDateParam object is short-lived I suppose it does not matter much but I would have just inlined all this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inlined formats.

val gmtDay = new SimpleDateFormat("yyyy-MM-dd")
gmtDay.setTimeZone(TimeZone.getTimeZone("GMT"))

Seq(
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz"),
gmtDay
)
}

val timestamp: Long = {
SimpleDateParam.formats.collectFirst {
formats.collectFirst {
case fmt if Try(fmt.parse(originalValue)).isSuccess =>
fmt.parse(originalValue).getTime()
}.getOrElse(
Expand All @@ -39,17 +50,3 @@ private[v1] class SimpleDateParam(val originalValue: String) {
)
}
}

private[v1] object SimpleDateParam {

val formats: Seq[SimpleDateFormat] = {

val gmtDay = new SimpleDateFormat("yyyy-MM-dd")
gmtDay.setTimeZone(TimeZone.getTimeZone("GMT"))

Seq(
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz"),
gmtDay
)
}
}