-
Notifications
You must be signed in to change notification settings - Fork 648
Include timezone when serializing JSON responses #1146
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
Conversation
This adds back the timezone information to JSON responses. Note that the format is slightly different than we provided from the deprecated `time` crate. Previously, responses would end in `Z` and now the timezone is provided as `+00:00`. However, both representations are compliant with RFC3339. Fixes rust-lang#1123
28a5bcd
to
99c459b
Compare
Out of curiosity - why you opted to keep the timestamps in |
@imp I originally tried changing things to |
@jtgeibel Admittedly I don't know much about interaction with diesel, but naive (pun unintended) approach would be stick to struct Version {
updated_at: NaiveDateTime,
...
}
struct EncodableVersion {
updated_at: DateTime<Utc>,
...
}
impl Version {
pub fn encodable(self, crate_name: &str) -> EncodableVersion {
EncodableVersion {
updated_at: DateTime::<Utc>::from_utc(self.updated_at, Utc);
...
}
}
} From this point on |
@imp Yeah that is the other option that I considered and is similar to what the previous code (with the |
@jtgeibel Very well, thanks for explaining! |
This looks great! The one request I have is could we add a test for at least one of these, setting a time to a known value and checking the JSON datetime against a static string, to hopefully prevent us from inadvertently breaking this in the future? :) |
Adding tests for this might also be a good task for someone new to take on, so I'm also okay with merging this as-is and opening an issue for tests. What do you think? |
Let's merge this and make a new issue for the tests :) bors: r+ |
1146: Include timezone when serializing JSON responses r=carols10cents This adds back the timezone information to JSON responses. Note that the format is slightly different than we provided from the old `time` crate. Previously, responses would end in `Z` and now the timezone is provided as `+00:00`. However, both representations are compliant with RFC3339. Because of this regression, cargo-info has applied a patch to handle responses that may or may not include the timezone information. I've locally tested cargo-info both with and without this patch to confirm that both versions correctly handle the format with `+00:00`. The code for handling Option<NaiveDateTime> is a bit more complicated that I would like (given that we only have one instance of this), but I couldn't find a way to direct serde to handle this automatically. Fixes #1123
Build succeeded |
This adds back the timezone information to JSON responses. Note that the format is slightly different than we provided from the old
time
crate. Previously, responses would end inZ
and now the timezone is provided as+00:00
. However, both representations are compliant with RFC3339.Because of this regression, cargo-info has applied a patch to handle responses that may or may not include the timezone information. I've locally tested cargo-info both with and without this patch to confirm that both versions correctly handle the format with
+00:00
.The code for handling Option is a bit more complicated that I would like (given that we only have one instance of this), but I couldn't find a way to direct serde to handle this automatically.
Fixes #1123