{"version":3,"file":"getReadableRelativeTime.cjs","sources":["../../src/misc/getReadableRelativeTime.js"],"sourcesContent":["const arrMonths = [\n    'Jan',\n    'Feb',\n    'Mar',\n    'Apr',\n    'May',\n    'Jun',\n    'Jul',\n    'Aug',\n    'Sep',\n    'Oct',\n    'Nov',\n    'Dec'\n];\n\n// FIXME: If this code is running at server side, then the timezone can be different from the client side. Extend this\n//        function to accept the timezone as a parameter.\nconst getReadableRelativeTime = function (timestamp) {\n    const now = new Date();\n    const dateForTimestamp = new Date(timestamp);\n\n    // @ts-ignore\n    let diffInMs = now - timestamp;\n    if (diffInMs >= 0) {\n        // do nothing\n    } else {\n        diffInMs = -1;\n    }\n\n    const\n        timeDiffInSeconds = diffInMs          / 1000,\n        timeDiffInMinutes = timeDiffInSeconds /   60,\n        timeDiffInHours   = timeDiffInMinutes /   60,\n        timeDiffInDays    = timeDiffInHours   /   24,\n        timeDiffInWeeks   = timeDiffInDays    /    7;\n\n    let relativeTime;\n    if (timeDiffInDays >= 364) {\n        relativeTime = dateForTimestamp.getDate() + ' ' + arrMonths[dateForTimestamp.getMonth()] + ' ' + dateForTimestamp.getFullYear();\n    } else if (timeDiffInWeeks >= 5) {\n        relativeTime = dateForTimestamp.getDate() + ' ' + arrMonths[dateForTimestamp.getMonth()];\n    } else if (timeDiffInWeeks   >= 1) { relativeTime = Math.floor(timeDiffInWeeks  ) + 'w';\n    } else if (timeDiffInDays    >= 1) { relativeTime = Math.floor(timeDiffInDays   ) + 'd';\n    } else if (timeDiffInHours   >= 1) { relativeTime = Math.floor(timeDiffInHours  ) + 'h';\n    } else if (timeDiffInMinutes >= 1) { relativeTime = Math.floor(timeDiffInMinutes) + 'm';\n    } else if (timeDiffInSeconds >= 1) { relativeTime = Math.floor(timeDiffInSeconds) + 's';\n    } else if (timeDiffInSeconds >= 0) { relativeTime = 'Just now';\n    } else {\n        relativeTime = dateForTimestamp.getDate() + ' ' + arrMonths[dateForTimestamp.getMonth()] + ' ' + dateForTimestamp.getFullYear();\n    }\n\n    return relativeTime;\n};\n\nexport { getReadableRelativeTime };\n"],"names":["arrMonths","timestamp","now","Date","dateForTimestamp","diffInMs","timeDiffInSeconds","timeDiffInMinutes","timeDiffInHours","timeDiffInDays","timeDiffInWeeks","relativeTime","getDate","getMonth","getFullYear","Math","floor"],"mappings":";AAAA,MAAMA,UAAY,CACd,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA;gCAK4B,SAAUC,WACtC,MAAMC,IAAM,IAAIC,KACVC,iBAAmB,IAAID,KAAKF;AAGlC,IAAII,SAAWH,IAAMD;AACjBI,UAAY,IAGZA,UAAW;AAGf,MACIC,kBAAoBD,SAAoB,IACxCE,kBAAoBD,kBAAsB,GAC1CE,gBAAoBD,kBAAsB,GAC1CE,eAAoBD,gBAAsB,GAC1CE,gBAAoBD,eAAuB;AAE/C,IAAIE;AAEAA,aADAF,gBAAkB,IACHL,iBAAiBQ,UAAY,IAAMZ,UAAUI,iBAAiBS,YAAc,IAAMT,iBAAiBU,cAC3GJ,iBAAmB,EACXN,iBAAiBQ,UAAY,IAAMZ,UAAUI,iBAAiBS,YACtEH,iBAAqB,EAAoBK,KAAKC,MAAMN,iBAAqB,IACzED,gBAAqB,EAAoBM,KAAKC,MAAMP,gBAAqB,IACzED,iBAAqB,EAAoBO,KAAKC,MAAMR,iBAAqB,IACzED,mBAAqB,EAAoBQ,KAAKC,MAAMT,mBAAqB,IACzED,mBAAqB,EAAoBS,KAAKC,MAAMV,mBAAqB,IACzEA,mBAAqB,EAAoB,WAEjCF,iBAAiBQ,UAAY,IAAMZ,UAAUI,iBAAiBS,YAAc,IAAMT,iBAAiBU;AAGtH,OAAOH,YACX"}