diff options
| author | Edward Barnard | 2017-04-20 12:04:59 +0100 |
|---|---|---|
| committer | Edward Barnard | 2017-04-20 12:04:59 +0100 |
| commit | 2e7bd78be40b04ff12379b6aeb739f7172ab11c9 (patch) | |
| tree | 86d5548413c4684170fdf318cb11cf9aa7834adb /src/xml | |
| parent | ef418ab58970d396e9c8daf7a86d6a410ad11beb (diff) | |
| download | rust-plist-2e7bd78be40b04ff12379b6aeb739f7172ab11c9.tar.bz2 | |
Use a custom date type.
Diffstat (limited to 'src/xml')
| -rw-r--r-- | src/xml/reader.rs | 15 | ||||
| -rw-r--r-- | src/xml/writer.rs | 5 |
2 files changed, 5 insertions, 15 deletions
diff --git a/src/xml/reader.rs b/src/xml/reader.rs index 6af89b0..00b3bc4 100644 --- a/src/xml/reader.rs +++ b/src/xml/reader.rs @@ -1,17 +1,9 @@ -use chrono::{DateTime, UTC}; -use chrono::format::ParseError as ChronoParseError; use rustc_serialize::base64::FromBase64; use std::io::Read; use std::str::FromStr; use xml_rs::reader::{EventReader as XmlEventReader, ParserConfig, XmlEvent}; -use {Error, Result, PlistEvent}; - -impl From<ChronoParseError> for Error { - fn from(_: ChronoParseError) -> Error { - Error::InvalidData - } -} +use {Date, Error, Result, PlistEvent}; pub struct EventReader<R: Read> { xml_reader: XmlEventReader<R>, @@ -83,8 +75,7 @@ impl<R: Read> EventReader<R> { } "date" => { return Some(self.read_content(|s| { - let date = try!(DateTime::parse_from_rfc3339(&s)); - Ok(PlistEvent::DateValue(date.with_timezone(&UTC))) + Ok(PlistEvent::DateValue(Date::from_str(&s).map_err(|_| Error::InvalidData)?)) })) } "integer" => { @@ -187,7 +178,7 @@ mod tests { StringValue("Data".to_owned()), DataValue(vec![0, 0, 0, 190, 0, 0, 0, 3, 0, 0, 0, 30, 0, 0, 0]), StringValue("Birthdate".to_owned()), - DateValue(UTC.ymd(1981, 05, 16).and_hms(11, 32, 06)), + DateValue(UTC.ymd(1981, 05, 16).and_hms(11, 32, 06).into()), StringValue("Blank".to_owned()), StringValue("".to_owned()), EndDictionary]; diff --git a/src/xml/writer.rs b/src/xml/writer.rs index 9018e2d..02c57db 100644 --- a/src/xml/writer.rs +++ b/src/xml/writer.rs @@ -166,8 +166,7 @@ impl<W: Write> PlistEventWriter for EventWriter<W> { try!(self.write_element_and_value("data", &base64_data)); } PlistEvent::DateValue(ref value) => { - let date = format!("{:?}", value); - try!(self.write_element_and_value("date", &date)); + try!(self.write_element_and_value("date", &value.to_string())); } PlistEvent::IntegerValue(ref value) => { try!(self.write_element_and_value("integer", &value.to_string())) @@ -212,7 +211,7 @@ mod tests { StringValue("Data".to_owned()), DataValue(vec![0, 0, 0, 190, 0, 0, 0, 3, 0, 0, 0, 30, 0, 0, 0]), StringValue("Birthdate".to_owned()), - DateValue(UTC.ymd(1981, 05, 16).and_hms(11, 32, 06)), + DateValue(UTC.ymd(1981, 05, 16).and_hms(11, 32, 06).into()), EndDictionary]; let mut cursor = Cursor::new(Vec::new()); |
