Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirumaramba committed Nov 5, 2020
1 parent 0de7c09 commit a71dcd2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
16 changes: 5 additions & 11 deletions src/main/java/com/google/firebase/remoteconfig/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
*/
public final class Version {

private static final Pattern ZULU_TIME_NO_NANOSECONDS_PATTERN = Pattern
.compile("^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})");

private final String versionNumber;
private final long updateTime;
private final String updateOrigin;
Expand All @@ -69,19 +66,16 @@ private Version() {
if (!Strings.isNullOrEmpty(versionResponse.getUpdateTime())) {
// Update Time is a timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds.
// example: "2014-10-02T15:01:23.045123456Z"
// SimpleDateFormat cannot handle nanoseconds, therefore we drop nanoseconds from the string.
Matcher errorMatcher = ZULU_TIME_NO_NANOSECONDS_PATTERN
.matcher(versionResponse.getUpdateTime());
String updateTimeWithoutNanoseconds = "";
if (errorMatcher.find()) {
updateTimeWithoutNanoseconds = errorMatcher.group(1);
}
// SimpleDateFormat cannot handle nanoseconds, therefore we strip nanoseconds from the string.
String updateTime = versionResponse.getUpdateTime();
int indexOfPeriod = !updateTime.contains(".") ? 0 : updateTime.indexOf(".");
String updateTimeWithoutNanoseconds = updateTime.substring(0, indexOfPeriod);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
this.updateTime = dateFormat.parse(updateTimeWithoutNanoseconds).getTime();
} catch (ParseException e) {
throw new IllegalStateException();
throw new IllegalStateException("Unable to parse update time.", e);
}
} else {
this.updateTime = 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void testGetTemplate() throws Exception {
.setEmail("firebase-user@account.com")
.setName("dev-admin")
.setImageUrl("http://image.jpg"))
.setUpdateTime("2020-11-03T20:24:15.203Z")
.setUpdateTime("2020-11-03T20:24:15.045123456Z")
.setDescription("promo config")
);

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/getRemoteConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"name": "dev-admin",
"imageUrl": "http://image.jpg"
},
"updateTime": "2020-11-03T20:24:15.203Z",
"updateTime": "2020-11-03T20:24:15.045123456ZZ",
"description": "promo config"
}
}

0 comments on commit a71dcd2

Please sign in to comment.