| 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 |