firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
370 stars 131 forks source link

Incorrect serialization of the event_time field on Italian systems #408

Closed andreatrentini74 closed 2 months ago

andreatrentini74 commented 5 months ago

Description:

There is an issue with the serialization of the event_time field on systems set to Italian locale. The ':' characters are being converted to '.', which causes the server to return the following error:

Invalid value at 'message.android.notification.event_time' (type.googleapis.com/google.protobuf.Timestamp), Field 'event_time', Invalid time format: Failed to parse input

Steps to reproduce:

  1. Set your client system locale to Italian
  2. Send a notification
  3. Observe the server response

Relevant Code (how to solve):

In file FirebaseAdmin/FirebaseAdmin/Messaging/AndroidNotification.cs Substitute

        /// <summary>
        /// Gets or sets the string representation of the <see cref="EventTimestamp"/> property.
        /// </summary>
        [JsonProperty("event_time")]
        private string EventTimeString
        {
            get
            {
                return this.EventTimestamp.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.ffffff000'Z'");
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    throw new ArgumentException("Invalid event timestamp. Event timestamp should be a non-empty string");
                }

                this.EventTimestamp = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.None);
            }
        }

with

        /// <summary>
        /// Gets or sets the string representation of the <see cref="EventTimestamp"/> property.
        /// </summary>
        [JsonProperty("event_time")]
        private string EventTimeString
        {
            get
            {
                return this.EventTimestamp.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.ffffff000'Z'", CultureInfo.InvariantCulture);
            }
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    throw new ArgumentException("Invalid event timestamp. Event timestamp should be a non-empty string");
                }

                this.EventTimestamp = DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.None);
            }
        }
google-oss-bot commented 5 months ago

I found a few problems with this issue:

lahirumaramba commented 2 months ago

Thanks for reporting this! Should be fixed in https://github.com/firebase/firebase-admin-dotnet/pull/417