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

Method pushDuration

base/src/main/java/net/time4j/PrettyTime.java:1753–1788  ·  view source on GitHub ↗
(
        long[] values,
        Duration<?> duration,
        TimeSource<?> refClock,
        boolean weekToDays
    )

Source from the content-addressed store, hash-verified

1751 }
1752
1753 private static void pushDuration(
1754 long[] values,
1755 Duration<?> duration,
1756 TimeSource<?> refClock,
1757 boolean weekToDays
1758 ) {
1759 int len = duration.getTotalLength().size();
1760
1761 for (int i = 0; i < len; i++) {
1762 TimeSpan.Item<? extends IsoUnit> item =
1763 duration.getTotalLength().get(i);
1764 IsoUnit unit = item.getUnit();
1765 long amount = item.getAmount();
1766
1767 if (unit instanceof CalendarUnit) {
1768 push(values, CalendarUnit.class.cast(unit), amount, weekToDays);
1769 } else if (unit instanceof ClockUnit) {
1770 push(values, ClockUnit.class.cast(unit), amount);
1771 } else if (unit instanceof OverflowUnit) {
1772 push(
1773 values,
1774 OverflowUnit.class.cast(unit).getCalendarUnit(),
1775 amount,
1776 weekToDays);
1777 } else if (unit.equals(CalendarUnit.weekBasedYears())) {
1778 values[0] = MathUtils.safeAdd(amount, values[0]); // YEARS
1779 } else { // approximated duration by normalization without nanos
1780 Moment unix = Moment.from(refClock.currentTime());
1781 PlainTimestamp start = unix.toZonalTimestamp(ZonalOffset.UTC);
1782 PlainTimestamp end = start.plus(amount, unit);
1783 IsoUnit[] units = (weekToDays ? TSP_UNITS : STD_UNITS);
1784 Duration<?> part = Duration.in(units).between(start, end);
1785 pushDuration(values, part, refClock, weekToDays);
1786 }
1787 }
1788 }
1789
1790 private static void push(
1791 long[] values,

Callers 1

printMethod · 0.95

Calls 15

pushMethod · 0.95
weekBasedYearsMethod · 0.95
safeAddMethod · 0.95
fromMethod · 0.95
toZonalTimestampMethod · 0.95
plusMethod · 0.95
inMethod · 0.95
getCalendarUnitMethod · 0.80
getTotalLengthMethod · 0.65
getMethod · 0.65
currentTimeMethod · 0.65
betweenMethod · 0.65

Tested by

no test coverage detected