| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
encode_ttl and encode_milliseconds computed the nanoseconds from the float returned by timedelta.total_seconds(), so some durations were sent with rounding errors: an AndroidConfig.ttl of 86400.9 seconds (or timedelta(days=1, microseconds=900000)) was encoded as "86400.899999999s", and 1.123457 as "1.123456999s". The Duration string is now built from the exact days/seconds/microseconds of the timedelta.
There was a problem hiding this comment.
This pull request refactors duration encoding in firebase_admin/_messaging_encoder.py by introducing an encode_duration helper method. This method uses exact integer fields of datetime.timedelta to avoid floating-point precision issues associated with total_seconds(). Corresponding test cases have been added to tests/test_messaging.py. The feedback suggests using Python's f-string integer formatting {nanos:09d} instead of str(nanos).zfill(9) for cleaner and more idiomatic code.
Sorry, something went wrong.
| if nanos: | ||
| return f'{seconds}.{str(nanos).zfill(9)}s' |
There was a problem hiding this comment.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
encode_ttl and encode_milliseconds computed the nanoseconds from the float returned by timedelta.total_seconds(), so some durations were sent with rounding errors: an AndroidConfig.ttl of 86400.9 seconds (or timedelta(days=1, microseconds=900000)) was encoded as "86400.899999999s", and 1.123457 as "1.123456999s". The Duration string is now built from the exact days/seconds/microseconds of the timedelta.
Hey there! So you want to contribute to a Firebase SDK?
Before you file this pull request, please read these guidelines:
Discussion
If not, go file an issue about this before creating a pull request to discuss.
Testing
API Changes
us make Firebase APIs better, please propose your change in an issue so that we
can discuss it together.