firebase / firebase-admin-dotnet

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

Incorrect serialization of the event_time field on Italian systems #408

Open andreatrentini74 opened 1 month ago

andreatrentini74 commented 1 month 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 1 month ago

I found a few problems with this issue: