Skip to content

Commit 76f0f95

Browse files
sakebookhiranya911
authored andcommitted
Fix Date test in another Locale (#327)
* Add Locale.ROOT use SimpleDateFormat * Fix SimpleDateFormat locale use UK * Change default locale to US
1 parent b7b7125 commit 76f0f95

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/main/java/com/google/firebase/internal/DateUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.text.SimpleDateFormat;
2121
import java.util.Calendar;
2222
import java.util.Date;
23+
import java.util.Locale;
2324
import java.util.TimeZone;
2425

2526
/**
@@ -57,9 +58,9 @@ final class DateUtils {
5758
static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy";
5859

5960
private static final SimpleDateFormat[] DEFAULT_PATTERNS = new SimpleDateFormat[] {
60-
new SimpleDateFormat(PATTERN_RFC1123),
61-
new SimpleDateFormat(PATTERN_RFC1036),
62-
new SimpleDateFormat(PATTERN_ASCTIME)
61+
new SimpleDateFormat(PATTERN_RFC1123, Locale.US),
62+
new SimpleDateFormat(PATTERN_RFC1036, Locale.US),
63+
new SimpleDateFormat(PATTERN_ASCTIME, Locale.US)
6364
};
6465

6566
static final TimeZone GMT = TimeZone.getTimeZone("GMT");

src/test/java/com/google/firebase/internal/RetryUnsuccessfulResponseHandlerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
import java.util.ArrayList;
3636
import java.util.Date;
3737
import java.util.List;
38+
import java.util.Locale;
3839
import java.util.TimeZone;
40+
3941
import org.junit.Test;
4042

4143
public class RetryUnsuccessfulResponseHandlerTest {
@@ -137,7 +139,8 @@ public void testRetryAfterGivenAsSeconds() throws IOException {
137139

138140
@Test
139141
public void testRetryAfterGivenAsDate() throws IOException {
140-
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
142+
SimpleDateFormat dateFormat =
143+
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
141144
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
142145
Date date = new Date(1000);
143146
Clock clock = new FixedClock(date.getTime());

src/test/java/com/google/firebase/messaging/MessageTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Date;
3434
import java.util.HashMap;
3535
import java.util.List;
36+
import java.util.Locale;
3637
import java.util.Map;
3738
import java.util.concurrent.TimeUnit;
3839
import org.junit.Test;
@@ -769,7 +770,7 @@ public void testImageInAndroidNotification() throws IOException {
769770
assertJsonEquals(ImmutableMap.of(
770771
"topic", "test-topic", "notification", notification, "android", androidConfig), message);
771772
}
772-
773+
773774
@Test
774775
public void testImageInApnsNotification() throws IOException {
775776
Message message = Message.builder()
@@ -799,7 +800,7 @@ public void testImageInApnsNotification() throws IOException {
799800
.build();
800801
assertJsonEquals(expected, message);
801802
}
802-
803+
803804
@Test
804805
public void testInvalidColorInAndroidNotificationLightSettings() throws IOException {
805806
try {
@@ -814,7 +815,7 @@ public void testInvalidColorInAndroidNotificationLightSettings() throws IOExcept
814815
// expected
815816
}
816817
}
817-
818+
818819
@Test
819820
public void testExtendedAndroidNotificationParameters() throws IOException {
820821
long[] vibrateTimings = {1000L, 1001L};
@@ -848,7 +849,7 @@ public void testExtendedAndroidNotificationParameters() throws IOException {
848849
.put("title", "title")
849850
.put("body", "body")
850851
.build();
851-
String eventTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'")
852+
String eventTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'", Locale.US)
852853
.format(new Date(1546304523123L));
853854
Map<String, Object> androidConfig = ImmutableMap.<String, Object>builder()
854855
.put("notification", ImmutableMap.<String, Object>builder()

0 commit comments

Comments
 (0)