Skip to content

fix(fcm): Omit event_time when AndroidNotification.EventTimestamp is not set - #619

Open
caglarenes wants to merge 1 commit into
firebase:mainfrom
caglarenes:fix/android-event-time-default
Open

caglarenes wants to merge 1 commit into
firebase:mainfrom
caglarenes:fix/android-event-time-default

Conversation

@caglarenes

Copy link
Copy Markdown

Fixes #618.

AndroidNotification.EventTimestamp is a non-nullable DateTime, and the private
EventTimeString helper always returned a formatted value. A notification that never set
EventTimestamp was therefore sent with "event_time": "0001-01-01T00:00:00.000000000Z". On
hosts west of UTC the value was shifted by the UTC offset. The FCM Android SDK uses event_time
as the notification's when, so these notifications show a wrong time and the drawer sorts them
as the oldest entries.

EventTimeString now returns null when EventTimestamp is default(DateTime).
NewtonsoftJsonSerializer omits null values, so event_time is left out of the request.
Priority, Visibility, Proxy and VibrateTimingsMillis are omitted the same way when they
are unset. The XML doc for EventTimestamp now says that the default value is not sent.
Deserialization is unchanged: a payload without event_time leaves the default value, and the
round trip still omits it.

Why not change the type to DateTime?

  • DateTime? gives a clearer API. It matches the other optional members of this class, the
    other Admin SDKs, and AndroidNotificationV2 in feat(fcm): Add support for AndroidConfigV2 #537. However, it changes a public property's
    type:

    • Binary break: assemblies compiled against 3.x fail with MissingMethodException on
      get_EventTimestamp and set_EventTimestamp until they are recompiled. This hits libraries
      that depend on FirebaseAdmin.
    • Source break for code that reads the value, for example n.EventTimestamp.ToString("o"),
      .Year, or passing it to a DateTime parameter.

    Under semver, both breaks require a major release.

  • The default sentinel (this PR) changes neither the API nor the ABI, so it can ship in a
    patch release. The only cost is that a caller can no longer send exactly
    0001-01-01T00:00:00 (DateTime == ignores Kind). That value is not a meaningful event time.

  • feat(fcm): Add support for AndroidConfigV2 #537 deprecates this class in favor of the nullable AndroidNotificationV2. Changing the
    legacy type now would be churn on an API that is being phased out.

Testing

  • Added MessageTest.AndroidNotificationWithoutEventTimestamp and
    MessageTest.AndroidNotificationWithEventTimestamp. Before the fix, the first test fails
    because the actual JSON contains "event_time": "0001-01-01T00:00:00.000000000Z". After the
    fix, both tests pass.

  • Ran dotnet test FirebaseAdmin.Tests --filter "FullyQualifiedName~FirebaseAdmin.Messaging"
    with .NET SDK 11.0.100:

    Run Total Passed Failed
    net6.0 121 120 1
    net462 121 120 1
    net6.0 with DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 121 121 0

    The one failure is AndroidNotificationDeserialization. It is pre-existing and unrelated: it
    fails the same way on unmodified main (119 tests, 1 failure) on a machine with a culture that
    uses , as the decimal separator. The cause is that TimeConverter.StringToLongMillis parses
    "1.001000000" with the current culture.

  • FirebaseAdmin builds for netstandard2.0, net462 and net6.0 with TreatWarningsAsErrors.
    dotnet format --verify-no-changes reports no changes for the two edited files.

🤖 Generated with Claude Code

@caglarenes
caglarenes requested a review from a team November 28, 2026 22:17
@google-cla

google-cla Bot commented Nov 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the AndroidNotification class to prevent the EventTimestamp from being included in the serialized message when it is left at its default value. Specifically, a check was added to return null in EventTimeString if EventTimestamp is equal to default(DateTime). Corresponding unit tests were added to verify serialization behavior both with and without an event timestamp. There are no review comments, so I have no feedback to provide.

@caglarenes
caglarenes force-pushed the fix/android-event-time-default branch from c6de157 to ce7624e Compare November 28, 2026 22:22
…not set

AndroidNotification.EventTimestamp is a non-nullable DateTime and the private
EventTimeString helper always returned a formatted value, so a notification
that never set EventTimestamp was sent with
"event_time": "0001-01-01T00:00:00.000000000Z" (shifted by the host's UTC
offset on hosts west of UTC). The Android FCM SDK uses event_time as the
notification's "when" value, so these notifications show a wrong time and
sort as the oldest entry in the notification drawer.

EventTimeString now returns null when EventTimestamp is default(DateTime), and
the serializer omits null values, so event_time is left out of the request.
This matches how Priority, Visibility, Proxy and VibrateTimingsMillis are
omitted when unset. The public API does not change.

Testing: Added unit tests in MessageTest.cs that serialize an
AndroidNotification with and without EventTimestamp.
@caglarenes
caglarenes force-pushed the fix/android-event-time-default branch from ce7624e to 28728dd Compare November 28, 2026 22:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AndroidNotification sends event_time = 0001-01-01 when EventTimestamp is not set

1 participant