Skip to content

Pass "Locale-US" to SimpleDateFormat while formatting first-open time… #3877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ private JSONObject createFetchRequestBody(
}

private String convertToISOString(long millisFromEpoch) {
SimpleDateFormat isoDateFormat = new SimpleDateFormat(ISO_DATE_PATTERN);
// ISO-8601 Timestamp expects Western Arabic numerals. Locale.US ensures that the english
// numerals are not converted to the local language numerals.
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