From 6d98ad97cdf5a6e6a71adcb4101ddea3ceb8c0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Tue, 22 Nov 2022 18:59:09 +0100 Subject: [PATCH] parsers: Change deprecated FixedOffset::{east,west} for *_opt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For the second call, the doc says that None is returned when secs is out-of-bound. It looks like it should be alright to unwrap here Signed-off-by: Maxime “pep” Buquet --- parsers/src/date.rs | 2 +- parsers/src/time.rs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/parsers/src/date.rs b/parsers/src/date.rs index 07d73bc..8540c4b 100644 --- a/parsers/src/date.rs +++ b/parsers/src/date.rs @@ -73,7 +73,7 @@ mod tests { assert_eq!(date.0.minute(), 08); assert_eq!(date.0.second(), 25); assert_eq!(date.0.nanosecond(), 0); - assert_eq!(date.0.timezone(), FixedOffset::east(0)); + assert_eq!(date.0.timezone(), FixedOffset::east_opt(0).unwrap()); } #[test] diff --git a/parsers/src/time.rs b/parsers/src/time.rs index 3b468b4..1ccb729 100644 --- a/parsers/src/time.rs +++ b/parsers/src/time.rs @@ -56,8 +56,9 @@ impl TryFrom for TimeResult { check_no_children!(child, "utc"); check_no_attributes!(child, "utc"); let date_time = DateTime::from_str(&child.text())?; - if date_time.timezone() != FixedOffset::east(0) { - return Err(Error::ParseError("Non-UTC timezone for utc element.")); + match FixedOffset::east_opt(0) { + Some(tz) if date_time.timezone() == tz => (), + _ => return Err(Error::ParseError("Non-UTC timezone for utc element.")), } utc = Some(date_time); } else { @@ -78,8 +79,11 @@ impl From for Element { Element::builder("time", ns::TIME) .append(Element::builder("tzo", ns::TIME).append(format!("{}", time.0.timezone()))) .append( - Element::builder("utc", ns::TIME) - .append(time.0.with_timezone(FixedOffset::east(0)).format("%FT%TZ")), + Element::builder("utc", ns::TIME).append( + time.0 + .with_timezone(FixedOffset::east_opt(0).unwrap()) + .format("%FT%TZ"), + ), ) .build() } @@ -104,7 +108,7 @@ mod tests { .unwrap(); let elem1 = elem.clone(); let time = TimeResult::try_from(elem).unwrap(); - assert_eq!(time.0.timezone(), FixedOffset::west(6 * 3600)); + assert_eq!(time.0.timezone(), FixedOffset::west_opt(6 * 3600).unwrap()); assert_eq!( time.0, DateTime::from_str("2006-12-19T12:58:35-05:00").unwrap()