Implement std::fmt::Display trait for DateTime.
This commit is contained in:
parent
065276d5a1
commit
8f2ece2b01
18
src/tiff.rs
18
src/tiff.rs
|
@ -24,6 +24,8 @@
|
||||||
// SUCH DAMAGE.
|
// SUCH DAMAGE.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
use endian::{Endian, BigEndian, LittleEndian};
|
use endian::{Endian, BigEndian, LittleEndian};
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use tag;
|
use tag;
|
||||||
|
@ -157,6 +159,14 @@ pub fn is_tiff(buf: &[u8]) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A struct used to parse a DateTime field.
|
/// A struct used to parse a DateTime field.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
/// ```
|
||||||
|
/// use exif::DateTime;
|
||||||
|
/// let dt = DateTime::from_ascii(b"2016:05:04 03:02:01").unwrap();
|
||||||
|
/// assert_eq!(dt.year, 2016);
|
||||||
|
/// assert_eq!(format!("{}", dt), "2016-05-04 03:02:01");
|
||||||
|
/// ```
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DateTime {
|
pub struct DateTime {
|
||||||
pub year: u16,
|
pub year: u16,
|
||||||
|
@ -190,6 +200,14 @@ impl DateTime {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for DateTime {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "{:04}-{:02}-{:02} {:02}:{:02}:{:02}",
|
||||||
|
self.year, self.month, self.day,
|
||||||
|
self.hour, self.minute, self.second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in New Issue