Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom Duration and Timestamp types for conversion with serde #89

Merged
merged 15 commits into from
Nov 19, 2024

Conversation

fore5fire
Copy link
Contributor

Currently chrono::Duration doesn't implement Seralize and chrono::DateTime serializes to an ISO 8601 string. This change is inspired by the toml crate's approach to preserving date formats across functions available in the Serialize trait to ensure that durations and timestamp are converted into the appropriate CEL types.

Using the newly exposed Duration and Timestamp types is only necessary for types using serde to convert to CEL, but maybe it could be confusing to keep track of where to use the chrono types vs the cel_interpreter types? But it seems like an unnecessary breaking change to use the new types in Value::Duration and Value::Timestamp 🤷🏼

example/src/serde.rs Outdated Show resolved Hide resolved
@fore5fire
Copy link
Contributor Author

I did some research and found the clever idea to use serde's newtype_struct name field as the indicator to do special type handling. Since serde's official recommendation is to silently unwrap newtypes, it's a great way to signal to a custom Serializer but remain compatible with most other implementations

@fore5fire
Copy link
Contributor Author

Updated for the new chrono feature

interpreter/src/ser.rs Outdated Show resolved Hide resolved
@clarkmcc clarkmcc merged commit 4effd74 into clarkmcc:master Nov 19, 2024
1 check passed
@github-actions github-actions bot mentioned this pull request Nov 19, 2024
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