-
Notifications
You must be signed in to change notification settings - Fork 149
RUST-977 Support RFC 3339 to bson::DateTime
conversion without chrono feature flag
#317
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
Changes from 3 commits
5d6a530
c8338c6
7bcb901
9496a4f
e082ed0
6b4ad85
eccb081
85d5d63
0bd1b00
83b9a7a
348262e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,12 @@ pub enum Error { | |
/// while decoding a UTF-8 String from the input data. | ||
InvalidUtf8String(string::FromUtf8Error), | ||
|
||
/// An error encountered during the conversion of one datetime format to another. | ||
InvalidTimestamp { | ||
|
||
/// A message describing the error. | ||
message: String, | ||
}, | ||
|
||
/// While decoding a `Document` from bytes, an unexpected or unsupported element type was | ||
/// encountered. | ||
#[non_exhaustive] | ||
|
@@ -55,6 +61,7 @@ impl fmt::Display for Error { | |
match *self { | ||
Error::Io(ref inner) => inner.fmt(fmt), | ||
Error::InvalidUtf8String(ref inner) => inner.fmt(fmt), | ||
Error::InvalidTimestamp { ref message } => message.fmt(fmt), | ||
Error::UnrecognizedDocumentElementType { | ||
ref key, | ||
element_type, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use std::str::FromStr; | ||
|
||
#[test] | ||
fn rfc3339_to_datetime() { | ||
isabelatkinson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let rfc = "2020-06-09T10:58:07.095Z"; | ||
let date = chrono::DateTime::<chrono::Utc>::from_str(rfc).unwrap(); | ||
assert_eq!( | ||
crate::DateTime::from_rfc3339(rfc).unwrap(), | ||
crate::DateTime::from_chrono(date) | ||
); | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be good to also have a test to validate failure behavior - doesn't need to assert on the exact error message, just that one is returned for invalid input. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added invalid test cases in 7bcb901. |
||
|
||
#[test] | ||
fn invalid_rfc3339_to_datetime() { | ||
let a = "2020-06-09T10:58:07-095Z"; | ||
let b = "2020-06-09T10:58:07.095"; | ||
let c = "2020-06-09T10:62:07.095Z"; | ||
assert!(crate::DateTime::from_rfc3339(a).is_err()); | ||
assert!(crate::DateTime::from_rfc3339(b).is_err()); | ||
assert!(crate::DateTime::from_rfc3339(c).is_err()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod binary_subtype; | ||
mod datetime; | ||
mod modules; | ||
mod serde; | ||
mod spec; | ||
|
Uh oh!
There was an error while loading. Please reload this page.