Skip to content

Commit

Permalink
Fix JSON date parsing. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
atherlangga authored Jan 4, 2024
1 parent fefd95b commit 4231235
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private JSONObject convertProtoBuffTimeStampToDateTime(JSONObject jsonObject, St

Date date;
try {
date = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss").parse(timestampObject);
date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(timestampObject);
} catch (java.text.ParseException e) {
throw new RuntimeException(String.format("Not able to parse date, %s", timestampObject));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ public void shouldProperlySerializeEsbMessage() throws DeserializerException {
+ "\\\"s2Id\\\":\\\"3344472187078705152\\\"}\"}");
}

@Test
public void shouldProperlyHandleMiddayCycle() throws DeserializerException {
MessageToJson messageToJson = new MessageToJson(protoParser, false, true);

String logMessageWithMidday = "CgYI9/7PoQYSBgiz/8+hBhgNIICAgIDA9/y0LigCMAM\u003d";
String logKeyWithMidday = "CgYI9/7PoQYSBgiz/8+hBhgNIICAgIDA9/y0LigC";
Message message = new Message(Base64.getDecoder().decode(logKeyWithMidday.getBytes()),
Base64.getDecoder().decode(logMessageWithMidday.getBytes()), "sample-topic", 0, 100);
String actualOutput = messageToJson.serialize(message);
assertEquals(actualOutput, "{\"logMessage\":\"{\\\"uniqueDrivers\\\":\\\"3\\\","
+ "\\\"windowStartTime\\\":\\\"Apr 10, 2023 12:22:15 PM\\\","
+ "\\\"windowEndTime\\\":\\\"Apr 10, 2023 12:23:15 PM\\\",\\\"s2IdLevel\\\":13,\\\"vehicleType\\\":\\\"BIKE\\\","
+ "\\\"s2Id\\\":\\\"3344472187078705152\\\"}\",\"topic\":\"sample-topic\",\"logKey\":\"{"
+ "\\\"windowStartTime\\\":\\\"Apr 10, 2023 12:22:15 PM\\\","
+ "\\\"windowEndTime\\\":\\\"Apr 10, 2023 12:23:15 PM\\\",\\\"s2IdLevel\\\":13,\\\"vehicleType\\\":\\\"BIKE\\\","
+ "\\\"s2Id\\\":\\\"3344472187078705152\\\"}\"}");
}

@Test
public void shouldSerializeWhenKeyIsMissing() throws DeserializerException {
MessageToJson messageToJson = new MessageToJson(protoParser, false, true);
Expand Down

0 comments on commit 4231235

Please sign in to comment.