[go: nahoru, domu]

Skip to content

Commit

Permalink
Pass "Locale-US" to SimpleDateFormat while formatting first-open time…
Browse files Browse the repository at this point in the history
…. This makes sure that first-open time digits are not formatted to the local language characters.

This change is a fix for #3757
  • Loading branch information
richaurora committed Jul 6, 2022
1 parent 085c946 commit d21d501
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ private JSONObject createFetchRequestBody(
if (firstOpenTime != null) {
requestBodyMap.put(FIRST_OPEN_TIME, convertToISOString(firstOpenTime));
}

System.out.println(requestBodyMap);
return new JSONObject(requestBodyMap);
}

private String convertToISOString(long millisFromEpoch) {
SimpleDateFormat isoDateFormat = new SimpleDateFormat(ISO_DATE_PATTERN);
SimpleDateFormat isoDateFormat = new SimpleDateFormat(ISO_DATE_PATTERN, Locale.US);
isoDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return isoDateFormat.format(millisFromEpoch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,25 @@ public void fetch_nullFirstOpenTime_fieldNotPresentInRequestBody() throws Except
assertFalse(requestBody.has(FIRST_OPEN_TIME));
}

@Test
public void fetch_firstOpenTimeFromNonEnglishLanguageLocale_digitsInEnglishInRequestBody()
throws Exception {
String languageTag = "ar-AE"; // Language Tag for UAE Arabic
Locale.setDefault(Locale.forLanguageTag(languageTag));

setServerResponseTo(noChangeResponseBody, SECOND_ETAG);

Map<String, String> customUserProperties = ImmutableMap.of("up1", "hello", "up2", "world");
long firstOpenTimeEpochFromMillis = 1636146000000L;
// ISO-8601 value corresponding to 1636146000000 ms-from-epoch in UTC
String firstOpenTimeIsoString = "2021-11-05T21:00:00.000Z";

fetch(FIRST_ETAG, customUserProperties, firstOpenTimeEpochFromMillis);

JSONObject requestBody = new JSONObject(fakeHttpURLConnection.getOutputStream().toString());
assertThat(requestBody.get(FIRST_OPEN_TIME)).isEqualTo(firstOpenTimeIsoString);
}

@Test
public void fetch_requestEncodesLanguageSubtags() throws Exception {
String languageTag = "zh-Hant-TW"; // Taiwan Chinese in traditional script
Expand Down

0 comments on commit d21d501

Please sign in to comment.