{"version":3,"sources":["../../src/helpers/date.ts"],"sourcesContent":["import dayjs from \"dayjs\";\r\nimport moment from 'moment';\r\n\r\n\r\nimport localizedFormat from \"dayjs/plugin/localizedFormat\";\r\nimport calendarFormat from \"dayjs/plugin/calendar\";\r\ndayjs.extend(localizedFormat);\r\ndayjs.extend(calendarFormat);\r\n\r\nexport const formatMessageTime = (date: string) => {\r\n  return dayjs(date).format(\"LT\");\r\n};\r\n\r\nexport const formatSectionTime = (date: string) => {\r\n  return dayjs(date).format(\"ll\");\r\n};\r\n\r\nexport function formatWhatsAppDate(dateInput: Date): string {\r\n  const now = new Date();\r\n  const messageDate = new Date(dateInput);\r\n\r\n  const isSameDay = now.toDateString() === messageDate.toDateString();\r\n  const isYesterday =\r\n    now.getDate() - messageDate.getDate() === 1 &&\r\n    now.getMonth() === messageDate.getMonth() &&\r\n    now.getFullYear() === messageDate.getFullYear();\r\n\r\n  const oneWeekAgo = new Date();\r\n  oneWeekAgo.setDate(now.getDate() - 7);\r\n\r\n  if (isSameDay) {\r\n    return \"Today\";\r\n  } else if (isYesterday) {\r\n    return \"Yesterday\";\r\n  } else if (messageDate > oneWeekAgo) {\r\n    // Return the day of the week (e.g., \"Monday\")\r\n    return messageDate.toLocaleDateString(\"en-US\", { weekday: \"long\" });\r\n  } else {\r\n    // Return the date in DD/MM/YYYY format\r\n    const day = String(messageDate.getDate()).padStart(2, \"0\");\r\n    const month = String(messageDate.getMonth() + 1).padStart(2, \"0\"); // Months are zero-indexed\r\n    const year = messageDate.getFullYear();\r\n\r\n    return `${day}/${month}/${year}`;\r\n  }\r\n}\r\n\r\nexport function formatConversationTime(time: Date | string) {\r\n  if(!time) return ''\r\n  const now = moment();\r\n  const then = moment(time);\r\n  const duration = moment.duration(now.diff(then));\r\n\r\n  // Get the largest unit\r\n  const years = Math.floor(duration.asYears());\r\n  if (years > 0) return years + 'yr';\r\n\r\n  const months = Math.floor(duration.asMonths());\r\n  if (months > 0) return months + 'mo';\r\n\r\n  const weeks = Math.floor(duration.asWeeks());\r\n  if (weeks > 0) return weeks + 'w';\r\n\r\n  const days = Math.floor(duration.asDays());\r\n  if (days > 0) return days + 'd';\r\n\r\n  const hours = Math.floor(duration.asHours());\r\n  if (hours > 0) return hours + 'h';\r\n\r\n  const minutes = Math.floor(duration.asMinutes());\r\n  if (minutes > 0) return minutes + 'm';\r\n\r\n  // If duration is less than 1 minute\r\n  return 'Just now';\r\n}\r\n\r\nexport function convertToMinutes(seconds: number) {\r\n  if(seconds === 0) {\r\n    return '00:00'\r\n  }\r\n  var _seconds = Number(seconds.toFixed(0))\r\n  const minutes = Math.floor(_seconds / 60);\r\n  const remainingSeconds = _seconds % 60;\r\n\r\n  // Pad the numbers to always have two digits\r\n  const paddedMinutes = String(minutes).padStart(2, '0');\r\n  const paddedSeconds = String(remainingSeconds).padStart(2, '0');\r\n\r\n  return `${paddedMinutes}:${paddedSeconds}`;\r\n}"],"mappings":"AAAA,OAAOA,MAAW,QAClB,OAAOC,MAAY,SAGnB,OAAOC,MAAqB,+BAC5B,OAAOC,MAAoB,wBAC3BH,EAAM,OAAOE,CAAe,EAC5BF,EAAM,OAAOG,CAAc,EAEpB,IAAMC,EAAqBC,GACzBL,EAAMK,CAAI,EAAE,OAAO,IAAI,EAGnBC,EAAqBD,GACzBL,EAAMK,CAAI,EAAE,OAAO,IAAI,EAGzB,SAASE,EAAmBC,EAAyB,CAC1D,IAAMC,EAAM,IAAI,KACVC,EAAc,IAAI,KAAKF,CAAS,EAEhCG,EAAYF,EAAI,aAAa,IAAMC,EAAY,aAAa,EAC5DE,EACJH,EAAI,QAAQ,EAAIC,EAAY,QAAQ,IAAM,GAC1CD,EAAI,SAAS,IAAMC,EAAY,SAAS,GACxCD,EAAI,YAAY,IAAMC,EAAY,YAAY,EAE1CG,EAAa,IAAI,KAGvB,GAFAA,EAAW,QAAQJ,EAAI,QAAQ,EAAI,CAAC,EAEhCE,EACF,MAAO,QACF,GAAIC,EACT,MAAO,YACF,GAAIF,EAAcG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EAAE,SAAS,EAAG,GAAG,EAC/CM,EAAgB,OAAOF,CAAgB,EAAE,SAAS,EAAG,GAAG,EAE9D,MAAO,GAAGC,CAAa,IAAIC,CAAa,EAC1C","names":["dayjs","moment","localizedFormat","calendarFormat","formatMessageTime","date","formatSectionTime","formatWhatsAppDate","dateInput","now","messageDate","isSameDay","isYesterday","oneWeekAgo","day","month","year","formatConversationTime","time","then","duration","years","months","weeks","days","hours","minutes","convertToMinutes","seconds","_seconds","remainingSeconds","paddedMinutes","paddedSeconds"]}