| 1859 | * @see #toClockPeriod() |
| 1860 | */ |
| 1861 | public Duration<CalendarUnit> toCalendarPeriod() { |
| 1862 | |
| 1863 | if (this.isEmpty()) { |
| 1864 | return Duration.ofZero(); |
| 1865 | } |
| 1866 | |
| 1867 | List<Item<CalendarUnit>> calItems = new ArrayList<>(); |
| 1868 | |
| 1869 | for (Item<U> item : this.items) { |
| 1870 | if (item.getUnit() instanceof CalendarUnit) { |
| 1871 | calItems.add(Item.of(item.getAmount(), CalendarUnit.class.cast(item.getUnit()))); |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | if (calItems.isEmpty()) { |
| 1876 | return Duration.ofZero(); |
| 1877 | } |
| 1878 | |
| 1879 | return new Duration<>(calItems, this.isNegative()); |
| 1880 | |
| 1881 | } |
| 1882 | |
| 1883 | /** |
| 1884 | * <p>Extracts a new duration with all contained clock units only. </p> |