Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
time format
successJsonResponse(Extraction.decompose(json)(formats = new Formats {
import java.text.{ParseException, SimpleDateFormat}
val dateFormat = new DateFormat {
def parse(s: String) = try {
Some(formatter.parse(s))
} catch {
case e: ParseException => None
}
def format(d: Date) = formatter.format(d)
private def formatter = {
val f = dateFormatter
f.setTimeZone(new GregorianCalendar().getTimeZone)
f
}
}
protected def dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
}))
@hongwei1

This comment has been minimized.

Copy link
Owner Author

@hongwei1 hongwei1 commented Mar 8, 2017

val importJsonDateFormat = {
val f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
//setting the time zone is important!
f.setTimeZone(TimeZone.getTimeZone("UTC"))
f
}

  t.transactionType should equal(dummyKind)

  //compare time as a long to avoid issues comparing Dates, e.g. java.util.Date vs java.sql.Date
  t.startDate.getTime should equal(importJsonDateFormat.parse(startDate).getTime) 
  t.finishDate.getTime should equal(importJsonDateFormat.parse(endDate).getTime)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment