Repository: firebase/firebase-admin-java (java)

Issue:
Incorrect timestamp format in AndroidNotification.event_time
I think the way we format the `event_time` field on `AndroidNotification` is wrong:

https://github.com/firebase/firebase-admin-java/blob/83b7a64c103fbf20f46c04df229000529e9a8d2d/src/main/java/com/google/firebase/messaging/AndroidNotification.java#L458-L462

There seems to be couple of issues with this.

1. We are not specifying the timezone for the `SimpleDateFormat`. Therefore the resulting timestamp string is in the local timezone while the backend expects it to be in UTC.
2. The way nanoseconds are formatted seems to be wrong. For the milliseconds value `1546304523123L` this generates the string `2019-01-01T01:02:03.000000123Z`. I would expect the nanos to be formatted as `123000000` (i.e. 123 milliseconds in nanos).

Pull request description:
fix(fcm): Fix issues in event_time timestamp parsing
- Set the timezone to always be UTC.
- Pending zeros after the millisecond digits to the right instead of left.

RELEASE NOTE: `AndroidNotification` class now correctly formats the `event_time` field sent to the Cloud Messaging service.

Resolves #337

Patch:
diff --git a/src/main/java/com/google/firebase/messaging/AndroidNotification.java b/src/main/java/com/google/firebase/messaging/AndroidNotification.java
index 08a872c..05e6809 100644
--- a/src/main/java/com/google/firebase/messaging/AndroidNotification.java
+++ b/src/main/java/com/google/firebase/messaging/AndroidNotification.java
@@ -28,6 +28,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -456,8 +457,9 @@ public class AndroidNotification {
      * @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;
     }
 


Test patch:
diff --git a/src/test/java/com/google/firebase/messaging/MessageTest.java b/src/test/java/com/google/firebase/messaging/MessageTest.java
index 5c8c3cb..778b4f1 100644
--- a/src/test/java/com/google/firebase/messaging/MessageTest.java
+++ b/src/test/java/com/google/firebase/messaging/MessageTest.java
@@ -859,15 +859,13 @@ public class MessageTest {
         .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"))