Improve some more

This commit is contained in:
Michael Pfaff 2021-05-29 02:08:22 -04:00
parent a6461ef7d5
commit b3cf5d9e61
Signed by: michael
GPG Key ID: E53B118B12B5C7F9
4 changed files with 24 additions and 9 deletions

10
Cargo.lock generated
View File

@ -103,9 +103,19 @@ dependencies = [
"itoa",
"libc",
"standback",
"time-macros",
"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]]
name = "unicode-xid"
version = "0.2.2"

View File

@ -20,4 +20,4 @@ time = {version = "0.3.0-alpha-0", features = ["local-offset"], optional = true}
serde = { version = "1", features = ["derive"], optional = true }
[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"]}

View File

@ -93,8 +93,8 @@ pub use error::Error;
pub use jpeg::get_exif_attr as get_exif_attr_from_jpeg;
pub use reader::{Exif, Reader};
pub use tag::{Context, Tag};
pub use tiff::{DateTime, Field, In};
pub use tiff::parse_exif_compat03 as parse_exif;
pub use tiff::{DateTime, Field, In};
pub use value::Value;
pub use value::{Rational, SRational};

View File

@ -487,8 +487,15 @@ impl core::convert::TryFrom<&DateTime> for time::OffsetDateTime {
fn try_from(value: &DateTime) -> core::result::Result<Self, Self::Error> {
let naive = time::PrimitiveDateTime::new(
time::Date::from_calendar_date(value.year as i32, value.month, value.day).map_err(|_| ())?,
time::Time::from_hms_nano(value.hour, value.minute, value.second, value.nanosecond.unwrap_or(0)).map_err(|_| ())?,
time::Date::from_calendar_date(value.year as i32, value.month, value.day)
.map_err(|_| ())?,
time::Time::from_hms_nano(
value.hour,
value.minute,
value.second,
value.nanosecond.unwrap_or(0),
)
.map_err(|_| ())?,
);
let offset = value
.offset
@ -757,13 +764,11 @@ mod tests {
fn date_time_chrono() {
let mut dt = DateTime::from_ascii(b"2016:05:04 03:02:01").unwrap();
use core::convert::TryFrom;
let fmt = time::format_description::parse(
"[year]-[month]-[day]T[hour]:[minute]:[second][offset_hour \
sign:mandatory]:[offset_minute]",
).unwrap();
let fmt = time::macros::format_description!("[year]-[month]-[day]T[hour]:[minute]:[second][offset_hour sign:mandatory]:[offset_minute]");
let dt_str = time::OffsetDateTime::try_from(dt)
.unwrap()
.format(&fmt).unwrap();
.format(&fmt)
.unwrap();
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:01Z");