Skip to content

Commit

Permalink
API provides all dates as UTC.
Browse files Browse the repository at this point in the history
Fixes #35.
  • Loading branch information
manuelkiessling committed Mar 7, 2016
1 parent f0dd189 commit d3a87ae
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
4 changes: 3 additions & 1 deletion api/app/controllers/Statistics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class Statistics(statisticsRepository: StatisticsRepository) extends Controller

implicit val dateFormat: Writes[java.util.Date] = new Writes[java.util.Date] {
override def writes(o: java.util.Date): JsValue = {
JsString(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ").format(o))
val sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ")
sdf.setTimeZone(java.util.TimeZone.getTimeZone("UTC"))
JsString(sdf.format(o))
}
}

Expand Down
4 changes: 2 additions & 2 deletions api/test/ApplicationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ class ApplicationSpec extends PlaySpec with OneAppPerSuite {
"""
|[
|{"testresultId":"mocked-testcase1-1",
|"testresultDatetimeRun":"2016-02-20 23:07:12+0100",
|"testresultDatetimeRun":"2016-02-20 22:07:12+0000",
|"runtimeMilliseconds":987,
|"numberOf200":123,
|"numberOf400":456,
|"numberOf500":789},
|{"testresultId":"mocked-testcase1-2",
|"testresultDatetimeRun":"2016-02-20 23:07:12+0100",
|"testresultDatetimeRun":"2016-02-20 22:07:12+0000",
|"runtimeMilliseconds":987,
|"numberOf200":123,
|"numberOf400":456,
Expand Down
22 changes: 11 additions & 11 deletions api/test/IntegrationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,31 @@ class IntegrationSpec extends PlaySpec with OneBrowserPerSuite with OneServerPer
|[
| {
| "testresultId":"testresult3",
| "testresultDatetimeRun":"2016-01-03<space>02:32:12+0100",
| "testresultDatetimeRun":"2016-01-03<space>01:32:12+0000",
| "runtimeMilliseconds":333,
| "numberOf200":123,
| "numberOf400":456,
| "numberOf500":789
| },
| {
| "testresultId":"testresult2",
| "testresultDatetimeRun":"2016-01-02<space>02:32:12+0100",
| "testresultDatetimeRun":"2016-01-02<space>01:32:12+0000",
| "runtimeMilliseconds":222,
| "numberOf200":123,
| "numberOf400":456,
| "numberOf500":789
| },
| {
| "testresultId":"testresult1b",
| "testresultDatetimeRun":"2016-01-01<space>03:32:12+0100",
| "testresultDatetimeRun":"2016-01-01<space>02:32:12+0000",
| "runtimeMilliseconds":111,
| "numberOf200":123,
| "numberOf400":456,
| "numberOf500":789
| },
| {
| "testresultId":"testresult1a",
| "testresultDatetimeRun":"2016-01-01<space>02:32:12+0100",
| "testresultDatetimeRun":"2016-01-01<space>01:32:12+0000",
| "runtimeMilliseconds":111,
| "numberOf200":123,
| "numberOf400":456,
Expand All @@ -125,31 +125,31 @@ class IntegrationSpec extends PlaySpec with OneBrowserPerSuite with OneServerPer
|[
| {
| "testresultId":"testresult3",
| "testresultDatetimeRun":"2016-01-03<space>02:32:12+0100",
| "testresultDatetimeRun":"2016-01-03<space>01:32:12+0000",
| "runtimeMilliseconds":333,
| "numberOf200":123,
| "numberOf400":456,
| "numberOf500":789
| },
| {
| "testresultId":"testresult2",
| "testresultDatetimeRun":"2016-01-02<space>02:32:12+0100",
| "testresultDatetimeRun":"2016-01-02<space>01:32:12+0000",
| "runtimeMilliseconds":222,
| "numberOf200":123,
| "numberOf400":456,
| "numberOf500":789
| },
| {
| "testresultId":"testresult1b",
| "testresultDatetimeRun":"2016-01-01<space>03:32:12+0100",
| "testresultDatetimeRun":"2016-01-01<space>02:32:12+0000",
| "runtimeMilliseconds":111,
| "numberOf200":123,
| "numberOf400":456,
| "numberOf500":789
| },
| {
| "testresultId":"testresult1a",
| "testresultDatetimeRun":"2016-01-01<space>02:32:12+0100",
| "testresultDatetimeRun":"2016-01-01<space>01:32:12+0000",
| "runtimeMilliseconds":111,
| "numberOf200":123,
| "numberOf400":456,
Expand All @@ -166,23 +166,23 @@ class IntegrationSpec extends PlaySpec with OneBrowserPerSuite with OneServerPer
|[
| {
| "testresultId":"testresult3",
| "testresultDatetimeRun":"2016-01-03<space>02:32:12+0100",
| "testresultDatetimeRun":"2016-01-03<space>01:32:12+0000",
| "runtimeMilliseconds":333,
| "numberOf200":123,
| "numberOf400":456,
| "numberOf500":789
| },
| {
| "testresultId":"testresult2",
| "testresultDatetimeRun":"2016-01-02<space>02:32:12+0100",
| "testresultDatetimeRun":"2016-01-02<space>01:32:12+0000",
| "runtimeMilliseconds":222,
| "numberOf200":123,
| "numberOf400":456,
| "numberOf500":789
| },
| {
| "testresultId":"testresult1b",
| "testresultDatetimeRun":"2016-01-01<space>03:32:12+0100",
| "testresultDatetimeRun":"2016-01-01<space>02:32:12+0000",
| "runtimeMilliseconds":111,
| "numberOf200":123,
| "numberOf400":456,
Expand Down
3 changes: 1 addition & 2 deletions api/test/IntegrationWithFailingCassandraSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ import play.api.{ApplicationLoader, Environment, Mode}
class IntegrationWithFailingCassandraSpec extends PlaySpec with OneBrowserPerSuite with OneServerPerSuite with HtmlUnitFactory {

// TODO: Problematic if test case runs at 23:59:59...
val yesterday = Calendar.getInstance()
val yesterday = Calendar.getInstance(java.util.TimeZone.getTimeZone("UTC"))
yesterday.roll(Calendar.DAY_OF_MONTH, -1)
val yesterdayDaybucket = Util.yMd(yesterday)
val yesterdayTimestamp = yesterday.getTime.getTime / 1000 * 1000
val yesterdayDatetime = Util.fullDatetimeWithRfc822Tz(yesterday)
val yesterdayDatetimeUrlEncoded = java.net.URLEncoder.encode(yesterdayDatetime, "utf-8")
// zeroing last three digits because the app time resolution is seconds

class FakeApplicationComponents(context: Context) extends AppComponents(context) {
val s = new ServerStubRunner()
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/scala/util/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import scala.collection.{Seq, mutable}

object Util {
def fullDatetimeWithRfc822Tz(calendar: Calendar): String = {
var sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ")
val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ")
sdf.setTimeZone(java.util.TimeZone.getTimeZone("UTC"))
sdf.format(calendar.getTime)
}

Expand Down

0 comments on commit d3a87ae

Please sign in to comment.