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

Function publishExperienceTime

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

Source from the content-addressed store, hash-verified

260};
261
262const publishExperienceTime = (start: Date, end?: Date): string => {
263 const difference =
264 new Date(end || Date.now()).getTime() - new Date(start).getTime();
265 const differenceInMonths = Math.floor(difference / oneMonth);
266 const years = Math.floor(differenceInMonths / 12);
267 const months = differenceInMonths % 12;
268
269 if (years > 0) {
270 const yearCopy = `${years} ${pluralize('year', years)}`;
271
272 if (months === 0) {
273 return yearCopy;
274 }
275
276 return `${yearCopy} ${months} ${pluralize('month', months)}`;
277 }
278
279 return months > 0
280 ? `${months} ${pluralize('month', months)}`
281 : 'Less than a month';
282};
283
284export const getTodayTz = (timeZone: string, now = new Date()): Date => {
285 const timeZonedToday = now.toLocaleString('en', { timeZone });

Callers 1

formatDateFunction · 0.85

Calls 1

pluralizeFunction · 0.90

Tested by

no test coverage detected