Merge pull request #251 from ehuss/datetime-space
0.5: Support space separator in datetime.
This commit is contained in:
commit
625d2a18bb
|
@ -176,7 +176,8 @@ impl FromStr for Datetime {
|
|||
|
||||
// Next parse the "partial-time" if available
|
||||
let partial_time = if full_date.is_some() &&
|
||||
chars.clone().next() == Some('T') {
|
||||
(chars.clone().next() == Some('T')
|
||||
|| chars.clone().next() == Some(' ')) {
|
||||
chars.next();
|
||||
true
|
||||
} else {
|
||||
|
|
11
src/de.rs
11
src/de.rs
|
@ -1019,6 +1019,17 @@ impl<'a> Deserializer<'a> {
|
|||
-> Result<(Span, &'a str), Error> {
|
||||
let start = self.tokens.substr_offset(date);
|
||||
|
||||
// Check for space separated date and time.
|
||||
if let Some((_, Token::Whitespace(s))) = self.peek()? {
|
||||
if s == " " {
|
||||
self.next()?;
|
||||
// Skip past the hour.
|
||||
if let Some((_, Token::Keylike(_))) = self.peek()? {
|
||||
self.next()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if colon_eaten || self.eat(Token::Colon)? {
|
||||
// minutes
|
||||
match self.next()? {
|
||||
|
|
|
@ -6,10 +6,14 @@ use toml::Value;
|
|||
|
||||
#[test]
|
||||
fn times() {
|
||||
fn good(s: &str) {
|
||||
fn dogood(s: &str, serialized: &str) {
|
||||
let to_parse = format!("foo = {}", s);
|
||||
let value = Value::from_str(&to_parse).unwrap();
|
||||
assert_eq!(value["foo"].as_datetime().unwrap().to_string(), s);
|
||||
assert_eq!(value["foo"].as_datetime().unwrap().to_string(), serialized);
|
||||
}
|
||||
fn good(s: &str) {
|
||||
dogood(s, s);
|
||||
dogood(&s.replace("T", " "), s);
|
||||
}
|
||||
|
||||
good("1997-09-09T09:09:09Z");
|
||||
|
|
Loading…
Reference in a new issue