Rewrite Interval.parse(CharSequence)
#242
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an attempt to make
Interval
parsing more readable and (hopefully) less error prone. I believe that proposed way of splitting code into methods makes much more sense than before. At least one bug was fixed.At the same time, parsing became a little more flexible.The bug was caused by the following:
It looks like author's intention was to move instant 1000 days towards
Instant.EPOCH
. First, it is not exactly 1000 days - it's approximately 1000 days. What's important is that it can (but doesn't have to) move instant into month with different number of days. I decided to use leap year cycle length (which is fixed) to avoid this kind of problems.Without this fix, not a single test covered by
org.threeten.extra.TestInterval.data_parse_outside_bounds(String, String, String)
is going to pass. For instance-1000000000-01-31T00:00:00Z/P1M
should be parsed to interval ending at-02-29
, not-03-02
and for-1000000000-01-31T00:00:00Z/P2M
interval's end should be-03-31
instead of-04-01
.There are still some cases that this rewrite doesn't fix. All of them involve duration. Please, see
org.threeten.extra.TestInterval.data_parse_crossing_bounds(String, String, String)
(intervals starting within date-time bounds, with duration making them end outside of it) andorg.threeten.extra.TestInterval.data_parse_crossing_bounds_twice(String, String, String)
(intervals starting beforeOffsetDateTime.MIN
and ending afterOffsetDateTime.MAX
because of duration). Maybe someone will be interested in making these tests pass - for now, they are disabled.As I mentioned, parsing became a little more flexible. It is now possible to parse `OffsetDateTime/LocalDateTime` and `LocalDateTime/OffsetDateTime` (previously only `OffsetDateTime/LocalDateTime` was supported). It seems to be valid according to spec, at least if Wiki can be trusted.Edit: I must have misread something. If desired, I can easily revert old behavior.
Probably related: #80.