MCPcopy Create free account
hub / github.com/MenoData/Time4J / between

Method between

base/src/main/java/net/time4j/CalendarUnit.java:680–744  ·  view source on GitHub ↗
(T start, T end)

Source from the content-addressed store, hash-verified

678 }
679
680 @Override
681 public long between(T start, T end) {
682
683 PlainDate d1 = start.get(PlainDate.CALENDAR_DATE);
684 PlainDate d2 = end.get(PlainDate.CALENDAR_DATE);
685 long amount;
686
687 switch (this.unit) {
688 case MILLENNIA:
689 amount = this.monthDelta(d1, d2) / 12000;
690 break;
691 case CENTURIES:
692 amount = this.monthDelta(d1, d2) / 1200;
693 break;
694 case DECADES:
695 amount = this.monthDelta(d1, d2) / 120;
696 break;
697 case YEARS:
698 amount = this.monthDelta(d1, d2) / 12;
699 break;
700 case QUARTERS:
701 amount = this.monthDelta(d1, d2) / 3;
702 break;
703 case MONTHS:
704 amount = this.monthDelta(d1, d2);
705 break;
706 case WEEKS:
707 amount = dayDelta(d1, d2) / 7;
708 break;
709 case DAYS:
710 amount = dayDelta(d1, d2);
711 break;
712 default:
713 throw new UnsupportedOperationException(this.unit.name());
714 }
715
716 if (
717 (amount != 0)
718 && start.contains(PlainTime.WALL_TIME)
719 && end.contains(PlainTime.WALL_TIME)
720 ) {
721 boolean needsTimeCorrection;
722
723 if (this.unit == DAYS) {
724 needsTimeCorrection = true;
725 } else {
726 PlainDate d = d1.plus(amount, this.unit);
727 needsTimeCorrection = (d.compareByTime(d2) == 0);
728 }
729
730 if (needsTimeCorrection) {
731 PlainTime t1 = start.get(PlainTime.WALL_TIME);
732 PlainTime t2 = end.get(PlainTime.WALL_TIME);
733
734 if ((amount > 0) && t1.isAfter(t2)) {
735 amount--;
736 } else if ((amount < 0) && t1.isBefore(t2)) {
737 amount++;

Callers

nothing calls this directly

Calls 9

monthDeltaMethod · 0.95
dayDeltaMethod · 0.95
plusMethod · 0.95
compareByTimeMethod · 0.95
isAfterMethod · 0.95
isBeforeMethod · 0.95
getMethod · 0.65
nameMethod · 0.65
containsMethod · 0.65

Tested by

no test coverage detected