Skip to content

fix(fcm): Fix issues in event_time timestamp parsing #338

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 4 commits into from
Dec 19, 2019
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 @@ -28,6 +28,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -456,8 +457,9 @@ public Builder setSticky(boolean sticky) {
* @return This builder.
*/
public Builder setEventTimeInMillis(long eventTimeInMillis) {
this.eventTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'")
.format(new Date(eventTimeInMillis));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS000000'Z'");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
this.eventTime = dateFormat.format(new Date(eventTimeInMillis));
return this;
}

Expand Down
4 changes: 1 addition & 3 deletions src/test/java/com/google/firebase/messaging/MessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -859,15 +859,13 @@ public void testExtendedAndroidNotificationParameters() throws IOException {
.put("title", "title")
.put("body", "body")
.build();
String eventTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSSS'Z'", Locale.US)
.format(new Date(1546304523123L));
Map<String, Object> androidConfig = ImmutableMap.<String, Object>builder()
.put("notification", ImmutableMap.<String, Object>builder()
.put("title", "android-title")
.put("body", "android-body")
.put("ticker", "ticker")
.put("sticky", true)
.put("event_time", eventTime)
.put("event_time", "2019-01-01T01:02:03.123000000Z")
.put("local_only", true)
.put("notification_priority", "PRIORITY_HIGH")
.put("vibrate_timings", ImmutableList.of("1s", "1.001000000s"))
Expand Down