import * as moment from 'moment' import { IActivity } from '../modules/activity/interfaces' import { IProfile } from '../modules/enrichment/interfaces' const ONE_MINUTE = 1000 * 60 const ONE_HOUR = ONE_MINUTE * 60 export const humanizeTime = (unixMilliseconds: number) => { const diff = Date.now() - unixMilliseconds if (diff < ONE_MINUTE) { return 'Now' } if (diff < ONE_HOUR) { return `${Math.floor(diff / ONE_MINUTE)} min ago` } const date = moment(unixMilliseconds) if (date.isSame(moment(), 'day')) { return date.format('LT') } return date.format('MMM D') } export const humanizeMeetingDuration = (meetingDuration: number) => { if (meetingDuration % 60 === 0) { const hours = meetingDuration / 60 return hours === 1 ? '1 hour' : `${hours} hours` } else { return `${meetingDuration} minutes` } } export const humanizeDate = (unixMilliseconds: number) => { const now = moment().startOf('day') const then = moment(unixMilliseconds).startOf('day') const diff = now.diff(then, 'days') if (diff === 0) { return 'Today' } if (diff === 1) { return 'Yesterday' } return then.format('MMM D') } export const renderEndUserShortName = (email: string, profile: IProfile, activity: IActivity) => { if (activity && activity.name) { return activity.name } if (profile && profile.attributes) { return profile.attributes.firstName || profile.attributes.displayName } return email } export const renderEndUserName = (email: string, profile: IProfile, activity: IActivity) => { if (activity && activity.name) { return activity.name + ' at Drift' } if (profile && profile.attributes) { const displayName = profile.attributes.displayName const company = profile.attributes.employmentName if (displayName && company) { return `${displayName} at ${company}` } else if (displayName) { return `${displayName}` } } return email }