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

Function durationInDays

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

Source from the content-addressed store, hash-verified

1793 * Compute the duration between two temporal values in days only.
1794 */
1795export function durationInDays(start: TemporalValue, end: TemporalValue): DurationValue | null {
1796 if (
1797 (start instanceof DateValue ||
1798 start instanceof LocalDateTimeValue ||
1799 start instanceof DateTimeValue) &&
1800 (end instanceof DateValue || end instanceof LocalDateTimeValue || end instanceof DateTimeValue)
1801 ) {
1802 const startDate = new Date(Date.UTC(start.year, start.month - 1, start.day));
1803 const endDate = new Date(Date.UTC(end.year, end.month - 1, end.day));
1804 const diffMs = endDate.getTime() - startDate.getTime();
1805 const days = Math.round(diffMs / (24 * 60 * 60 * 1000));
1806 return new DurationValue(0, days, 0, 0);
1807 }
1808 return null;
1809}
1810
1811/**
1812 * Compute the duration between two temporal values in seconds only.

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected