(
ChronoEntity<?> entity,
Locale locale,
AttributeQuery attributes
)
| 617 | } |
| 618 | |
| 619 | @Override |
| 620 | public ChronoEntity<?> resolve( |
| 621 | ChronoEntity<?> entity, |
| 622 | Locale locale, |
| 623 | AttributeQuery attributes |
| 624 | ) { |
| 625 | if ( |
| 626 | entity.contains(PlainTime.COMPONENT) |
| 627 | || entity.contains(PlainTime.HOUR_FROM_0_TO_24) |
| 628 | || entity.contains(PlainTime.DIGITAL_HOUR_OF_DAY) |
| 629 | || entity.contains(PlainTime.CLOCK_HOUR_OF_DAY) |
| 630 | ) { |
| 631 | return entity; // optimization |
| 632 | } |
| 633 | |
| 634 | DayPeriod dp = from(locale, attributes); |
| 635 | Element approximate = new Element(false, dp); |
| 636 | |
| 637 | if (entity.contains(approximate)) { |
| 638 | String codes = entity.get(approximate); |
| 639 | int index = 0; |
| 640 | int count = 0; |
| 641 | Meridiem meridiem = null; |
| 642 | |
| 643 | do { |
| 644 | int nextIndex = codes.indexOf('|', index); |
| 645 | String code; |
| 646 | if (nextIndex == -1) { |
| 647 | code = codes.substring(index); |
| 648 | } else { |
| 649 | code = codes.substring(index, nextIndex); |
| 650 | } |
| 651 | index = nextIndex + 1; |
| 652 | count++; |
| 653 | |
| 654 | if (dp.isPredefined() && (meridiem == null)) { |
| 655 | if (code.equals("midnight")) { |
| 656 | meridiem = Meridiem.AM; |
| 657 | continue; |
| 658 | } else if (code.equals("noon")) { |
| 659 | meridiem = Meridiem.PM; |
| 660 | continue; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | for (PlainTime time : dp.codeMap.keySet()) { |
| 665 | if (dp.codeMap.get(time).equals(code)) { |
| 666 | Meridiem m = null; |
| 667 | int hour12 = getHour12(entity); |
| 668 | PlainTime end = dp.getEnd(time); |
| 669 | |
| 670 | // Optimistic assumption that hour12 is always within time range described by code. |
| 671 | // However, the strict parser will detect any inconsistencies with day periods later. |
| 672 | if (time.getHour() >= 12) { |
| 673 | if (end.isAfter(time) || end.isSimultaneous(PlainTime.midnightAtStartOfDay())) { |
| 674 | m = Meridiem.PM; |
| 675 | } else if (hour12 != -1) { |
| 676 | m = ((hour12 + 12 >= time.getHour()) ? Meridiem.PM : Meridiem.AM); |
nothing calls this directly
no test coverage detected