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

Function publishExperienceTime

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

Source from the content-addressed store, hash-verified

286};
287
288const publishExperienceTime = (start: Date, end?: Date): string => {
289 const difference =
290 new Date(end || Date.now()).getTime() - new Date(start).getTime();
291 const differenceInMonths = Math.floor(difference / oneMonth);
292 const years = Math.floor(differenceInMonths / 12);
293 const months = differenceInMonths % 12;
294
295 if (years > 0) {
296 const yearCopy = `${years} ${pluralize('year', years)}`;
297
298 if (months === 0) {
299 return yearCopy;
300 }
301
302 return `${yearCopy} ${months} ${pluralize('month', months)}`;
303 }
304
305 return months > 0
306 ? `${months} ${pluralize('month', months)}`
307 : 'Less than a month';
308};
309
310export const getTodayTz = (timeZone: string, now = new Date()): Date => {
311 const timeZonedToday = now.toLocaleString('en', { timeZone });

Callers 1

formatDateFunction · 0.85

Calls 2

pluralizeFunction · 0.90
nowMethod · 0.80

Tested by

no test coverage detected