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

Function publishExperienceTime

packages/shared/src/lib/dateFormat.ts:277–297  ·  view source on GitHub ↗
(start: Date, end?: Date)

Source from the content-addressed store, hash-verified

275};
276
277const publishExperienceTime = (start: Date, end?: Date): string => {
278 const difference =
279 new Date(end || Date.now()).getTime() - new Date(start).getTime();
280 const differenceInMonths = Math.floor(difference / oneMonth);
281 const years = Math.floor(differenceInMonths / 12);
282 const months = differenceInMonths % 12;
283
284 if (years > 0) {
285 const yearCopy = `${years} ${pluralize('year', years)}`;
286
287 if (months === 0) {
288 return yearCopy;
289 }
290
291 return `${yearCopy} ${months} ${pluralize('month', months)}`;
292 }
293
294 return months > 0
295 ? `${months} ${pluralize('month', months)}`
296 : 'Less than a month';
297};
298
299export const getTodayTz = (timeZone: string, now = new Date()): Date => {
300 const timeZonedToday = now.toLocaleString('en', { timeZone });

Callers 1

formatDateFunction · 0.85

Calls 1

pluralizeFunction · 0.90

Tested by

no test coverage detected