(
String period,
int from,
int to,
boolean date,
List<Item<U>> items
)
| 3627 | } |
| 3628 | |
| 3629 | private static <U extends ChronoUnit> void parseAlt( |
| 3630 | String period, |
| 3631 | int from, |
| 3632 | int to, |
| 3633 | boolean date, |
| 3634 | List<Item<U>> items |
| 3635 | ) throws ParseException { |
| 3636 | |
| 3637 | boolean extended = false; |
| 3638 | |
| 3639 | if (date) { |
| 3640 | if (from + 4 < to) { |
| 3641 | extended = (period.charAt(from + 4) == '-'); |
| 3642 | } |
| 3643 | boolean ordinalStyle = ( |
| 3644 | extended |
| 3645 | ? (from + 8 == to) |
| 3646 | : (from + 7 == to)); |
| 3647 | Duration<?> dur = getAlternativeDateFormat(extended, ordinalStyle).parse(period, from); |
| 3648 | long years = dur.getPartialAmount(YEARS); |
| 3649 | long months; |
| 3650 | long days; |
| 3651 | if (ordinalStyle) { |
| 3652 | months = 0; |
| 3653 | days = dur.getPartialAmount(DAYS); |
| 3654 | // ISO does not specify any constraint here |
| 3655 | } else { |
| 3656 | months = dur.getPartialAmount(MONTHS); |
| 3657 | days = dur.getPartialAmount(DAYS); |
| 3658 | if (months > 12) { |
| 3659 | throw new ParseException( |
| 3660 | "ISO-8601 prohibits months-part > 12: " + period, |
| 3661 | from + 4 + (extended ? 1 : 0)); |
| 3662 | } |
| 3663 | if (days > 30) { |
| 3664 | throw new ParseException( |
| 3665 | "ISO-8601 prohibits days-part > 30: " + period, |
| 3666 | from + 6 + (extended ? 2 : 0)); |
| 3667 | } |
| 3668 | } |
| 3669 | if (years > 0) { |
| 3670 | U unit = cast(YEARS); |
| 3671 | items.add(Item.of(years, unit)); |
| 3672 | } |
| 3673 | if (months > 0) { |
| 3674 | U unit = cast(MONTHS); |
| 3675 | items.add(Item.of(months, unit)); |
| 3676 | } |
| 3677 | if (days > 0) { |
| 3678 | U unit = cast(DAYS); |
| 3679 | items.add(Item.of(days, unit)); |
| 3680 | } |
| 3681 | } else { |
| 3682 | if (from + 2 < to) { |
| 3683 | extended = (period.charAt(from + 2) == ':'); |
| 3684 | } |
| 3685 | Duration<?> dur = getAlternativeTimeFormat(extended).parse(period, from); |
| 3686 | long hours = dur.getPartialAmount(HOURS); |
no test coverage detected