aboutsummaryrefslogtreecommitdiffstats
path: root/src/xml/reader.rs
diff options
context:
space:
mode:
authorEdward Barnard2015-08-28 23:08:03 +0700
committerEdward Barnard2015-08-28 23:08:03 +0700
commit361aa56bf877cd4210018c97ebaf6aa92ab4f608 (patch)
tree82c6a47a8e9e597f221cc096c4f86d93fdae436e /src/xml/reader.rs
parent3e41485288049b1d7a9be60b84b4d78dcd400f39 (diff)
downloadrust-plist-361aa56bf877cd4210018c97ebaf6aa92ab4f608.tar.bz2
Add date support via chrono
Diffstat (limited to 'src/xml/reader.rs')
-rw-r--r--src/xml/reader.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/xml/reader.rs b/src/xml/reader.rs
index f047db4..006a04e 100644
--- a/src/xml/reader.rs
+++ b/src/xml/reader.rs
@@ -1,3 +1,4 @@
+use chrono::{DateTime, UTC};
use rustc_serialize::base64::FromBase64;
use std::io::Read;
use std::str::FromStr;
@@ -58,7 +59,10 @@ impl<R: Read> Iterator for StreamingParser<R> {
Err(_) => Err(ParserError::InvalidData)
}
})),
- "date" => return Some(self.read_content(|s| Ok(PlistEvent::DateValue(s)))),
+ "date" => return Some(self.read_content(|s| {
+ let date = try!(DateTime::parse_from_rfc3339(&s));
+ Ok(PlistEvent::DateValue(date.with_timezone(&UTC)))
+ })),
"integer" => return Some(self.read_content(|s| {
match FromStr::from_str(&s) {
Ok(i) => Ok(PlistEvent::IntegerValue(i)),
@@ -104,6 +108,7 @@ impl<R: Read> Iterator for StreamingParser<R> {
#[cfg(test)]
mod tests {
+ use chrono::{TimeZone, UTC};
use std::fs::File;
use std::path::Path;
@@ -128,12 +133,14 @@ mod tests {
StringValue("It is a tale told by an idiot,".to_owned()),
StringValue("Full of sound and fury, signifying nothing.".to_owned()),
EndArray,
- StringValue("Birthdate".to_owned()),
+ StringValue("Death".to_owned()),
IntegerValue(1564),
StringValue("Height".to_owned()),
RealValue(1.60),
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)),
EndDictionary,
EndPlist
];