MCPcopy Create free account
hub / github.com/dailydotdev/apps / formatTotalDuration

Function formatTotalDuration

packages/shared/src/lib/date.ts:120–141  ·  view source on GitHub ↗
(experiences: DurationRangeInput[])

Source from the content-addressed store, hash-verified

118}
119
120export function formatTotalDuration(experiences: DurationRangeInput[]): string {
121 const ranges: DateRange[] = experiences.map((exp) => ({
122 start: exp.startedAt ? new Date(exp.startedAt) : new Date(),
123 end: exp.endedAt ? new Date(exp.endedAt) : new Date(),
124 }));
125
126 const { years, months } = calculateTotalDurationInMonths(ranges);
127
128 if (years > 0) {
129 const yearCopy = `${years} ${pluralize('year', years)}`;
130
131 if (months === 0) {
132 return yearCopy;
133 }
134
135 return `${yearCopy} ${months} ${pluralize('month', months)}`;
136 }
137
138 return months > 0
139 ? `${months} ${pluralize('month', months)}`
140 : 'Less than a month';
141}

Callers 2

date.spec.tsFile · 0.90
UserExperienceListFunction · 0.90

Calls 2

pluralizeFunction · 0.90

Tested by

no test coverage detected