-
Notifications
You must be signed in to change notification settings - Fork 102
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
Chrono support #188
Chrono support #188
Conversation
https://docs.rs/chrono/latest/chrono/serde/ts_microseconds/index.html should give microsecond precision, fixing CI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
@dean-shaff, can you please sign the CLA? We won't be able to merge without it. |
When is this getting released? |
Hey, if you add a mod with pub mod dt_from_str {
use super::*;
// type DateTimeUtc = DateTime<Utc>;
// option!(
// DateTimeUtc,
// "Ser/de `Option<DateTime<Utc>>` to/from `Nullable(DateTime)`."
// );
pub fn serialize<S>(dt: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let ts: i64 = dt.timestamp();
u32::try_from(ts)
.map_err(|_| S::Error::custom(format!("{dt} cannot be represented as DateTime")))?
.serialize(serializer)
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
where
D: Deserializer<'de>,
{
let ts: String = Deserialize::deserialize(deserializer)?;
DateTime::<Utc>::from_str(&ts).map_err(|_| {
D::Error::custom(format!("{ts} cannot be converted to DateTime<Utc>"))
})
}
#[derive(Serialize, Deserialize, Debug, Row)]
pub struct MyRow {
pub id: String,
#[serde(with = "dt_from_str")]
pub requested_at: DateTime<Utc>, |
@StashOfCode I think my intention with this PR was the replicate the existing |
…into chrono-support
If everything is OK with this PR, let's merge and release it with the current pending changes as 0.14.0? |
LGTM, let's merge |
@dean-shaff, I found a crate called serde_with that seems to have already implemented what I did for myself. The documentation is pretty bad there though :/ |
Summary
Add support for chrono.
Checklist
Delete items not relevant to your PR: