mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
parsers: Change deprecated FixedOffset::{east,west} for *_opt
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 <pep@bouah.net>
This commit is contained in:
parent
f3e1160f6e
commit
6d98ad97cd
2 changed files with 10 additions and 6 deletions
|
@ -73,7 +73,7 @@ mod tests {
|
||||||
assert_eq!(date.0.minute(), 08);
|
assert_eq!(date.0.minute(), 08);
|
||||||
assert_eq!(date.0.second(), 25);
|
assert_eq!(date.0.second(), 25);
|
||||||
assert_eq!(date.0.nanosecond(), 0);
|
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]
|
#[test]
|
||||||
|
|
|
@ -56,8 +56,9 @@ impl TryFrom<Element> for TimeResult {
|
||||||
check_no_children!(child, "utc");
|
check_no_children!(child, "utc");
|
||||||
check_no_attributes!(child, "utc");
|
check_no_attributes!(child, "utc");
|
||||||
let date_time = DateTime::from_str(&child.text())?;
|
let date_time = DateTime::from_str(&child.text())?;
|
||||||
if date_time.timezone() != FixedOffset::east(0) {
|
match FixedOffset::east_opt(0) {
|
||||||
return Err(Error::ParseError("Non-UTC timezone for utc element."));
|
Some(tz) if date_time.timezone() == tz => (),
|
||||||
|
_ => return Err(Error::ParseError("Non-UTC timezone for utc element.")),
|
||||||
}
|
}
|
||||||
utc = Some(date_time);
|
utc = Some(date_time);
|
||||||
} else {
|
} else {
|
||||||
|
@ -78,8 +79,11 @@ impl From<TimeResult> for Element {
|
||||||
Element::builder("time", ns::TIME)
|
Element::builder("time", ns::TIME)
|
||||||
.append(Element::builder("tzo", ns::TIME).append(format!("{}", time.0.timezone())))
|
.append(Element::builder("tzo", ns::TIME).append(format!("{}", time.0.timezone())))
|
||||||
.append(
|
.append(
|
||||||
Element::builder("utc", ns::TIME)
|
Element::builder("utc", ns::TIME).append(
|
||||||
.append(time.0.with_timezone(FixedOffset::east(0)).format("%FT%TZ")),
|
time.0
|
||||||
|
.with_timezone(FixedOffset::east_opt(0).unwrap())
|
||||||
|
.format("%FT%TZ"),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -104,7 +108,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let elem1 = elem.clone();
|
let elem1 = elem.clone();
|
||||||
let time = TimeResult::try_from(elem).unwrap();
|
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!(
|
assert_eq!(
|
||||||
time.0,
|
time.0,
|
||||||
DateTime::from_str("2006-12-19T12:58:35-05:00").unwrap()
|
DateTime::from_str("2006-12-19T12:58:35-05:00").unwrap()
|
||||||
|
|
Loading…
Reference in a new issue