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

Support for the date part of an ISO 8601 time interval #70

Closed
akkie opened this issue Nov 24, 2016 · 2 comments
Closed

Support for the date part of an ISO 8601 time interval #70

akkie opened this issue Nov 24, 2016 · 2 comments

Comments

@akkie
Copy link

akkie commented Nov 24, 2016

I'm not really sure if this is a bug or if this is the expected behavior. I try to parse the ISO 8601 time interval "2007-03-01T13:00:00Z/P1Y2M10DT2H30M" as noted in the Wikepedia page. This is not possible with the current Interval implementation, because it doesn't support the date part of the interval. If I remove the date part, then it works as expected.

Interval.parse("2007-03-01T13:00:00Z/P1Y2M10DT2H30M") // Fails
Interval.parse("2007-03-01T13:00:00Z/PT2H30M") // Works

It seems that the issue comes from the fact that the java.time.Duration class cannot parse this format. It seems that the current Java implementations uses two classes to represent the ISO 8601 duration format. The java.time.Period class can parse the date part and the java.time.Duration class can parse the time part.

I'm not really sure if this is wrong documented on the Wikipedia page, or if this is an issue in the library. Anyway, the org.joda.time.Interval does parse the string with the date part "2007-03-01T13:00:00Z/P1Y2M10DT2H30M".

@MenoData
Copy link

Not a bug, just an API-limitation (expected behaviour as documented).

public static Interval parse(CharSequence text)

Obtains an instance of Interval from a text string such as 2007-12-03T10:15:30Z/2007-12-04T10:15:30Z.
The string must consist of one of the following three formats:

•a representations of an Instant, followed by a forward slash, followed by a representation of a Instant
•a representation of an Instant, followed by a forward slash, followed by a representation of a Duration
•a representation of a Duration, followed by a forward slash, followed by a representation of an Instant

Personally I think that such a question is probably better located at Stackoverflow to get more detailed answers and to reach a broader audience. I am also not sure how far this project will go to implement all the many ISO-8601-features (not always easy to implement!), see examples in my interval implementation or this old Joda-issue.

@jodastephen
Copy link
Member

jodastephen commented Nov 27, 2016

Parsing additional formats would be a reasonable enhancement to ThreeTen-Extra.

jodastephen added a commit that referenced this issue Apr 2, 2017
Allow years, months, weeks and days via `PeriodDuration`
See #70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants