Skip to content

Commit 78852a9

Browse files
authored
fix(fcm): Fix issues in event_time timestamp parsing (#338)
* fix issues in event_time timestamp conversion * fix the formatting issue in event_time timestamp
1 parent 83b7a64 commit 78852a9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/main/java/com/google/firebase/messaging/AndroidNotification.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Date;
2929
import java.util.List;
3030
import java.util.Map;
31+
import java.util.TimeZone;
3132
import java.util.concurrent.TimeUnit;
3233

3334
/**
@@ -456,8 +457,9 @@ public Builder setSticky(boolean sticky) {
456457
* @return This builder.
457458
*/
458459
public Builder setEventTimeInMillis(long eventTimeInMillis) {
459-
this.eventTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'")
460-
.format(new Date(eventTimeInMillis));
460+
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS000000'Z'");
461+
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
462+
this.eventTime = dateFormat.format(new Date(eventTimeInMillis));
461463
return this;
462464
}
463465

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -859,15 +859,13 @@ public void testExtendedAndroidNotificationParameters() throws IOException {
859859
.put("title", "title")
860860
.put("body", "body")
861861
.build();
862-
String eventTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'", Locale.US)
863-
.format(new Date(1546304523123L));
864862
Map<String, Object> androidConfig = ImmutableMap.<String, Object>builder()
865863
.put("notification", ImmutableMap.<String, Object>builder()
866864
.put("title", "android-title")
867865
.put("body", "android-body")
868866
.put("ticker", "ticker")
869867
.put("sticky", true)
870-
.put("event_time", eventTime)
868+
.put("event_time", "2019-01-01T01:02:03.123000000Z")
871869
.put("local_only", true)
872870
.put("notification_priority", "PRIORITY_HIGH")
873871
.put("vibrate_timings", ImmutableList.of("1s", "1.001000000s"))

0 commit comments

Comments
 (0)