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

Method truncatedTo

base/src/main/java/net/time4j/Duration.java:2129–2152  ·  view source on GitHub ↗
(U unit)

Source from the content-addressed store, hash-verified

2127 * @since 5.2
2128 */
2129 public Duration<U> truncatedTo(U unit) {
2130
2131 if (this.isEmpty()) {
2132 return Duration.ofZero();
2133 }
2134
2135 double min = unit.getLength();
2136 List<Item<U>> newItems = new ArrayList<>();
2137
2138 for (Item<U> item : this.items) {
2139 if (Double.compare(item.getUnit().getLength(), min) >= 0) {
2140 newItems.add(item);
2141 } else {
2142 break;
2143 }
2144 }
2145
2146 if (newItems.isEmpty()) {
2147 return Duration.ofZero();
2148 }
2149
2150 return new Duration<>(newItems, this.isNegative());
2151
2152 }
2153
2154 /**
2155 * <p>Yields an approximate normalizer in steps of hours which

Calls 8

isEmptyMethod · 0.95
ofZeroMethod · 0.95
isNegativeMethod · 0.95
getLengthMethod · 0.65
compareMethod · 0.65
isEmptyMethod · 0.65
getUnitMethod · 0.45
addMethod · 0.45