Skip to content

Comments

Simplify NumericDate conversions #693

Merged
timothee-haudebourg merged 1 commit intomainfrom
simpler-jwt-numeric-date
Feb 2, 2026
Merged

Simplify NumericDate conversions #693
timothee-haudebourg merged 1 commit intomainfrom
simpler-jwt-numeric-date

Conversation

@timothee-haudebourg
Copy link
Contributor

@timothee-haudebourg timothee-haudebourg commented Feb 2, 2026

Description

The NumericDate type is overly concerned about f64 precision, trying to prevent microseconds rounding errors for dates starting from year ~2200. Because of this it only provide TryFrom conversions most of the time, instead of simpler From conversions. But it's not being consistent either, with Add and Sub implementations using unwrap even though it might trigger rounding errors.

This PR simplifies all of this by not caring about rounding errors by default anymore, and providing simple From implementations. If we do care about microseconds rounding errors at some point in the future, we can deal with it by adding safe methods and improving the internal representation of NumericDate (using f128 for instance, or a lexical representation, etc.).

@timothee-haudebourg timothee-haudebourg merged commit eb1c026 into main Feb 2, 2026
2 checks passed
@timothee-haudebourg timothee-haudebourg deleted the simpler-jwt-numeric-date branch February 2, 2026 13:43
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.

2 participants