Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const timeFormats = [
- { max: 2760000, value: 60000, name: "minute", past: "a minute ago", future: "in a minute" },
- { max: 7200000, value: 3600000, name: "hour", past: "an hour ago", future: "in an hour" },
- { max: 5184000000, value: 86400000, name: "day", past: "yesterday", future: "tomorrow" },
- { max: 24192000000, value: 604800000, name: "week", past: "last week", future: "in a week" },
- { max: 28512000000, value: 2592000000, name: "month", past: "last month", future: "in a month" }
- ];
- function formatTime(t, e, n, i, h, b) {
- const s = Math.round(Math.abs(t) / e);
- if (b) {
- return s <= 1 ? h : `in ${s} ${n}s`;
- }
- return s <= 1 ? i : `${s} ${n}s ago`;
- }
- function relativeTime(date) {
- const now = new Date();
- const diff = now - date;
- if (Math.abs(diff) < 60000) {
- return "just now";
- }
- for (let tf of timeFormats) {
- if (Math.abs(diff) < tf.max) {
- return formatTime(diff, tf.value, tf.name, tf.past, tf.future, diff < 0);
- }
- }
- return formatTime(diff, 31536000000, "year", "last year", "in a year", diff < 0);
- }
- function interpolateValue(symbol, timestamp) {
- return [symbol, new Date(timestamp * 1000)];
- }
- const ids = [
- [1000000, 1380326400], [2768409, 1383264000], [7679610, 1388448000], [11538514, 1391212800],
- [15835244, 1392940000], [23646077, 1393459200], [38015510, 1393632000], [44634663, 1399334400],
- [46145305, 1400198400], [54845238, 1411257600], [63263518, 1414454400], [101260938, 1425600000],
- [101323197, 1426204800], [103151531, 1433376000], [103258382, 1432771200], [109393468, 1439078400],
- [111220210, 1429574400], [112594714, 1439683200], [116812045, 1437696000], [122600695, 1437782400],
- [124872445, 1439856000], [125828524, 1444003200], [130029930, 1441324800], [133909606, 1444176000],
- [143445125, 1448928000], [148670295, 1452211200], [152079341, 1453420000], [157242073, 1446768000],
- [171295414, 1457481600], [181783990, 1460246400], [222021233, 1465344000], [225034354, 1466208000],
- [278941742, 1473465600], [285253072, 1476835200], [294851037, 1479600000], [297621225, 1481846400],
- [328594461, 1482969600], [337808429, 1487707200], [341546272, 1487782800], [352940995, 1487894400],
- [369669043, 1490918400], [400169472, 1501459200], [616816630, 1529625600], [681896077, 1532821500],
- [727572658, 1543708800], [796147074, 1541371800], [925078064, 1563290400], [928636984, 1581513420],
- [1054883348, 1585674420], [1057704545, 1580393640], [1145856008, 1586342040], [1227964864, 1596127860],
- [1382531194, 1600188120], [1658586909, 1613148540], [1660971491, 1613329440], [1692464211, 1615402500],
- [1719536397, 1619293500], [1721844091, 1620224820], [1772991138, 1617540360], [1807942741, 1625520300],
- [1893429550, 1622040000], [1972424006, 1631669400], [1974255900, 1634000000], [2030606431, 1631992680],
- [2041327411, 1631989620], [2078711279, 1634321820], [2104178931, 1638353220], [2120496865, 1636714020],
- [2123596685, 1636503180], [2138472342, 1637590800], [3318845111, 1618028800], [4317845111, 1620028800],
- [5162494923, 1652449800], [5186883095, 1648764360], [5304951856, 1656718440], [5317829834, 1653152820],
- [5318092331, 1652024220], [5336336790, 1646368100], [5362593868, 1652024520], [5387234031, 1662137700],
- [5396587273, 1648014800], [5409444610, 1659025020], [5416026704, 1660925460], [5465223076, 1661710860],
- [5480654757, 1660926300], [5499934702, 1662130740], [5513192189, 1659626400], [5522237606, 1654167240],
- [5537251684, 1664269800], [5559167331, 1656718560], [5568348673, 1654642200], [5591759222, 1659025500],
- [5608562550, 1664012820], [5614111200, 1661780160], [5666819340, 1664112240], [5684254605, 1662134040],
- [5684689868, 1661304720], [5707112959, 1663803300], [5756095415, 1660925940], [5772670706, 1661539140],
- [5778063231, 1667477640], [5802242180, 1671821040], [5853442730, 1674866100], [5859878513, 1673117760],
- [5885964106, 1671081840], [5982648124, 1686941700], [6020888206, 1675534800], [6032606998, 1686998640],
- [6057123350, 1676198350], [6058560984, 1686907980], [6101607245, 1686830760], [6108011341, 1681032060],
- [6132325730, 1692033840], [6182056052, 1687870740], [6279839148, 1688399160], [6306077724, 1692442920],
- [6321562426, 1688486760], [6364973680, 1696349340], [6386727079, 1691696880], [6429580803, 1692082680],
- [6527226055, 1690289160], [6813121418, 1698489600], [6865576492, 1699052400], [6925870357, 1701192327],
- [6944368668, 1726144496], [7682429075, 1725539696], [8000499714, 1745152496], [7798375391, 1745411696],
- [7321742406, 1726835696], [7538420552, 1723379696], [7745089650, 1745584496]
- ];
- ids.sort((a, b) => a[0] - b[0]);
- function findDate(userId) {
- for (let i = 1; i < ids.length; i++) {
- if (ids[i - 1][0] <= userId && userId <= ids[i][0]) {
- const prev = ids[i - 1];
- const curr = ids[i];
- const ratio = (userId - prev[0]) / (curr[0] - prev[0]);
- const interpolated = Math.round(prev[1] + ratio * (curr[1] - prev[1]));
- return interpolateValue("~", interpolated);
- }
- }
- if (userId <= 1000000) return interpolateValue("<", 1380326400);
- return interpolateValue(">", 1745584496);
- }
- function creation(userId) {
- const [comparison, date] = findDate(userId);
- const approx = comparison === "~" ? "Approximately " : comparison === ">" ? "After " : "Before ";
- return `${approx}${date.toISOString().slice(0, 10)} (${relativeTime(date)})`;
- }
Advertisement
Add Comment
Please, Sign In to add comment