Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage Examples #28

Open
mlevkov opened this issue Apr 22, 2020 · 2 comments
Open

Usage Examples #28

mlevkov opened this issue Apr 22, 2020 · 2 comments

Comments

@mlevkov
Copy link

mlevkov commented Apr 22, 2020

I've been trying to figure out how to use your library for parsing iso:8601 duration and attach it to the standard Time or Chrono library. Do you have an example of such or other similar usages? All I get is the Duration enum with values, but cannot do anything else with it. Sorry, if this sounds too silly.

@badboy
Copy link
Owner

badboy commented May 10, 2020

I'm not sure what you need.
Parsing a string to get the Duration enum is pretty much all this crate does:

iso8601/tests/lib.rs

Lines 960 to 1002 in a44ab6e

#[test]
fn test_duration_ymdhms() {
// full YMDHMS
assert_eq!(
Ok(Duration::YMDHMS {
year: 1,
month: 2,
day: 3,
hour: 4,
minute: 5,
second: 6,
millisecond: 0,
}),
duration("P1Y2M3DT4H5M6S")
);
// full YMDHMS with milliseconds dot delimiter
assert_eq!(
Ok(Duration::YMDHMS {
year: 1,
month: 2,
day: 3,
hour: 4,
minute: 5,
second: 6,
millisecond: 700,
}),
duration("P1Y2M3DT4H5M6.7S")
);
// full YMDHMS with milliseconds comma delimiter
assert_eq!(
Ok(Duration::YMDHMS {
year: 1,
month: 2,
day: 3,
hour: 4,
minute: 5,
second: 6,
millisecond: 700,
}),
duration("P1Y2M3DT4H5M6,7S")
);

What else do you expect?

@imp
Copy link
Contributor

imp commented Sep 5, 2020

I believe the OP wanted compatibility with std::time::Duration and/or chrono::Duration.
I would like to add my +1 for this issue.

@imp imp mentioned this issue Sep 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants