(start: TemporalValue, end: TemporalValue)
| 1765 | * Compute the duration between two temporal values in months only. |
| 1766 | */ |
| 1767 | export function durationInMonths(start: TemporalValue, end: TemporalValue): DurationValue | null { |
| 1768 | if ( |
| 1769 | (start instanceof DateValue || |
| 1770 | start instanceof LocalDateTimeValue || |
| 1771 | start instanceof DateTimeValue) && |
| 1772 | (end instanceof DateValue || end instanceof LocalDateTimeValue || end instanceof DateTimeValue) |
| 1773 | ) { |
| 1774 | const startYear = start.year; |
| 1775 | const startMonth = start.month; |
| 1776 | const endYear = end.year; |
| 1777 | const endMonth = end.month; |
| 1778 | |
| 1779 | let months = (endYear - startYear) * 12 + (endMonth - startMonth); |
| 1780 | const startDay = start.day; |
| 1781 | const endDay = end.day; |
| 1782 | |
| 1783 | if (endDay < startDay) { |
| 1784 | months--; |
| 1785 | } |
| 1786 | |
| 1787 | return new DurationValue(months, 0, 0, 0); |
| 1788 | } |
| 1789 | return null; |
| 1790 | } |
| 1791 | |
| 1792 | /** |
| 1793 | * Compute the duration between two temporal values in days only. |
no outgoing calls
no test coverage detected