Skip to content

Fix GeneralizedTime encoding for fractional seconds below 0.0001 - #136

Open
deadcaf3 wants to merge 1 commit into
apple:mainfrom
deadcaf3:fix/generalized-time-fractional-seconds
Open

deadcaf3 wants to merge 1 commit into
apple:mainfrom
deadcaf3:fix/generalized-time-fractional-seconds

Conversation

@deadcaf3

Copy link
Copy Markdown

Motivation:

GeneralizedTime builds its fractional seconds from String(Double). Swift prints values below 0.0001 in scientific notation, so 0.00001 becomes "1e-05" and the encoder writes "-05" as the digits. The asserts that would catch this are stripped in release builds, so release emits an invalid encoding and debug aborts.

Only encoding is affected. The parser accepts digits only.

Modifications:

Expand scientific notation into plain digits in append(fractionalSeconds:). Replace the asserts with thrown errors. Add a test covering values from 0.0001 down to 1e-7 via both the initializer and the setter.

Result:

Small fractional seconds encode and round-trip correctly. The new test fails before this patch and passes after it.

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.

1 participant