MCPcopy Create free account
hub / github.com/codemix/graph / durationInMonths

Function durationInMonths

packages/graph/src/TemporalTypes.ts:1767–1790  ·  view source on GitHub ↗
(start: TemporalValue, end: TemporalValue)

Source from the content-addressed store, hash-verified

1765 * Compute the duration between two temporal values in months only.
1766 */
1767export 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.

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected