(
Moment ref,
Moment moment,
Timezone tz,
TimeUnit precision,
CalendarUnit maxRelativeUnit,
TemporalFormatter<Moment> formatter
)
| 1610 | } |
| 1611 | |
| 1612 | private String printRelativeTime( |
| 1613 | Moment ref, |
| 1614 | Moment moment, |
| 1615 | Timezone tz, |
| 1616 | TimeUnit precision, |
| 1617 | CalendarUnit maxRelativeUnit, |
| 1618 | TemporalFormatter<Moment> formatter |
| 1619 | ) { |
| 1620 | PlainTimestamp start = |
| 1621 | PlainTimestamp.from( |
| 1622 | ref, |
| 1623 | tz.getOffset(ref)); |
| 1624 | PlainTimestamp end = |
| 1625 | PlainTimestamp.from( |
| 1626 | moment, |
| 1627 | tz.getOffset(moment)); |
| 1628 | |
| 1629 | IsoUnit[] units = (this.weekToDays ? TSP_UNITS : STD_UNITS); |
| 1630 | Duration<IsoUnit> duration = Duration.in(tz, units).between(start, end); |
| 1631 | |
| 1632 | if (duration.isEmpty()) { |
| 1633 | return this.getEmptyRelativeString(precision); |
| 1634 | } |
| 1635 | |
| 1636 | TimeSpan.Item<IsoUnit> item = duration.getTotalLength().get(0); |
| 1637 | long amount = item.getAmount(); |
| 1638 | IsoUnit unit = item.getUnit(); |
| 1639 | |
| 1640 | if (unit instanceof ClockUnit) { |
| 1641 | if (5 - ((ClockUnit) unit).ordinal() < precision.ordinal()) { |
| 1642 | return this.getEmptyRelativeString(precision); |
| 1643 | } |
| 1644 | } else if ( |
| 1645 | (maxRelativeUnit != null) |
| 1646 | && (Double.compare(unit.getLength(), maxRelativeUnit.getLength()) > 0) |
| 1647 | ) { |
| 1648 | return formatter.format(moment); |
| 1649 | } else if (unit.equals(CalendarUnit.DAYS)) { |
| 1650 | String replacement = this.getRelativeReplacement(end.toDate(), duration.isNegative(), amount); |
| 1651 | |
| 1652 | if (!replacement.isEmpty()) { |
| 1653 | return replacement; |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | String pattern; |
| 1658 | |
| 1659 | if (duration.isNegative()) { |
| 1660 | if (unit.isCalendrical()) { |
| 1661 | assert (unit instanceof CalendarUnit); |
| 1662 | pattern = this.getPastPattern(amount, (CalendarUnit) unit); |
| 1663 | } else { |
| 1664 | assert (unit instanceof ClockUnit); |
| 1665 | pattern = this.getPastPattern(amount, (ClockUnit) unit); |
| 1666 | } |
| 1667 | } else { |
| 1668 | if (unit.isCalendrical()) { |
| 1669 | assert (unit instanceof CalendarUnit); |
no test coverage detected