Improve some more
This commit is contained in:
parent
a6461ef7d5
commit
b3cf5d9e61
|
@ -103,9 +103,19 @@ dependencies = [
|
||||||
"itoa",
|
"itoa",
|
||||||
"libc",
|
"libc",
|
||||||
"standback",
|
"standback",
|
||||||
|
"time-macros",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "time-macros"
|
||||||
|
version = "0.2.0-alpha.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06871c63832e5091df3d04d5777d742dabc86159651d161afa8e3133fa6a41b0"
|
||||||
|
dependencies = [
|
||||||
|
"standback",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
|
|
@ -20,4 +20,4 @@ time = {version = "0.3.0-alpha-0", features = ["local-offset"], optional = true}
|
||||||
serde = { version = "1", features = ["derive"], optional = true }
|
serde = { version = "1", features = ["derive"], optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
time = {version = "0.3.0-alpha-0", features = ["local-offset", "formatting"]}
|
time = {version = "0.3.0-alpha-0", features = ["local-offset", "formatting", "macros"]}
|
||||||
|
|
|
@ -93,8 +93,8 @@ pub use error::Error;
|
||||||
pub use jpeg::get_exif_attr as get_exif_attr_from_jpeg;
|
pub use jpeg::get_exif_attr as get_exif_attr_from_jpeg;
|
||||||
pub use reader::{Exif, Reader};
|
pub use reader::{Exif, Reader};
|
||||||
pub use tag::{Context, Tag};
|
pub use tag::{Context, Tag};
|
||||||
pub use tiff::{DateTime, Field, In};
|
|
||||||
pub use tiff::parse_exif_compat03 as parse_exif;
|
pub use tiff::parse_exif_compat03 as parse_exif;
|
||||||
|
pub use tiff::{DateTime, Field, In};
|
||||||
pub use value::Value;
|
pub use value::Value;
|
||||||
pub use value::{Rational, SRational};
|
pub use value::{Rational, SRational};
|
||||||
|
|
||||||
|
|
19
src/tiff.rs
19
src/tiff.rs
|
@ -487,8 +487,15 @@ impl core::convert::TryFrom<&DateTime> for time::OffsetDateTime {
|
||||||
|
|
||||||
fn try_from(value: &DateTime) -> core::result::Result<Self, Self::Error> {
|
fn try_from(value: &DateTime) -> core::result::Result<Self, Self::Error> {
|
||||||
let naive = time::PrimitiveDateTime::new(
|
let naive = time::PrimitiveDateTime::new(
|
||||||
time::Date::from_calendar_date(value.year as i32, value.month, value.day).map_err(|_| ())?,
|
time::Date::from_calendar_date(value.year as i32, value.month, value.day)
|
||||||
time::Time::from_hms_nano(value.hour, value.minute, value.second, value.nanosecond.unwrap_or(0)).map_err(|_| ())?,
|
.map_err(|_| ())?,
|
||||||
|
time::Time::from_hms_nano(
|
||||||
|
value.hour,
|
||||||
|
value.minute,
|
||||||
|
value.second,
|
||||||
|
value.nanosecond.unwrap_or(0),
|
||||||
|
)
|
||||||
|
.map_err(|_| ())?,
|
||||||
);
|
);
|
||||||
let offset = value
|
let offset = value
|
||||||
.offset
|
.offset
|
||||||
|
@ -757,13 +764,11 @@ mod tests {
|
||||||
fn date_time_chrono() {
|
fn date_time_chrono() {
|
||||||
let mut dt = DateTime::from_ascii(b"2016:05:04 03:02:01").unwrap();
|
let mut dt = DateTime::from_ascii(b"2016:05:04 03:02:01").unwrap();
|
||||||
use core::convert::TryFrom;
|
use core::convert::TryFrom;
|
||||||
let fmt = time::format_description::parse(
|
let fmt = time::macros::format_description!("[year]-[month]-[day]T[hour]:[minute]:[second][offset_hour sign:mandatory]:[offset_minute]");
|
||||||
"[year]-[month]-[day]T[hour]:[minute]:[second][offset_hour \
|
|
||||||
sign:mandatory]:[offset_minute]",
|
|
||||||
).unwrap();
|
|
||||||
let dt_str = time::OffsetDateTime::try_from(dt)
|
let dt_str = time::OffsetDateTime::try_from(dt)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.format(&fmt).unwrap();
|
.format(&fmt)
|
||||||
|
.unwrap();
|
||||||
assert_eq!(dt_str, "2016-05-04T03:02:01-04:00");
|
assert_eq!(dt_str, "2016-05-04T03:02:01-04:00");
|
||||||
assert_ne!(dt_str, "2016-05-04T03:02:01+04:00");
|
assert_ne!(dt_str, "2016-05-04T03:02:01+04:00");
|
||||||
assert_ne!(dt_str, "2016-05-04T03:02:01Z");
|
assert_ne!(dt_str, "2016-05-04T03:02:01Z");
|
||||||
|
|
Loading…
Reference in New Issue