Skip to content
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 @@ -43,9 +43,12 @@ public final class CommunicationClientCredential {

// Previously DateTimeFormatter.RFC_1123_DATE_TIME was being used. There
// was an issue with the day of month part. RFC_1123_DATE_TIME does not
// append a leading '0' on days that are less than 10.
// append a leading '0' on days that are less than 10. It is important
// that the locale remain US. In other locals the values that are generated
// for the day and month strings may be different. (e.g. Canada day strings
// have a '.' at the end)
static final DateTimeFormatter HMAC_DATETIMEFORMATTER_PATTERN =
DateTimeFormatter.ofPattern("E, dd MMM YYYY HH:mm:ss 'GMT'");
DateTimeFormatter.ofPattern("E, dd MMM YYYY HH:mm:ss 'GMT'", Locale.US);

private final ClientLogger logger = new ClientLogger(CommunicationClientCredential.class);
private final Mac sha256HMAC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.Test;

import java.time.ZonedDateTime;
import java.util.Locale;
import java.time.ZoneId;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -26,6 +27,18 @@ public void twentyFourHourClockTest() {
assertEquals("Wed, 01 Jan 2020 23:01:00 GMT", getDateTimeString(2020, 1, 1, 23, 1, 0));
}

@Test
public void twentyFourHourClockTestNonUSLocale() {
Locale defaultLocale = Locale.getDefault();

try {
Locale.setDefault(Locale.CANADA);
assertEquals("Wed, 01 Jan 2020 23:01:00 GMT", getDateTimeString(2020, 1, 1, 23, 1, 0));
} finally {
Locale.setDefault(defaultLocale);
}
}

private String getDateTimeString(int year, int month, int day, int hour, int minute, int second) {
ZonedDateTime dateTime = ZonedDateTime.of(year, month, day, hour, minute, second, 0 /* nanoOfSecond */, ZoneId.of("UTC"));
return dateTime.format(CommunicationClientCredential.HMAC_DATETIMEFORMATTER_PATTERN);
Expand Down